Skip to content

Commit b6f4c54

Browse files
authored
handle not authorized to perform on resource error (#2258)
* handle not authorized to perform on resource error * add resource to resolution
1 parent 0114549 commit b6f4c54

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

.changeset/slimy-sheep-wonder.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+
handle not authorized to perform on resource error

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,13 @@ npm error A complete log of this run can be found in: /home/some-path/.npm/_logs
399399
errorName: 'InvalidPackageJsonError',
400400
expectedDownstreamErrorMessage: undefined,
401401
},
402+
{
403+
errorMessage: `Error: some-stack failed: ValidationError: User: <escaped ARN> is not authorized to perform: ssm:GetParameters on resource: <escaped ARN> because no identity-based policy allows the ssm:GetParameters action`,
404+
expectedTopLevelErrorMessage:
405+
'Unable to deploy due to insufficient permissions',
406+
errorName: 'AccessDeniedError',
407+
expectedDownstreamErrorMessage: undefined,
408+
},
402409
];
403410

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

packages/backend-deployer/src/cdk_error_mapper.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ export class CdkErrorMapper {
4040
if (matchGroups.groups) {
4141
for (const [key, value] of Object.entries(matchGroups.groups)) {
4242
const placeHolder = `{${key}}`;
43-
if (matchingError.humanReadableErrorMessage.includes(placeHolder)) {
43+
if (
44+
matchingError.humanReadableErrorMessage.includes(placeHolder) ||
45+
matchingError.resolutionMessage.includes(placeHolder)
46+
) {
4447
matchingError.humanReadableErrorMessage =
4548
matchingError.humanReadableErrorMessage.replace(
4649
placeHolder,
4750
value
4851
);
52+
53+
matchingError.resolutionMessage =
54+
matchingError.resolutionMessage.replace(placeHolder, value);
4955
// reset the stderr dump in the underlying error
5056
underlyingError = undefined;
5157
}
@@ -205,6 +211,16 @@ export class CdkErrorMapper {
205211
errorName: 'GetLambdaLayerVersionError',
206212
classification: 'ERROR',
207213
},
214+
{
215+
errorRegex:
216+
/User:(.*) is not authorized to perform:(.*) on resource:(?<resource>.*) because no identity-based policy allows the (?<action>.*) action/,
217+
humanReadableErrorMessage:
218+
'Unable to deploy due to insufficient permissions',
219+
resolutionMessage:
220+
'Ensure you have permissions to call {action} for {resource}',
221+
errorName: 'AccessDeniedError',
222+
classification: 'ERROR',
223+
},
208224
{
209225
// Also extracts the first line in the stack where the error happened
210226
errorRegex: new RegExp(

0 commit comments

Comments
 (0)