Skip to content

Commit 255ca18

Browse files
authored
Handle parameter not found error while deleting secret (#2186)
* Handle parameter not found error while deleting secret * remove if
1 parent a191fe5 commit 255ca18

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

.changeset/tidy-chicken-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/backend-secret': patch
3+
---
4+
5+
Handle parameter not found error while deleting secret

packages/backend-secret/src/ssm_secret_with_amplify_error_handling.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ void describe('getSecretClientWithAmplifyErrorHandling', () => {
8989
);
9090
});
9191

92+
void it('throws AmplifyUserError if removeSecret fails due to ParameterNotFound error', async (context) => {
93+
const notFoundError = new Error('Parameter not found error');
94+
notFoundError.name = 'ParameterNotFound';
95+
const secretsError = SecretError.createInstance(notFoundError);
96+
context.mock.method(rawSecretClient, 'removeSecret', () => {
97+
throw secretsError;
98+
});
99+
const secretName = 'testSecretName';
100+
await assert.rejects(
101+
() =>
102+
classUnderTest.removeSecret(
103+
{
104+
namespace: 'testSandboxId',
105+
name: 'testSandboxName',
106+
type: 'sandbox',
107+
},
108+
secretName
109+
),
110+
new AmplifyUserError('SSMParameterNotFoundError', {
111+
message: `Failed to remove ${secretName} secret. ParameterNotFound: Parameter not found error`,
112+
resolution: `Make sure that ${secretName} has been set. See https://docs.amplify.aws/react/deploy-and-host/fullstack-branching/secrets-and-vars/.`,
113+
})
114+
);
115+
});
116+
92117
void it('throws AmplifyFault if listSecrets fails due to a non-SSM exception other than expired credentials', async (context) => {
93118
const underlyingError = new Error('some secret error');
94119
const secretsError = SecretError.createInstance(underlyingError);

packages/backend-secret/src/ssm_secret_with_amplify_error_handling.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class SSMSecretClientWithAmplifyErrorHandling implements SecretClient {
6969
secretName
7070
);
7171
} catch (e) {
72-
throw this.translateToAmplifyError(e, 'Remove');
72+
throw this.translateToAmplifyError(e, 'Remove', { name: secretName });
7373
}
7474
};
7575

@@ -87,6 +87,7 @@ export class SSMSecretClientWithAmplifyErrorHandling implements SecretClient {
8787
'ExpiredTokenException',
8888
'ExpiredToken',
8989
'CredentialsProviderError',
90+
'IncompleteSignatureException',
9091
'InvalidSignatureException',
9192
].includes(error.cause.name)
9293
) {
@@ -100,11 +101,13 @@ export class SSMSecretClientWithAmplifyErrorHandling implements SecretClient {
100101
}
101102
if (
102103
error.cause.name === 'ParameterNotFound' &&
103-
apiName === 'Get' &&
104+
(apiName === 'Get' || apiName === 'Remove') &&
104105
secretIdentifier
105106
) {
106107
return new AmplifyUserError('SSMParameterNotFoundError', {
107-
message: `Failed to get ${secretIdentifier.name} secret. ${error.cause.name}: ${error.cause?.message}`,
108+
message: `Failed to ${apiName.toLowerCase()} ${
109+
secretIdentifier.name
110+
} secret. ${error.cause.name}: ${error.cause?.message}`,
108111
resolution: `Make sure that ${secretIdentifier.name} has been set. See https://docs.amplify.aws/react/deploy-and-host/fullstack-branching/secrets-and-vars/.`,
109112
});
110113
}

0 commit comments

Comments
 (0)