Skip to content

Conversation

binhao22
Copy link

Support AWS_PROFILE environment variable in use_aws tool

Description

This PR implements support for the AWS_PROFILE environment variable in the use_aws tool to align with AWS CLI credential precedence behavior.

Closes #2088

Background

The use_aws tool currently ignores the AWS_PROFILE environment variable and always defaults to the "default" profile, which breaks expected AWS CLI behavior consistency. This is particularly problematic for users with SSO authentication workflows who rely on environment variables for profile switching.

Changes

This implementation follows AWS CLI credential precedence:

  1. Explicit profile_name parameter (highest priority)
  2. AWS_PROFILE environment variable
  3. "default" profile (lowest priority)

Modified Files

  • Updated profile resolution logic to check AWS_PROFILE environment variable before defaulting to "default"
  • Maintained backward compatibility with existing explicit profile_name parameter usage
  • Added appropriate error handling for invalid profile names

Testing

  • Verified that explicit profile_name parameter still takes precedence
  • Confirmed AWS_PROFILE environment variable is respected when no explicit profile is specified
  • Ensured fallback to "default" profile works when neither is set
  • Tested with SSO-configured profiles
  • Validated behavior matches standard AWS CLI precedence

Agent Configuration Examples

{
  "$schema": "https://raw.githubusercontent.com/aws/amazon-q-developer-cli/refs/heads/main/schemas/agent-v1.json",
  "name": "test-profile",
  "description": "AWS agent with test-profile profile as default",
  "tools": ["*"],
  "allowedTools": ["use_aws", "fs_read", "fs_write", "execute_bash"],
  "toolsSettings": {
    "use_aws": {
      "profile_name": "test-profile"
    }
  }
}

Testing Result

Before (Issue)

Problem: AWS_PROFILE environment variable ignored

스크린샷 2025-09-18 오전 9 56 30

After (Fixed)

Solution: AWS_PROFILE environment variable respected

스크린샷 2025-09-18 오전 9 55 37

Breaking Changes

None. This change is fully backward compatible.

Impact

  • ✅ Improves consistency with AWS CLI behavior
  • ✅ Enhances user experience for SSO workflows
  • ✅ Reduces need for explicit profile specification
  • ✅ Maintains all existing functionality

Checklist

Additional Notes

This implementation specifically benefits users who:

  • Use AWS SSO authentication
  • Rely on environment variables for profile management
  • Switch between multiple AWS profiles regularly
  • Expect consistent behavior between AWS CLI and Amazon Q Developer CLI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use_aws tool ignores AWS_PROFILE environment variable, defaults to 'default' profile
1 participant