generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Description
Problem
Every agentcore deploy creates a new KMS key and calls SetTokenVaultCMKCommand to re-configure the account-level token-vault, even if a key already exists from a previous deploy. The old key is never deleted, disabled, or reused.
This means:
- Each deploy accumulates an orphaned KMS key (~$1/month per key)
remove all+deploy(teardown) destroys the CloudFormation stack but does not delete the KMS key- The
identityKmsKeyArnstored indeployed-state.jsonis lost when the target entry is cleaned up during teardown - Concurrent deploys to the same account race on
SetTokenVaultCMKCommand, causing"conflicting request during InitializeMutation"errors
Root Cause
setupTokenVaultKms in src/cli/operations/deploy/pre-deploy-identity.ts:91-121 unconditionally creates a new KMS key via CreateKeyCommand and sets it on the token-vault. It does not:
- Check if a KMS key already exists in deployed state and reuse it
- Clean up old keys when creating a new one
The teardown flow in src/cli/operations/deploy/teardown.ts does not call ScheduleKeyDeletion or DisableKey for the stored identityKmsKeyArn.
Suggested Fix
- Reuse existing key: Before creating a new KMS key, check
deployed-state.jsonfor an existingidentityKmsKeyArn. If present and the key is still valid (enabled), reuse it instead of creating a new one. - Cleanup on teardown: When performing a teardown deploy, schedule deletion of the KMS key stored in
identityKmsKeyArnusingScheduleKeyDeletionCommand. - Handle concurrent deploys: The
SetTokenVaultCMKCommandcall should retry with backoff when it receives a mutation-in-progress error.
Impact
- Every user accumulates ~$1/month in orphaned KMS keys per deploy
- CI/CD pipelines and e2e test suites that deploy frequently create many orphaned keys
- Concurrent deploys fail due to KMS mutation race condition
Relevant Files
src/cli/operations/deploy/pre-deploy-identity.ts—setupTokenVaultKms()src/cli/operations/identity/api-key-credential-provider.ts—setTokenVaultKmsKey()src/cli/operations/deploy/teardown.ts—performStackTeardown()src/schema/schemas/deployed-state.ts—identityKmsKeyArnfield
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels