If you’re using the @aws/agentcore CLI (versions 0.13.1, 0.17.0, or 1.0.0-preview.11), you might run into a bug that causes the agentcore validate and agentcore deploy commands to fail with the error message “Failed to configure KMS: Forbidden” during your first attempt in a new session. The good news is that rerunning these commands usually works without any issues.
Here’s what’s happening and how to fix it:
The problem comes from the way certain functions handle their inputs. Specifically, the getTokenVaultCommand function is called with an empty object, which means it doesn’t specify a tokenVaultId. On a fresh setup, this causes a temporary failure that’s silently ignored because of an empty catch block. As a result, the code wrongly assumes that no TokenVault exists.
When a new, orphaned KMS key is created with CreateKeyCommand, the next step involves calling the Vht function. However, Vht is expected to take three arguments: the first two are provided, but the third, tokenVaultId, is missing. Since this third parameter is essential to the function’s operation, it defaults to undefined and leads to a “Forbidden” error when the code attempts to set the CMK.
You can verify what’s happening by checking CloudTrail logs: each initial run shows a kms:CreateKey event, indicating orphaned keys are being created. However, there’s no CloudTrail event for SetTokenVaultCMK, meaning the request fails before reaching AWS. The core of the issue is only during this initial “cold start” — subsequent runs work because the API endpoint warms up, and the getTokenVaultCommand then correctly finds and returns the existing CMK, avoiding the faulty code execution.
To fix this, you can modify the calls like so:
- Change getTokenVaultCommand({}) to getTokenVaultCommand({tokenVaultId: “default”}).
- Update Vht calls from Vht(o, i) to Vht(o, i, “default”).
As a quick workaround for now, especially if you’re working in CI, run the command aws bedrock-agentcore-control get-token-vault via the AWS CLI before starting your agentcore validate or deploy processes. Doing this helps warm up the endpoint, ensuring the getTokenVaultCommand works as expected and prevents the error from cropping up during your scripts.
