Skip to content

Commit dedcc27

Browse files
authored
add error mapping for role is invalid or cannot be assumed error (#2325)
1 parent 560878f commit dedcc27

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

.changeset/brown-mayflies-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/backend-deployer': patch
3+
---
4+
5+
add error mapping for role is invalid or cannot be assumed error'

packages/backend-deployer/src/cdk_error_mapper.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,13 @@ npm error enoent`,
659659
errorName: 'LambdaEmptyZipFault',
660660
expectedDownstreamErrorMessage: undefined,
661661
},
662+
{
663+
errorMessage: `Error: some-stack failed: ValidationError: Role role-arn is invalid or cannot be assumed`,
664+
expectedTopLevelErrorMessage:
665+
'Role role-arn is invalid or cannot be assumed',
666+
errorName: 'InvalidOrCannotAssumeRoleError',
667+
expectedDownstreamErrorMessage: undefined,
668+
},
662669
];
663670

664671
void describe('invokeCDKCommand', { concurrency: 1 }, () => {

packages/backend-deployer/src/cdk_error_mapper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ export class CdkErrorMapper {
164164
errorName: 'CDKNotFoundError',
165165
classification: 'ERROR',
166166
},
167+
{
168+
errorRegex:
169+
/ValidationError: Role (?<roleArn>.*) is invalid or cannot be assumed/,
170+
humanReadableErrorMessage:
171+
'Role {roleArn} is invalid or cannot be assumed',
172+
resolutionMessage:
173+
'Ensure the role exists and AWS credentials have an IAM policy that grants sts:AssumeRole for the role',
174+
errorName: 'InvalidOrCannotAssumeRoleError',
175+
classification: 'ERROR',
176+
},
167177
{
168178
errorRegex: new RegExp(
169179
`(SyntaxError|ReferenceError|TypeError)( \\[[A-Z_]+])?:((?:.|${this.multiLineEolRegex})*?at .*)`
@@ -523,6 +533,7 @@ export type CDKDeploymentError =
523533
| 'ExpiredTokenError'
524534
| 'FileConventionError'
525535
| 'ModuleNotFoundError'
536+
| 'InvalidOrCannotAssumeRoleError'
526537
| 'InvalidPackageJsonError'
527538
| 'SecretNotSetError'
528539
| 'SyntaxError'

0 commit comments

Comments
 (0)