If the AWS API key and secret which you use and and are stored in ~/.aws/credentials
in
a profile called default
then you don't need to set the SOURCE_PROFILE_NAME
in the code.
If the profile name in ~/.aws/credentials
is something other than default
then set
SOURCE_PROFILE_NAME
to that name. For example if your ~/.aws/credentials
looked like this
[infosec-prod]
aws_access_key_id=ABCDEFGHIJKLMNOPQRST
aws_secret_access_key=abcdefghijklmnopqrstuvwxyz012345689/+ABC
then you would need to set line 5 in get-sts-session.sh
to
SOURCE_PROFILE_NAME=infosec-prod
If you use an MFA token with your IAM user, make sure that in your ~/.aws/config
file
where you have your profile configured there is an mfa_serial
set in that profile. For
example, if you login with a profile called infosec-prod
make sure your ~/.aws/config
looks like this
[profile infosec-prod]
region = us-west-2
mfa_serial = arn:aws:iam::123456789012:mfa/jdoe
- To cache your MFA serial so you don't need to keep entering it :
get-sts-session.sh 012345
- To assume an IAM role :
get-sts-session.sh 012345 arn:aws:iam::123456789012:role/MyIAMRole
- To assume an IAM role and enter the MFA code interactively :
get-sts-session.sh arn:aws:iam::123456789012:role/MyIAMRole
- To set the optional name of your session :
get-sts-session.sh arn:aws:iam::123456789012:role/MyIAMRole production
- To assume the IAM role set in your
DEFAULT_ASSUMED_ROLE_ARN
variable in the script :get-sts-session.sh 012345
The order of the three possible arguments doesn't matter
- MFA code
- IAM Role ARN
- Name to give the session