Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle parameter not found error while deleting secret #2186

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-chicken-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/backend-secret': patch
---

Handle parameter not found error while deleting secret
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@ void describe('getSecretClientWithAmplifyErrorHandling', () => {
);
});

void it('throws AmplifyUserError if removeSecret fails due to ParameterNotFound error', async (context) => {
const notFoundError = new Error('Parameter not found error');
notFoundError.name = 'ParameterNotFound';
const secretsError = SecretError.createInstance(notFoundError);
context.mock.method(rawSecretClient, 'removeSecret', () => {
throw secretsError;
});
const secretName = 'testSecretName';
await assert.rejects(
() =>
classUnderTest.removeSecret(
{
namespace: 'testSandboxId',
name: 'testSandboxName',
type: 'sandbox',
},
secretName
),
new AmplifyUserError('SSMParameterNotFoundError', {
message: `Failed to remove ${secretName} secret. ParameterNotFound: Parameter not found error`,
resolution: `Make sure that ${secretName} has been set. See https://docs.amplify.aws/react/deploy-and-host/fullstack-branching/secrets-and-vars/.`,
})
);
});

void it('throws AmplifyFault if listSecrets fails due to a non-SSM exception other than expired credentials', async (context) => {
const underlyingError = new Error('some secret error');
const secretsError = SecretError.createInstance(underlyingError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class SSMSecretClientWithAmplifyErrorHandling implements SecretClient {
secretName
);
} catch (e) {
throw this.translateToAmplifyError(e, 'Remove');
throw this.translateToAmplifyError(e, 'Remove', { name: secretName });
}
};

Expand All @@ -87,6 +87,7 @@ export class SSMSecretClientWithAmplifyErrorHandling implements SecretClient {
'ExpiredTokenException',
'ExpiredToken',
'CredentialsProviderError',
'IncompleteSignatureException',
'InvalidSignatureException',
].includes(error.cause.name)
) {
Expand All @@ -100,11 +101,13 @@ export class SSMSecretClientWithAmplifyErrorHandling implements SecretClient {
}
if (
error.cause.name === 'ParameterNotFound' &&
apiName === 'Get' &&
(apiName === 'Get' || apiName === 'Remove') &&
secretIdentifier
) {
return new AmplifyUserError('SSMParameterNotFoundError', {
message: `Failed to get ${secretIdentifier.name} secret. ${error.cause.name}: ${error.cause?.message}`,
message: `Failed to ${apiName.toLowerCase()} ${
secretIdentifier.name
} secret. ${error.cause.name}: ${error.cause?.message}`,
resolution: `Make sure that ${secretIdentifier.name} has been set. See https://docs.amplify.aws/react/deploy-and-host/fullstack-branching/secrets-and-vars/.`,
});
}
Expand Down