There are a few other posts related, but they didn't help solve my problem.
I have the script below that has an optional parameter for an aws profile -p
What I would like to do is save the profile configurations into environmental variables in the current shell.
#!/bin/bash
# This script is used to set an AWS profile for the current shell session.
# It is intended to be used with the AWS CLI and the AWS CLI v2.
usage() { echo "Usage: $0 [-p <string>]"; exit 1; }
while getopts "p:" options; do
case "${options}" in
p)
p=${OPTARG}
;;
esac
done
if [ -z "${p}" ]; then
export AWS_ACCESS_KEY_ID=$(aws configure get default.aws_access_key_id)
export AWS_SECRET_ACCESS_KEY=$(aws configure get default.aws_secret_access_key)
export AWS_DEFAULT_REGION=$(aws configure get default.region)
echo "Default profile set"
else
aws configure list-profiles | grep -q "${p}"
if [ $? -ne 0 ]; then
echo "Profile ${p} not found"
exit 1
else
export AWS_ACCESS_KEY_ID=$(aws configure get "${p}".aws_access_key_id)
export AWS_SECRET_ACCESS_KEY=$(aws configure get "${p}".aws_secret_access_key)
export AWS_DEFAULT_REGION=$(aws configure get "${p}".region)
fi
fi
I call the script like this
source ./set-aws-profile
However, when I look for environmental variables, I just get a new line
source ./set-aws-profile
Default profile set
% echo $AWS_ACCESS_KEY_ID
%
Probably something obvious, but any idea of what is wrong here?