inherit aws profile from active terminal session when entering "q chat"
Checks
- [x] I have searched github.com/aws/amazon-q-developer-cli/issues and there are no duplicates of my issue
Operating system
macOS 15.5.0 (24F74)
Expected behaviour
When using granted to assume an AWS role in the CLI, q chat ignores the active AWS profile and region from the terminal session and defaults to the profile/region from the AWS config file instead.
q chat should inherit the AWS profile and region from the active terminal session (environment variables like AWS_PROFILE, AWS_REGION, etc.)
Actual behaviour
Terminal shows active profile: AWS_PROFILE=AIX-test and AWS_REGION=eu-central-1 q chat uses Profile name: default and Region: us-east-1 instead
Steps to reproduce
Use granted (or similar tool) to assume an AWS role. Verify environment variables are set correctly: env | grep AWS Start q chat Try AWS operations - they use default profile/region instead of active session
Thanks for reporting this!
We currently support customizing the endpoint and region via the following command:
q settings api.codewhisperer.service '{ "endpoint": "your-endpoint", "region": "your-region" }'
This allows you to override the default region/profile behavior. Let us know if it doesn’t work as expected in your environment.
I tried it but it didn't work. Please let me know if I'm doing something wrong:
q settings api.codewhisperer.service '{ "profile": "AIX-test", "region": "eu-central-1" }'
❯ assume AIX-test
[23-06-2025 22:03:50] [INFO] Assuming role: AIX-test
❯ q chat
> list s3 buckets
I'll list your S3 buckets using the AWS CLI.
🛠️ Using tool: use_aws (trusted)
⋮
● Running aws cli command:
Service name: s3api
Operation name: list-buckets
Parameters:
Profile name: default
Region: us-east-1
Label: List all S3 buckets
⋮
● Execution failed after 0.769s:
An error occurred (AccessDenied) when calling the ListBuckets operation:
Access denied is normal since I'm not allowed to run commands in us-east-1.
I would expect now that it uses the profile and region I assumed before I started q chat
Thanks for the follow-up!
Just to clarify: q settings currently does not support setting the profile—it only supports overriding the endpoint and region. If you'd like to use a specific profile, please use 1. q login to log in with that profile, or 2. use q profile to view and select an existing one.
To avoid overriding your session unintentionally, you can remove the previous override by running:
q settings -d api.codewhisperer.service
When resolving region and endpoint, Q CLI gives priority in the following order:
- Values set via q settings
- Values from the currently selected profile
You can verify the active profile and region using:
q whoami
Let us know if that helps!
when I run q whoami it knows which profile is active, so it would be a good dev experience if it automatically uses that profile automatically when I start the q chat session, see output:
🤖 You are chatting with claude-4-sonnet
> q whoami
🛠️ Using tool: use_aws (trusted)
⋮
● Running aws cli command:
Service name: sts
Operation name: get-caller-identity
Parameters:
Profile name: default
Region: us-east-1
Label: Get current AWS caller identity
⋮
● Completed in 1.44s
You're currently authenticated as:
• **User ID**: <marked private>
• **Account ID**: <marked private>
• **Role**: <marked private>
• **ARN**: <marked private>
You're using AWS SSO with PowerUser access in the eu-central-1 region. This gives you broad permissions across AWS services while maintaining
centralized identity management through your organization's SSO setup.
so what's even more strange is after running the command q whoami listed above when I run the prompt list s3 buckets then it works and picks my active profile. But this only happens when I run q whoami before that prompt. Let me show you the full session so you have a clear picture of what I mean:
❯ arp AIX-test
[25-06-2025 10:37:42] [INFO] Assuming role: AIX-test
❯ q chat
⢠⣶⣶⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣿⣿⣿⣶⣦⡀⠀
⠀⠀⠀⣾⡿⢻⣿⡆⠀⠀⠀⢀⣄⡄⢀⣠⣤⣤⡀⢀⣠⣤⣤⡀⠀⠀⢀⣠⣤⣤⣤⣄⠀⠀⢀⣤⣤⣤⣤⣤⣤⡀⠀⠀⣀⣤⣤⣤⣀⠀⠀⠀⢠⣤⡀⣀⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⢠⣿⣿⠋⠀⠀⠀⠙⣿⣿⡆
⠀⠀⣼⣿⠇⠀⣿⣿⡄⠀⠀⢸⣿⣿⠛⠉⠻⣿⣿⠛⠉⠛⣿⣿⠀⠀⠘⠛⠉⠉⠻⣿⣧⠀⠈⠛⠛⠛⣻⣿⡿⠀⢀⣾⣿⠛⠉⠻⣿⣷⡀⠀⢸⣿⡟⠛⠉⢻⣿⣷⠀⠀⠀⠀⠀⠀⣼⣿⡏⠀⠀⠀⠀⠀⢸⣿⣿
⠀⢰⣿⣿⣤⣤⣼⣿⣷⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⢀⣴⣶⣶⣶⣿⣿⠀⠀⠀⣠⣾⡿⠋⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⡇⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⢹⣿⣇⠀⠀⠀⠀⠀⢸⣿⡿
⢀⣿⣿⠋⠉⠉⠉⢻⣿⣇⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⣿⣿⡀⠀⣠⣿⣿⠀⢀⣴⣿⣋⣀⣀⣀⡀⠘⣿⣿⣄⣀⣠⣿⣿⠃⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠈⢿⣿⣦⣀⣀⣀⣴⣿⡿⠃
⠚⠛⠋⠀⠀⠀⠀⠘⠛⠛⠀⠘⠛⠛⠀⠀⠀⠛⠛⠀⠀⠀⠛⠛⠀⠀⠙⠻⠿⠟⠋⠛⠛⠀⠘⠛⠛⠛⠛⠛⠛⠃⠀⠈⠛⠿⠿⠿⠛⠁⠀⠀⠘⠛⠃⠀⠀⠘⠛⠛⠀⠀⠀⠀⠀⠀⠀⠀⠙⠛⠿⢿⣿⣿⣋⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠿⢿⡧
╭─────────────────────────────── Did you know? ────────────────────────────────╮
│ │
│ You can enable custom tools with MCP servers. Learn more with │
│ /help │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯
/help all commands • ctrl + j new lines • ctrl + s fuzzy search
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🤖 You are chatting with claude-4-sonnet
> list s3 buckets
I'll list your S3 buckets using the AWS CLI.
🛠️ Using tool: use_aws (trusted)
⋮
● Running aws cli command:
Service name: s3api
Operation name: list-buckets
Parameters:
Profile name: default
Region: us-east-1
Label: List all S3 buckets
⋮
● Execution failed after 0.648s:
An error occurred (AccessDenied) when calling the ListBuckets operation: User: <arn> is not authorized to perform: s3:ListAllMyBuckets with an explicit deny in a service control policy
It looks like your AWS account has a service control policy that's preventing you from listing S3 buckets. The error shows you're using a PowerUser
role through AWS SSO, but there's an explicit deny policy blocking the s3:ListAllMyBuckets permission.
This is likely an organizational policy restriction. You'll need to:
1. Contact your AWS administrator to request access to list S3 buckets
2. Or use a different IAM role/user that has the necessary S3 permissions
3. Or if you know specific bucket names, you can still interact with individual buckets using commands like:
bash
aws s3 ls s3://your-bucket-name
Would you like ^C
> q whoami
I'll check your AWS identity using the AWS CLI.
🛠️ Using tool: use_aws (trusted)
⋮
● Running aws cli command:
Service name: sts
Operation name: get-caller-identity
Profile name: default
Region: us-east-1
Label: Get current AWS caller identity
⋮
● Completed in 0.726s
Here's your current AWS identity:
• **User ID**: <marked private>
• **Account**: <marked private>
• **Role**: <marked private>
You're currently authenticated as a PowerUser through AWS SSO in the eu-central-1 region.
> list s3 buckets
I'll list your S3 buckets using the AWS CLI.
🛠️ Using tool: use_aws (trusted)
⋮
● Running aws cli command:
Service name: s3api
Operation name: list-buckets
Profile name: default
Region: eu-central-1
Label: List all S3 buckets
⋮
● Completed in 0.370s
Here are your S3 buckets in account <marked private>:
Service-related buckets:
• <shows all buckets>
fyi the granted tool also exports the env vars in my terminal session automatically:
AWS_ACCESS_KEY_ID=<market private>
AWS_SECRET_ACCESS_KEY=<market private>
AWS_SESSION_TOKEN=<market private>
AWS_PROFILE=AIX-test
AWS_REGION=eu-central-1
AWS_DEFAULT_REGION=eu-central-1
AWS_SESSION_EXPIRATION=2025-06-25T18:37:42+02:00
AWS_CREDENTIAL_EXPIRATION=2025-06-25T18:37:42+02:00