Skip to content
Ercan Ermis
Ercan Ermis

notes for everyone about cloud technology

  • Cloud
    • AWS
    • GCP
  • Container
    • Kubernetes
    • Docker
  • Linux
  • DevOps
  • Privacy Policy
  • Contact
Ercan Ermis

notes for everyone about cloud technology

Update ECR Repositories with Bash Script

Ercan, April 8, 2025April 8, 2025

Below is an example Bash script that uses the AWS CLI to retrieve all your Amazon ECR repositories and then sets the image tag mutability of each repository to MUTABLE. Before running the script, ensure you have the AWS CLI installed and configured with appropriate permissions.

#!/bin/bash
# This script fetches all Amazon ECR repositories and sets their image tag mutability to MUTABLE.

# Fetch all repository names from ECR.
repositories=$(aws ecr describe-repositories --query "repositories[].repositoryName" --output text)

# Check if any repositories were found.
if [ -z "$repositories" ]; then
  echo "No ECR repositories found."
  exit 1
fi

# Loop over each repository and update its image tag mutability.
for repo in $repositories; do
  echo "Setting image tag mutability to MUTABLE for repository: $repo"
  aws ecr put-image-tag-mutability --repository-name "$repo" --image-tag-mutability MUTABLE | tee
  
  if [ $? -eq 0 ]; then
    echo "Successfully updated $repo"
  else
    echo "Failed to update $repo"
  fi
done

Explanation

  • Fetching repositories:
    The script starts by running aws ecr describe-repositories to retrieve a list of repository names using a JMESPath query. The --output text option formats the output as plain text.
  • Check for no repositories:
    It checks if the $repositories variable is empty. If no repositories are found, it exits with a message.
  • Loop and update mutability:
    For each repository name, the script calls aws ecr put-image-tag-mutability setting the --image-tag-mutability flag to MUTABLE.
    A success or failure message is printed based on the exit status of each command.
  • Permissions and AWS CLI configuration:
    Make sure your AWS CLI is correctly configured (for example, via aws configure) with credentials that have permissions to perform describe-repositories and put-image-tag-mutability actions in ECR.

This script automates the process of ensuring all repositories are mutable when it comes to image tags, making future updates or tagging changes possible.

Share on Social Media
x facebook linkedin reddit
AWS

Post navigation

Previous post
Next post
  • AWS (45)
    • Serverless (4)
  • Best (9)
  • DevOps (16)
  • Docker (10)
  • GCP (3)
  • Kubernetes (3)
  • Linux (13)
  • Uncategorized (6)

Recent Posts

  • Automating AWS CloudWatch Log Group Tagging with Python and Boto3
  • Automating AWS ECR Tagging with Python and Boto3
  • Automating ECR Image Cleanup with Bash
  • Update ECR Repositories with Bash Script
  • Why Automated Tests Are Essential in Your CI/CD Pipeline and Development Flow
  • Streamline Your AWS ECR Management with This Powerful Bash Script
  • Setting up DKIM for Google Workspace (Gmail) using Terraform and AWS Route 53
  • Automate AWS Site-to-Site VPN Monitoring
  • Optimizing Docker Images: Tips for Reducing Image Size and Build Time
  • Monitoring EC2 Disk Space with a Simple Bash Script and Slack Alerts
  • Securing Docker Containers: Best Practices for Container Security
  • Mastering Dockerfile: Writing Efficient, Scalable Container Builds
  • Migrating a Git Repository from GitLab to GitHub with GPG-Signed Commits
  • Accessing AWS Services in Private Subnets Without 0.0.0.0/0
  • Understanding AWS Regions, Availability Zones, and VPCs: A Comprehensive Guide
©2025 Ercan Ermis | WordPress Theme by SuperbThemes