Skip to content

Instantly share code, notes, and snippets.

@k-kawashiman
Forked from outofcoffee/find-ecr-image.sh
Created May 26, 2021 08:27
Show Gist options
  • Save k-kawashiman/03b4cac0d83d53478e05517ab0033630 to your computer and use it in GitHub Desktop.
Save k-kawashiman/03b4cac0d83d53478e05517ab0033630 to your computer and use it in GitHub Desktop.
Check if Docker image exists with tag in AWS ECR
#!/usr/bin/env bash
# Example:
# ./find-ecr-image.sh foo/bar mytag
if [[ $# -lt 2 ]]; then
echo "Usage: $( basename $0 ) <repository-name> <image-tag>"
exit 1
fi
IMAGE_META="$( aws ecr describe-images --repository-name=$1 --image-ids=imageTag=$2 2> /dev/null )"
if [[ $? == 0 ]]; then
IMAGE_TAGS="$( echo ${IMAGE_META} | jq '.imageDetails[0].imageTags[0]' -r )"
echo "$1:$2 found"
else
echo "$1:$2 not found"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment