Skip to content

Commit 24ad01a

Browse files
committed
docs: Add troubleshooting guide for AWS Bedrock security token expiration
- Create new page for handling security token timeout errors - Document awsAuthRefresh and awsCredentialExport configuration - Add troubleshooting steps for common credential refresh issues - Reference GitHub issues #3823 and #11264 for known bugs/feature requests - Update main Bedrock page with link to troubleshooting guide - Add journal entries for new documentation
1 parent 9ffc4eb commit 24ad01a

8 files changed

+187
-7
lines changed

journals/2025_11_12.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Rustacian Installers
22
- [[Rust/CLI/Concept/Best Practices for Rust-Based CLI Installers]]
3-
## Marketing Quote
4-
- [[Marketing]] - Added quote about marketing as the bridge between company purpose and customer needs from [[Person/Philip Kotler]]
3+
- ## Marketing Quote
4+
- [[Marketing]] - Added quote about marketing as the bridge between company purpose and customer needs from [[Person/Philip Kotler]]
5+
- > > **Marketing** is the art and science of creating genuine customer value. It is the **bridge** between the company's **purpose** and the customer's **needs**. #Quote from [[Person/Philip Kotler]], Father of Modern Marketing

journals/2025_11_13.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [[LangChain/Academy/LangSmith/Quickstart Essentials/Module 2 Evaluation/Online]]

journals/2025_11_14.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [[Claude Code]]
2+
- Created [[Claude Code/Bedrock/How To/Get Around Security Token Timeout]] - troubleshooting guide for handling "API Error: The security token included in the request is expired" when using Bedrock with Claude Code

