Skip to content

Instantly share code, notes, and snippets.

@nikhilw
Last active January 5, 2018 12:21
Show Gist options
  • Save nikhilw/35f537b184eb0d707cb8a48cb32dd324 to your computer and use it in GitHub Desktop.
Save nikhilw/35f537b184eb0d707cb8a48cb32dd324 to your computer and use it in GitHub Desktop.
This script loads aws cli profile configure as aws environment configuration
#! /bin/sh
# aws cli works with both: environment variables and values configured with `aws configure`.
# If our own script come to use env variables, like in case where we need to guess the url of a ECR reposiroty,
# there is hardly any support to load the profile values into environment.
# This script does just that!
set -e
profile="default"
#echo $profile
[ "$1" = "" ] || profile=$1
#echo "value: " $1
echo "Reading from profile: " $profile
export AWS_ACCESS_KEY_ID=`aws configure get aws_access_key_id --profile $profile`
export AWS_SECRET_ACCESS_KEY=`aws configure get aws_secret_access_key --profile $profile`
export AWS_DEFAULT_REGION=`aws configure get region --profile $profile`
# Some custom values added to aws config files
export AWS_ACCOUNT_ID=`aws configure get aws_account_id --profile $profile`
export AWS_PROFILE=`aws configure get aws_profile --profile $profile`
echo "new values: " \
"AWS_ACCESS_KEY_ID: '"$AWS_ACCESS_KEY_ID"', "\
"AWS_SECRET_ACCESS_KEY: '"$AWS_SECRET_ACCESS_KEY"', " \
"AWS_DEFAULT_REGION: '"$AWS_DEFAULT_REGION"', " \
"AWS_ACCOUNT_ID: '"$AWS_ACCOUNT_ID"', " \
"AWS_PROFILE: '"$AWS_PROFILE"'"
# How to run:
# A script cannot export variables into the calling shell, so run it like this:
# . aws_load_config.sh [profile_name]
# OR
# source aws_load_config.sh [profile_name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment