UNPKG

@softchef/cdk-iot-device-management

Version:

IoT device management is composed of things, thing types, thing groups, jobs, files API services. The constructs can be used independently, that are based on full-managed service to create an API Gateway & Lambda function.

28 lines (27 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.build = exports.parse = exports.validate = void 0; const validate = (str) => typeof str === "string" && str.indexOf("arn:") === 0 && str.split(":").length >= 6; exports.validate = validate; const parse = (arn) => { const segments = arn.split(":"); if (segments.length < 6 || segments[0] !== "arn") throw new Error("Malformed ARN"); const [, partition, service, region, accountId, ...resource] = segments; return { partition, service, region, accountId, resource: resource.join(":"), }; }; exports.parse = parse; const build = (arnObject) => { const { partition = "aws", service, region, accountId, resource } = arnObject; if ([service, region, accountId, resource].some((segment) => typeof segment !== "string")) { throw new Error("Input ARN object is invalid"); } return `arn:${partition}:${service}:${region}:${accountId}:${resource}`; }; exports.build = build;