Skip to content

Commit

Permalink
fix aws#8691 by identifying correct role name
Browse files Browse the repository at this point in the history
I am no typescript programmer but I think this change could solve aws#8691
  • Loading branch information
ThomasSteinbach authored Jun 23, 2020
1 parent 6b5d77b commit 0b47eef
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/@aws-cdk/aws-iam/lib/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ export class Role extends Resource implements IRole {
const parsedArn = scopeStack.parseArn(roleArn);
const resourceName = parsedArn.resourceName!;
// service roles have an ARN like 'arn:aws:iam::<account>:role/service-role/<roleName>'
// we want to support these as well, so strip out the 'service-role/' prefix if we see it
const roleName = resourceName.startsWith('service-role/')
? resourceName.slice('service-role/'.length)
: resourceName;
// or 'arn:aws:iam::<account>:role/service-role/servicename.amazonaws.com/service-role/<roleName>'
// we want to support these as well, so we just use the element after the last slash as role name
const roleName = resourceName.split('/').pop()

class Import extends Resource implements IRole {
public readonly grantPrincipal: IPrincipal = this;
Expand Down

0 comments on commit 0b47eef

Please sign in to comment.