Skip to content

Instantly share code, notes, and snippets.

@mccutchen
Last active May 4, 2020 18:04
Show Gist options
  • Save mccutchen/d7902e2c8cd414cdd2b0 to your computer and use it in GitHub Desktop.
Save mccutchen/d7902e2c8cd414cdd2b0 to your computer and use it in GitHub Desktop.

Revisions

  1. mccutchen revised this gist Oct 23, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions export-aws-credentials
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env bash

    # When sourced, this script will export the AWS_ACCESS_KEY_ID and
    # When eval'd, the output from script will export the AWS_ACCESS_KEY_ID and
    # AWS_SECRET_ACCESS_KEY credentials from the a specific profile in
    # ~/.aws/credentials.
    #
    @@ -27,7 +27,7 @@ fi

    echo "Exporting profile: $profile" >&2
    for key in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY; do
    val=$(echo "$credentials" | grep -i $key | awk -F '=' '{print $2}')
    val=$(echo "$credentials" | grep -i $key | tr -d '[:space:]' | awk -F '=' '{print $2}')
    if [[ "$val" == "" ]]; then
    echo " Error: missing $key" >&2
    exit 1
  2. mccutchen revised this gist Jan 28, 2016. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions export-aws-credentials
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,13 @@
    #
    # export-aws-credentials [PROFILE]
    #
    # If PROFILE is not given, the "default" profile will be exported.
    # If PROFILE is not given, the "default" profile will be exported. The
    # output of this script is intended to be fed into `eval`.
    #
    # Examples:
    #
    # eval $(scripts/export_aws_credentials)
    # eval $(scripts/export_aws_credentials other-profile)
    # eval $(export-aws-credentials)
    # eval $(export-aws-credentials other-profile)

    [[ -z "$1" ]] && profile="default" || profile="$1"

  3. mccutchen revised this gist Jan 28, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion export-aws-credentials
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,6 @@
    # eval $(scripts/export_aws_credentials)
    # eval $(scripts/export_aws_credentials other-profile)


    [[ -z "$1" ]] && profile="default" || profile="$1"

    credentials=$(grep -A 2 "$profile" ~/.aws/credentials | grep -v "$profile")
  4. mccutchen revised this gist Jan 28, 2016. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion export-aws-credentials
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,15 @@
    #
    # Usage:
    #
    # eval $(scripts/export_aws_credentials.sh [PROFILE])
    # export-aws-credentials [PROFILE]
    #
    # If PROFILE is not given, the "default" profile will be exported.
    #
    # Examples:
    #
    # eval $(scripts/export_aws_credentials)
    # eval $(scripts/export_aws_credentials other-profile)


    [[ -z "$1" ]] && profile="default" || profile="$1"

  5. mccutchen created this gist Jan 28, 2016.
    30 changes: 30 additions & 0 deletions export-aws-credentials
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/usr/bin/env bash

    # When sourced, this script will export the AWS_ACCESS_KEY_ID and
    # AWS_SECRET_ACCESS_KEY credentials from the a specific profile in
    # ~/.aws/credentials.
    #
    # Usage:
    #
    # eval $(scripts/export_aws_credentials.sh [PROFILE])
    #
    # If PROFILE is not given, the "default" profile will be exported.

    [[ -z "$1" ]] && profile="default" || profile="$1"

    credentials=$(grep -A 2 "$profile" ~/.aws/credentials | grep -v "$profile")

    if [[ "$credentials" == "" ]]; then
    echo "Error: profile '$profile' not found in ~/.aws/credentials" >&2
    exit 1
    fi

    echo "Exporting profile: $profile" >&2
    for key in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY; do
    val=$(echo "$credentials" | grep -i $key | awk -F '=' '{print $2}')
    if [[ "$val" == "" ]]; then
    echo " Error: missing $key" >&2
    exit 1
    fi
    echo "export $key='$val'"
    done