ask-cli
Version:
Alexa Skills Kit (ASK) Command Line Interfaces
66 lines (65 loc) • 2.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const client_iam_1 = require("@aws-sdk/client-iam");
const constants_1 = __importDefault(require("../../utils/constants"));
const abstract_aws_client_1 = __importDefault(require("./abstract-aws-client"));
/**
* Class for AWS IAM Client
*/
class IAMClient extends abstract_aws_client_1.default {
/**
* Constructor
* @param configuration The aws client config
*/
constructor(configuration) {
super(configuration);
this.client = new client_iam_1.IAMClient({
credentials: this.credentials,
region: this.region,
});
}
/**
* Returns information for an iam role
* @param roleArn The arn of the iam role to get information about
*/
getIAMRole(roleArn) {
const command = new client_iam_1.GetRoleCommand({
RoleName: this._extractIAMRoleName(roleArn),
});
return this.client.send(command).then((data) => data.Role);
}
/**
* Creates a basic lambda iam role
* @param roleName The name of the iam role
*/
createBasicLambdaRole(roleName) {
const policy = constants_1.default.AWS.IAM.ROLE.LAMBDA_BASIC_ROLE.POLICY;
const command = new client_iam_1.CreateRoleCommand({
RoleName: roleName,
AssumeRolePolicyDocument: JSON.stringify(policy),
});
return this.client.send(command).then((data) => data.Role);
}
/**
* Attaches the basic lambda managed role policy to an iam role
* @param roleArn The arn of the iam role to attach the role policy to
*/
attachBasicLambdaRolePolicy(roleArn) {
const command = new client_iam_1.AttachRolePolicyCommand({
PolicyArn: constants_1.default.AWS.IAM.ROLE.LAMBDA_BASIC_ROLE.POLICY_ARN,
RoleName: this._extractIAMRoleName(roleArn),
});
return this.client.send(command);
}
/**
* Extracts iam role name from an iam role arn
* @param roleArn The arn of the iam role to extract the role name from
*/
_extractIAMRoleName(roleArn) {
return roleArn.split("role/").pop();
}
}
exports.default = IAMClient;