Skip to content

Instantly share code, notes, and snippets.

@EKami
Created April 13, 2023 03:33
Show Gist options
  • Save EKami/de6b5a7a24b17607d8ed70d80130e7f6 to your computer and use it in GitHub Desktop.
Save EKami/de6b5a7a24b17607d8ed70d80130e7f6 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "Please provide AWS credentials"
exit 1
fi
if [ -z "$IAM_ROLE_ARN" ]; then
echo "Please supply the IAM_ROLE_ARN parameter for ECR!"
exit 1
fi
creds_json=$(aws sts assume-role --role-arn $IAM_ROLE_ARN --role-session-name auto-deploy)
export AWS_ACCESS_KEY_ID=$(echo "$creds_json" | jq .Credentials.AccessKeyId | tr -d '"')
export AWS_SECRET_ACCESS_KEY=$(echo "$creds_json" | jq .Credentials.SecretAccessKey | tr -d '"')
export AWS_SESSION_TOKEN=$(echo "$creds_json" | jq .Credentials.SessionToken | tr -d '"')
# This last line will output only the docker pwd
aws ecr get-login-password --region "us-east-1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment