Skip to content

Instantly share code, notes, and snippets.

@daniilyar
Created May 16, 2019 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniilyar/2beba8e70584f34601c9196f0d258832 to your computer and use it in GitHub Desktop.
Save daniilyar/2beba8e70584f34601c9196f0d258832 to your computer and use it in GitHub Desktop.
AWS ECR token refresh script
#!/bin/bash
HELP_MSG="This script read the AWS credentials from the execution environment and does the docker-login via the AWS-CLI utility.\n
Available arguments: '-s' for the name of the ECR secret will add, '-p' for the profile, '-h' for this message."
while getopts :r:p:h: option
do
case "${option}"
in
r) AWS_REGION="$OPTARG";;
p) AWS_PROFILE="$OPTARG";;
h) NEED_HELP="1";;
*) NEED_HELP="1";;
esac
done
if [[ "$#" -eq 0 ]]
then
echo -e "$HELP_MSG"
exit 1
fi
if [[ "$NEED_HELP" -eq 1 ]]
then
echo -e "$HELP_MSG"
exit 1
fi
$(aws --region $AWS_REGION ecr get-login --no-include-email --profile $AWS_PROFILE)
@daniilyar
Copy link
Author

Usage example for cron:

0 * * * * /usr/local/bin/ecr_secrets_refresher.sh -p my_aws_profile -r us-east-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment