This works fine for me using zsh. I put it in a file called .functions that gets sourced when I login.
Assumptions:
- you have a AWS credentials file that looks something like this:
[Credentials]
aws_access_key_id = <key_id>
aws_secret_access_key = <secret_key_id>
region = us-east-1
[profile testing-scratch]
aws_access_key_id = <key_id>
aws_secret_access_key = <secret_key_id>
region = us-west-2
[profile testing-dev]
aws_access_key_id = <key_id>
aws_secret_access_key = <secret_key_id>
region = us-west-2
- aws CLI installed.
The function:
aws-env-vars () {
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_DEFAULT_REGION
unset EC2_REGION
unset AWS_DEFAULT_PROFILE
export AWS_ACCESS_KEY_ID=`aws configure get aws_access_key_id --profile $1`
export AWS_SECRET_ACCESS_KEY=`aws configure get aws_secret_access_key --profile $1`
export AWS_DEFAULT_REGION=`aws configure get region --profile $1`
export EC2_REGION=`aws configure get region --profile $1`
export AWS_DEFAULT_PROFILE=$1
}
To run:
aws-env-vars <profile-name>