feat: infer role ARN if given role name (#35)

This commit is contained in:
Clare Liguori
2020-03-04 14:24:55 -08:00
committed by GitHub
parent 47312577c9
commit 96c6f7e07b
2 changed files with 38 additions and 7 deletions

View File

@@ -42,8 +42,16 @@ async function assumeRole(params) {
accessKeyId, secretAccessKey, sessionToken, region, endpoint, customUserAgent: USER_AGENT
});
let roleArn = roleToAssume;
if (!roleArn.startsWith('arn:aws')) {
const identity = await sts.getCallerIdentity().promise();
const accountId = identity.Account;
// Supports only 'aws' partition. Customers in other partitions ('aws-cn') will need to provide full ARN
roleArn = `arn:aws:iam::${accountId}:role/${roleArn}`;
}
const assumeRoleRequest = {
RoleArn: roleToAssume,
RoleArn: roleArn,
RoleSessionName: roleSessionName,
DurationSeconds: roleDurationSeconds,
Tags: [