pages/Claude Code___Bedrock.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ alias:: [[Anthropic/App/Claude Code/Bedrock]]
1212
}
1313
```
1414
- ##### Configuration settings explained
15-
- **`awsAuthRefresh`**: Use this for commands that modify the `.aws` directory (e.g., updating credentials, SSO cache, or config files). Output is shown to the user (but user input is not supported), making it suitable for browser-based authentication flows where the CLI displays a code to enter in the browser.**`awsCredentialExport`**: Only use this if you cannot modify `.aws` and must directly return credentials. Output is captured silently (not shown to the user). The command must output JSON in this format:
15+
- **`awsAuthRefresh`**: Use this for commands that modify the `.aws` directory (e.g., updating credentials, SSO cache, or config files). Output is shown to the user (but user input is not supported), making it suitable for browser-based authentication flows where the CLI displays a code to enter in the browser.**`awsCredentialExport`**: Only use this if you cannot modify `.aws` and must directly return credentials. Output is captured silently (not shown to the user). The command must output JSON in this format:
1616
- ```
1717
{
1818
"Credentials": {
@@ -21,4 +21,6 @@ alias:: [[Anthropic/App/Claude Code/Bedrock]]
2121
"SessionToken": "value"
2222
}
2323
}
24-
```
24+
```
25+
- #### Troubleshooting credential expiration
26+
- If you encounter the error "API Error: The security token included in the request is expired" and automatic credential refresh isn't working, see [[Claude Code/Bedrock/How To/Get Around Security Token Timeout]] for troubleshooting steps and workarounds.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
tags:: [[Diataxis/How To]], [[Claude Code]], [[AWS/Bedrock]]
2+
alias:: [[Anthropic/App/Claude Code/Bedrock/How To/Get Around Security Token Timeout]]
3+
4+
- # How To Handle Security Token Expiration Errors with Claude Code and AWS Bedrock
5+
- ## Problem
6+
- When using [[Claude Code]] with [[AWS/Bedrock]], you may encounter the error:
7+
- ```
8+
API Error: The security token included in the request is expired
9+
```
10+
- This occurs when AWS credentials (STS tokens, SSO sessions, etc.) have expired and Claude Code needs to refresh them.
11+
- ## Expected Behavior
12+
- According to the [official documentation](https://code.claude.com/docs/en/amazon-bedrock), Claude Code should automatically detect expired credentials and run your configured `awsAuthRefresh` command before retrying the request.
13+
- Detection happens in two ways:
14+
- **Local detection**: Based on credential timestamp in `~/.aws/credentials` or SSO cache
15+
- **Remote detection**: When Bedrock returns a credential error (like the expired token error)
16+
- ## Configuration
17+
- ### Basic Setup
18+
- Add `awsAuthRefresh` to your Claude Code settings file (`~/.claude/settings.json`):
19+
- ```json
20+
{
21+
"awsAuthRefresh": "aws sso login --profile myprofile",
22+
"env": {
23+
"AWS_PROFILE": "myprofile",
24+
}
25+
}
26+
```
27+
- ### Command Types
28+
- **`awsAuthRefresh`**: For commands that modify the `.aws` directory (credentials, SSO cache, config files)
29+
- Output is shown to the user
30+
- User input is NOT supported (see [GitHub Issue #11264](https://github.com/anthropics/claude-code/issues/11264) for feature request to support interactive authentication)
31+
- Suitable for browser-based authentication flows
32+
- **Limitation**: Interactive authentication tools (like `gimme-aws-creds` with password/MFA prompts) cannot be used with `awsAuthRefresh` currently
33+
- **`awsCredentialExport`**: For commands that output credentials directly as JSON
34+
- Output is captured silently (not shown)
35+
- Must output JSON in this format:
36+
- ```json
37+
{
38+
"Credentials": {
39+
"AccessKeyId": "value",
40+
"SecretAccessKey": "value",
41+
"SessionToken": "value"
42+
}
43+
}
44+
```
45+
- **Example Commands**:
46+
- **Using AWS STS assume-role with jq** (most common):
47+
- ```json
48+
"awsCredentialExport": "aws sts assume-role --role-arn arn:aws:iam::123456789012:role/MyRole --role-session-name mysession | jq '{Credentials: .Credentials | {AccessKeyId, SecretAccessKey, SessionToken}}'"
49+
```
50+
- Reference: [AWS CLI Command Reference: assume-role](https://docs.aws.amazon.com/cli/latest/reference/sts/assume-role.html)
51+
- **Using AWS STS get-session-token with jq**:
52+
- ```json
53+
"awsCredentialExport": "aws sts get-session-token | jq '{Credentials: .Credentials | {AccessKeyId, SecretAccessKey, SessionToken}}'"
54+
```
55+
- Reference: [AWS CLI Command Reference: get-session-token](https://docs.aws.amazon.com/cli/latest/reference/sts/get-session-token.html)
56+
- **Using a custom script**:
57+
- ```json
58+
"awsCredentialExport": "/path/to/generate_aws_grant.sh"
59+
```
60+
- The script should output the JSON format shown above to stdout
61+
- Reference: [Claude Code Settings Documentation](https://code.claude.com/docs/en/settings) - See `awsCredentialExport` setting
62+
- **Using AWS CLI export-credentials** (if your AWS CLI version supports it):
63+
- ```json
64+
"awsCredentialExport": "aws configure export-credentials --profile myprofile --format json | jq '{Credentials: {AccessKeyId: .AccessKeyId, SecretAccessKey: .SecretAccessKey, SessionToken: .SessionToken}}'"
65+
```
66+
- Reference: [AWS CLI Command Reference: configure export-credentials](https://docs.aws.amazon.com/cli/latest/reference/configure/export-credentials.html)
67+
- **Using a wrapper script with environment variables**:
68+
- ```json
69+
"awsCredentialExport": "bash -c 'aws sts assume-role --role-arn $AWS_ROLE_ARN --role-session-name $SESSION_NAME | jq \"{Credentials: .Credentials | {AccessKeyId, SecretAccessKey, SessionToken}}\"'"
70+
```
71+
- References:
72+
- [AWS CLI Command Reference: assume-role](https://docs.aws.amazon.com/cli/latest/reference/sts/assume-role.html)
73+
- [jq Manual](https://stedolan.github.io/jq/manual/) - For [[jq]] filter syntax
74+
- **Important Notes**:
75+
- The command must output **only** valid JSON to stdout (no error messages or other output)
76+
- Use `jq` to filter AWS STS output, as it includes additional fields (`Expiration`, `AssumedRoleUser`, etc.) that Claude Code doesn't need
77+
- Ensure `jq` is available in Claude Code's PATH if your command uses it
78+
- For commands with pipes, you may need to wrap them in `bash -c` or `sh -c`
79+
- Test your command manually first to ensure it outputs the correct JSON format
80+
- ## Troubleshooting: When Automatic Refresh Doesn't Work
81+
- ### Issue: Command Not Triggering
82+
- If you see the expired token error but no indication that `awsAuthRefresh` ran:
83+
- **Check command path**: Ensure your command is in your PATH when Claude Code runs
84+
- Claude Code may not have access to the same PATH as your shell
85+
- Try using the full path: `"/usr/local/bin/aws sso login --profile myprofile"`
86+
- **Check command syntax**: Verify the command works when run manually
87+
- ```bash
88+
aws sso login --profile myprofile
89+
```
90+
- **Check permissions**: Ensure Claude Code has permission to execute the command
91+
- Check your `permissions` settings in `settings.json`
92+
- May need to add: `"Bash(aws:*)"` to allowed commands
93+
- **Workaround**: Manually refresh credentials before using Claude Code
94+
- ```bash
95+
aws sso login --profile myprofile
96+
```
97+
- Then retry your Claude Code request
98+
- ### Issue: Credentials Refreshed But Not Used (Known Bug)
99+
- **Symptom**: `awsAuthRefresh` runs successfully and credentials are updated in `~/.aws/credentials`, but Claude Code still fails with expired token errors
100+
- **Cause**: This is a [known bug in Claude Code](https://github.com/anthropics/claude-code/issues/3823) where the refreshed credentials aren't always picked up after `awsAuthRefresh` completes
101+
- **Workaround**: Exit and resume Claude Code to force it to reload credentials
102+
- Exit Claude Code: `Ctrl+C` or `exit`
103+
- Resume with: `claude -r` (resume last session)
104+
- This forces Claude Code to reload credentials from `~/.aws/credentials`
105+
- **Alternative Workaround**: Use `awsCredentialExport` instead of `awsAuthRefresh`
106+
- `awsCredentialExport` directly provides credentials to Claude Code, bypassing the credential file reload issue
107+
- See the `awsCredentialExport` examples above
108+
- **Note**: The issue tracker includes a request for a `/refresh-credential` command to manually trigger credential reload without exiting
109+
- ### Issue: Command Not Found
110+
- If your refresh command isn't available in Claude Code's environment:
111+
- **Option 1**: Use full path to the command
112+
- Find command location: `which aws` or `command -v aws`
113+
- Use full path in `awsAuthRefresh`: `"/usr/local/bin/aws sso login --profile myprofile"`
114+
- **Option 2**: Use direct script path
115+
- If you have a custom refresh script, reference it directly:
116+
- ```json
117+
"awsAuthRefresh": "/path/to/refresh_credentials.sh"
118+
```
119+
- **Option 3**: Use `awsCredentialExport` with a wrapper script
120+
- Create a script that outputs credentials in the required JSON format
121+
- See examples in the `awsCredentialExport` section above
122+
- ### Issue: Interactive Commands
123+
- If your refresh command requires user interaction (like password entry, MFA approval, Touch ID):
124+
- Claude Code's `awsAuthRefresh` shows output but doesn't support user input
125+
- This may cause the command to hang or fail
126+
- **Current Workaround**: Use `awsCredentialExport` instead, or ensure your command can run non-interactively
127+
- **Future Enhancement**: [GitHub Issue #11264](https://github.com/anthropics/claude-code/issues/11264) requests support for interactive `awsAuthRefresh` to enable enterprise authentication flows (gimme-aws-creds, saml2aws, etc.)
128+
- **Alternative**: For now, manually refresh credentials in a separate terminal before using Claude Code
129+
- ### Issue: Environment Variables Not Available
130+
- If your refresh command needs specific environment variables:
131+
- Add them to the `env` section of your settings.json
132+
- Example:
133+
- ```json
134+
{
135+
"awsAuthRefresh": "aws sso login --profile myprofile",
136+
"env": {
137+
"AWS_PROFILE": "myprofile",
138+
"OP_SESSION_myorg": "your-session-token",
139+
"PATH": "/custom/path:$PATH"
140+
}
141+
}
142+
```
143+
- ## Manual Refresh Workflow
144+
- When automatic refresh fails, use this workflow:
145+
1. **Check current credentials**:
146+
- ```bash
147+
aws sts get-caller-identity --profile myprofile
148+
```
149+
2. **Refresh credentials**:
150+
- ```bash
151+
aws sso login --profile myprofile
152+
```
153+
3. **Verify new credentials**:
154+
- ```bash
155+
aws sts get-caller-identity --profile myprofile
156+
```
157+
4. **Retry Claude Code request**
158+
- ## Related Pages
159+
- [[Claude Code/Bedrock]] - Main Bedrock integration guide
160+
- [[mise/Task/How To/invoke aws_okta_keyman from mise with a configuration that references a default AWS account]] - Example of setting up credential refresh scripts
161+
- [[Claude Code/Settings]] - Claude Code settings documentation
162+
- ## References
163+
- [Claude Code on Amazon Bedrock - Advanced Credential Configuration](https://code.claude.com/docs/en/amazon-bedrock#advanced-credential-configuration)
164+
- [Claude Code Settings Documentation](https://code.claude.com/docs/en/settings)
165+
- [GitHub Issue #3823: CC not taking the updated credentials with awsAuthRefresh](https://github.com/anthropics/claude-code/issues/3823) - Known bug where refreshed credentials aren't always used
166+
- [GitHub Issue #11264: Interactive awsAuthRefresh](https://github.com/anthropics/claude-code/issues/11264) - Feature request to support interactive authentication flows (password/MFA prompts) within Claude Code

pages/Claude Code___Plugin___Marketplace___Report___25___11___Precedents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tags:: [[AI Deep Research]], [[Report]]
1515
- A large community-maintained marketplace with 84 agents, 63 plugins, and 47 skills.
1616
- Implements an internal `/plugin marketplace add` command for plugin management and orchestration, facilitating user-driven plugin registration and discovery.
1717
- Features a progressive disclosure architecture for skills, likely mapping to manifest-driven discovery and dependency definition.
18-
- #### 1.1.4. [davila7/claude-code-templates](https://github.com/davila7/claude-code-templates)
18+
- #### 1.1.4. [davila7/claude-code-templates](https://github.com/davila7/claude-code-templates) - see also [Claude Code Templates - Supercharge Your AI-Powered Development with Anthropic's Claude Code](https://www.aitmpl.com/hooks)
1919
- A CLI-driven plugin/skill marketplace focused on Claude Code setups.
2020
- Offers over 100 modular components (agents, commands, MCPs, hooks, skills) and a plugin dashboard.
2121
- Includes extensive documentation (docs.aitmpl.com), analytics, and possible health-check utilities.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- [Quickstart: LangSmith Essentials - LangChain Academy](https://academy.langchain.com/courses/take/quickstart-langsmith-essentials/lessons/70020762-online-evaluation-insights)
2+
- [[My Notes]]
3+
- Pretty useful! Quite a few new things
4+
- I learned about Waterfall view in LangSmith trace, which I wasn't as familiar with
5+
- Has some demos of a new insights dashboard
6+
- https://docs.langchain.com/langsmith/insights
7+
- once again, it requires either an Anthropic or OpenAI key - likely does not work with Bedrock or Azure

pages/Person___Daniel Avila___GitHub___claude-code-templates.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
alias:: [[aitmpl.com]]
2+
13
- # [Claude Code Templates (aitmpl.com)](https://github.com/davila7/claude-code-templates)
24
- Repository: [davila7/claude-code-templates](https://github.com/davila7/claude-code-templates)
35
- [[Person/Daniel Avila/GitHub/claude-code-templates/DeepWiki]] #DeepWiki
@@ -90,5 +92,4 @@
9092
- **Commands Collection:**
9193
- **awesome-claude-code Commands** by hesreallyhim - Licensed under CC0 1.0 Universal (21 commands)
9294
- ## License
93-
- MIT License - see the [LICENSE file](https://github.com/davila7/claude-code-templates/blob/main/LICENSE) for details
94-
95+
- MIT License - see the [LICENSE file](https://github.com/davila7/claude-code-templates/blob/main/LICENSE) for details

0 commit comments

Comments
 (0)