Skip to content

AWS_PROFILE is ignored when AWS_ROLE_ARN is set #8883

Closed
@Slevy35

Description

@Slevy35

Describe the bug

when using the environment variable AWS_PROFILE, if the AWS_ROLE_ARN env exists the profile env is ignored.
but when using the --profile the new profile is used.

Expected Behavior

AWS_PROFILE should not get override

Current Behavior

AWS_PROFILE env is ignored if AWS_ROLE_ARN is set

Reproduction Steps

run aws configure

aws configure set --profile <NEW_PROFILE> web_identity_token_file /var/run/secrets/eks.amazonaws.com/serviceaccount/token
aws configure set --profile <NEW_PROFILE> ****
aws configure set --profile <NEW_PROFILE> region cn-north-1

run aws sts get-caller-identity

root:/# env |  grep -i aws
AWS_DEFAULT_REGION=us-east-1
AWS_REGION=us-east-1
AWS_ROLE_ARN=<CURRENT_ROLE_ARN>
AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token
AWS_STS_REGIONAL_ENDPOINTS=regional
root:/# AWS_PROFILE=<NEW_PROFILE> aws sts get-caller-identity --region cn-north-1

An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid
root:/# unset AWS_ROLE_ARN
root:/# AWS_PROFILE=<NEW_PROFILE> aws sts get-caller-identity --region cn-north-1
{
    "UserId": "***",
    "Account": "***",
    "Arn": "arn:aws-cn:sts::****:assumed-role/****"
}

Possible Solution

No response

Additional Information/Context

No response

CLI version used

aws-cli/2.17.33 Python/3.11.9 Linux/5.10.219-208.866.amzn2.x86_64 exe/x86_64.debian.11

Environment details (OS name and version, etc.)

docker image python:3.11-slim-bullseye

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.closed-for-stalenessconfigurationp2This is a standard priority issueresponse-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions