aws-secrets-manager
aws/agent-toolkit-for-aws
Safely use AWS Secrets Manager secrets in agent commands without exposing plaintext to the LLM context.
What is aws-secrets-manager?
This skill prevents AI agents from directly fetching secret values from AWS Secrets Manager, which could leak credentials into logs or conversation history. Instead, it teaches a safer pattern using dynamic `{{resolve:secretsmanager:...}}` references that are resolved at runtime by the `asm-exec` wrapper, keeping plaintext secrets out of the agent's context window.
- Blocks direct calls to `get-secret-value` and `batch-get-secret-value` via a PreToolUse hook
- Resolves `{{resolve:secretsmanager:...}}` references at runtime through AWS Secrets Manager Agent or SigV4-signed MCP endpoint
- Substitutes secret values only in child process execution, never exposing them to the agent
- Supports JSON key extraction, custom version stages, and cross-region secret access
- Provides `asm-exec` wrapper that scans command arguments and environment variables for secret references
How to install aws-secrets-manager
npx skills add https://github.com/aws/agent-toolkit-for-aws --skill aws-secrets-manager- AWS Secrets Manager Agent (SMA) running on localhost:2773, OR valid AWS credentials for SigV4 signing of the MCP endpoint
- IAM permissions for `secretsmanager:GetSecretValue` on the secrets being accessed
- AWS region configured via `AWS_REGION`, `AWS_DEFAULT_REGION`, or secret ARN
How to use aws-secrets-manager
- 1.Install the skill via `npx skills add https://github.com/aws/agent-toolkit-for-aws --skill aws-secrets-manager`
- 2.Identify secrets you need to use and their JSON keys (e.g., `prod/db-creds` with keys `username` and `password`)
- 3.Replace hardcoded credentials in commands with `{{resolve:secretsmanager:secret-id:SecretString:json-key}}` references
- 4.Wrap commands with `asm-exec --` to resolve references at runtime (e.g., `asm-exec -- psql "password={{resolve:secretsmanager:prod/db:SecretString:password}}"`)
- 5.Verify IAM permissions allow `secretsmanager:GetSecretValue` and test with `aws sts get-caller-identity`
Use cases
- Pass database credentials to psql or mysql without exposing passwords in agent context
- Inject API tokens into HTTP requests via Authorization headers
- Set environment variables for Docker containers with secrets resolved at runtime
- Generate configuration files with resolved secrets without storing plaintext locally
- Access multiple secrets in a single command with different JSON keys
- AWS infrastructure engineers managing secrets for AI agent workflows
- DevOps teams enforcing secret safety policies for automated deployments
- Security-conscious organizations requiring defense-in-depth for credential handling
- Teams using Claude Code or Cursor with AWS API access
aws-secrets-manager FAQ
No. The `asm-exec` wrapper resolves references only in the child process before execution. The plaintext value never enters the agent's context window or logs.
Resolution will fail with a specific error message to stderr. Ensure either SMA is running on localhost:2773 or AWS credentials are valid and the secret's region is correctly configured.
Yes. Set `AWS_REGION` environment variable or use the full ARN (which includes the region) in the `{{resolve:...}}` reference.
The reference resolves to an empty string. Verify the secret structure in the AWS Console and confirm the JSON key name matches exactly.
No. It prevents the most common leakage path (plaintext in agent context) but is best-effort. Combine with IAM least-privilege, CloudTrail monitoring, and VPC endpoint policies for defense-in-depth.
Full instructions (SKILL.md)
Source of truth, from aws/agent-toolkit-for-aws.
name: aws-secrets-manager description: > Secret safety for AWS Secrets Manager, secret management, credentials, API keys, tokens, and passwords. Prevents AI agents from directly fetching secret values and teaches runtime dynamic references with asm-exec so plaintext never enters the LLM context window. metadata: version: "1"
Using Secrets Safely with Agents
Overview
When AI agents handle secrets, credentials, API keys, tokens, or passwords with
shell or AWS API access, they can call aws secretsmanager get-secret-value
and receive plaintext values in their context window. This creates risk:
secrets may leak into logs, conversation history, or downstream tool calls.
This skill teaches a safer pattern: dynamic references resolved at runtime
by a wrapper script (asm-exec), so the agent never sees the secret value.
Best-effort defense, not a security boundary. This prevents the most common leakage path but cannot stop all evasion vectors. Combine with IAM least-privilege, CloudTrail monitoring, and VPC endpoint policies.
Rules
You MUST follow these rules when working with secrets:
- MUST NOT call
get-secret-valueorbatch-get-secret-value-- not via AWS CLI, SDK, MCP tools, curl, or any other mechanism. - MUST NOT attempt to read secret values from the Secrets Manager Agent (SMA) daemon directly (localhost:2773 or any loopback variant).
- MUST use
{{resolve:secretsmanager:...}}references -- these are resolved at runtime byasm-execwithout exposing values to you.
The {{resolve:...}} Syntax
{{resolve:secretsmanager:<secret-id>:<field-type>:<json-key>:<version-stage>}}
| Component | Required | Default | Example |
|---|---|---|---|
secret-id | Yes | -- | prod/db-creds or full ARN |
field-type | No | SecretString | SecretString |
json-key | No | (full value) | password |
version-stage | No | AWSCURRENT | AWSPENDING |
Using asm-exec
asm-exec is a wrapper that resolves {{resolve:...}} references in command
arguments and environment variables, then execs the target command. The secret
value exists only in the child process -- never in the agent's context.
Usage
# Pass a database password to psql without exposing it
asm-exec -- psql \
"host=mydb.example.com \
user={{resolve:secretsmanager:prod/db-creds:SecretString:username}} \
password={{resolve:secretsmanager:prod/db-creds:SecretString:password}}" \
-c "SELECT * FROM users LIMIT 10"
# Use default field-type (SecretString) and full value (no json-key)
asm-exec -- curl -H "Authorization: Bearer {{resolve:secretsmanager:prod/api-token}}" \
https://api.example.com/data
# Multiple secrets in one command
asm-exec -- mysql \
-h {{resolve:secretsmanager:prod/mysql:SecretString:host}} \
-u {{resolve:secretsmanager:prod/mysql:SecretString:username}} \
-p{{resolve:secretsmanager:prod/mysql:SecretString:password}} \
-e "SHOW TABLES"
How It Works
- Scans all command arguments for
{{resolve:...}}patterns - Resolves each reference through the first available backend, in order:
- AWS Secrets Manager Agent (SMA) on localhost:2773 (zero-latency, cached)
- AWS MCP endpoint (
https://aws-mcp.us-east-1.api.aws/mcp), calling theaws___run_scripttool over a SigV4-signed request (the tool runs a short server-side Python script that fetches the secret viacall_boto3) - Determines the secret's region from an ARN's region segment, or from
AWS_REGION/AWS_DEFAULT_REGION, and passes it to the resolver
- Substitutes resolved values using
re.subwith a callable (single-pass -- prevents re-scan injection if a secret value contains{{resolve:...}}) - Runs the target command via
subprocess.run-- secret values exist only in the asm-exec process, never in the agent's context window
No local AWS CLI fallback for resolution.
asm-execdoes not shell out toaws secretsmanager get-secret-valueto resolve references. Resolution happens only through SMA or the MCP endpoint, so the plaintext value is never written to a local process's stdout where it could be captured.
SigV4 signing
The MCP endpoint authenticates every tool call with AWS SigV4. asm-exec signs
requests itself using only the Python standard library (hashlib/hmac) -- it
does not depend on botocore or spin up the mcp-proxy-for-aws-cli proxy, keeping
the wrapper a lightweight ephemeral process. The signing service and region are
inferred from the endpoint hostname (e.g. aws-mcp.us-east-1.api.aws ->
service aws-mcp, region us-east-1); this signing region is independent of the
secret's own region, which is passed as the region_name argument to the
server-side call_boto3 call.
Credentials for signing are resolved in order: environment variables
(AWS_ACCESS_KEY_ID etc.), aws configure export-credentials (AWS CLI v2), then
aws configure get (AWS CLI v1).
Prerequisites
Either backend must be reachable, with credentials that have
secretsmanager:GetSecretValue permission:
- AWS Secrets Manager Agent (SMA) running on localhost:2773, OR
- AWS credentials resolvable for SigV4 signing of the MCP endpoint (see above).
For cross-region secrets, set
AWS_REGION(or use a full ARN) so the correct region is targeted.
See SMA setup guide.
Common Patterns
Database connections
asm-exec -- psql "postgresql://{{resolve:secretsmanager:prod/db:SecretString:username}}:{{resolve:secretsmanager:prod/db:SecretString:password}}@db.example.com:5432/mydb"
Docker with secrets
asm-exec -- docker run -e "DB_PASSWORD={{resolve:secretsmanager:prod/db:SecretString:password}}" myapp:latest
Configuration file templating
# Generate config with resolved secrets, write to file
asm-exec -- sh -c 'echo "password={{resolve:secretsmanager:app/db:SecretString:password}}" > /tmp/app.conf'
Structural Enforcement (Plugin Hook)
When the aws-core plugin is enabled, a PreToolUse hook automatically blocks
any attempt to call get-secret-value or batch-get-secret-value -- via AWS CLI,
MCP tools, or direct SMA access. No manual configuration needed.
The hook is defined at plugins/aws-core/com.anthropic.claude-code/hooks/hooks.json
and activates automatically when the plugin is installed.
Troubleshooting
"Secret not found" errors
Verify the secret exists and your IAM role has secretsmanager:GetSecretValue
permission. Check the secret name matches exactly (case-sensitive).
SMA connection refused
The Secrets Manager Agent may not be running. This is non-fatal: asm-exec
falls through to the SigV4-signed MCP endpoint. Ensure AWS credentials are
resolvable (see SigV4 signing above) so that backend can authenticate.
"Failed to resolve" errors
Both backends were unreachable or returned no value. When MCP resolution fails,
asm-exec prints the specific cause to stderr (asm-exec: MCP resolution failed: ...) -- a timeout, an unreachable endpoint, an HTTP status, a denied permission,
or a missing value -- so read that line first. Check that either SMA is
running or AWS credentials are valid (aws sts get-caller-identity), that the
secret's region is correct (set AWS_REGION or use a full ARN), and that your
identity has secretsmanager:GetSecretValue on the secret. A 401 from the MCP
endpoint indicates a SigV4 signing or credential problem, not a missing secret. If
the failure is a timeout, the server-side call may need longer than the default
30s -- raise it with ASM_EXEC_MCP_TIMEOUT (seconds).
Resolution produces empty string
The JSON key may not exist in the secret value. Verify the secret structure in the AWS Console or ask the secret owner to confirm the available keys.
Related skills
More from aws/agent-toolkit-for-aws and the wider catalog.

aws-security
Unified AWS security posture, threat detection, and compliance findings across Security Hub, GuardDuty, Inspector, Macie, and Detective.

aws-serverless
Build, deploy, and optimize serverless applications on AWS Lambda, API Gateway, Step Functions, and EventBridge.

aws-social-messaging
Manage WhatsApp messaging, templates, media, and delivery tracking via AWS End User Messaging Social.

aws-step-functions
Author and edit AWS Step Functions state machines with ASL, JSONata, and workflow orchestration patterns.

aws-storage
Choose, configure, and troubleshoot AWS object, file, and block storage services for your workload.

aws-transform
Code upgrades, migrations, and transformations at scale using AWS Transform CLI.