Skip to content

Instantly share code, notes, and snippets.

@nikhilw
Last active January 5, 2018 12:21
Show Gist options
  • Select an option

  • Save nikhilw/35f537b184eb0d707cb8a48cb32dd324 to your computer and use it in GitHub Desktop.

Select an option

Save nikhilw/35f537b184eb0d707cb8a48cb32dd324 to your computer and use it in GitHub Desktop.

Revisions

  1. nikhilw revised this gist Jan 5, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion aws_load_config.sh
    Original file line number Diff line number Diff line change
    @@ -12,12 +12,13 @@ profile="default"
    [ "$1" = "" ] || profile=$1
    #echo "value: " $1

    echo "Choosing from profile: " $profile
    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`

  2. nikhilw revised this gist Jan 5, 2018. No changes.
  3. nikhilw created this gist Jan 5, 2018.
    35 changes: 35 additions & 0 deletions aws_load_config.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #! /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 "Choosing 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`

    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]