• DevOps
    Case Study

    How we built a resilient multi-account, multi-cloud solution for a Health Tech service provider!

    READ CASESTUDY
    icon

    24/7 DevOps as a Service

    Round-the-clock DevOps for uninterrupted efficiency.

    icon

    Infrastructure as a Code

    Crafting infrastructure with ingenious code.

    icon

    CI/CD Pipeline

    Automated CI/CD pipeline for seamless deployments.

    icon

    DevSecOps

    Integrated security in continuous DevOps practices.

    icon

    Hire DevOps Engineers

    Level up your team with DevOps visionaries.

    icon

    Consulting Services

    Navigate success with expert DevOps consulting.

  • TechOps
    Case Study

    How we built a scalable Odoo solution for a Travel Tech service provider!

    READ CASESTUDY

    WEB HOSTING SUPPORT

    icon

    HelpDesk Support

    Highly skilled 24/7 HelpDesk Support

    icon

    Product Support

    Boost your product support with our expertise.

    MANAGED SERVICES

    icon

    Server Management

    Don’t let server issues slow you down. Let us manage them for you.

    icon

    Server Monitoring

    Safeguard your server health with our comprehensive monitoring solutions.

    STAFF AUGMENTATION

    icon

    Hire an Admin

    Transform your business operations with our expert administrative support.

    icon

    Hire a Team

    Augment your workforce with highly skilled professionals from our diverse talent pool.

  • CloudOps
    Case Study

    How we helped a Private Deemed University in India, save US $3500/m on hosting charges!

    READ CASESTUDY
    icon

    AWS Well Architected Review

    Round-the-clock for uninterrupted efficiency

    icon

    Optimize

    Efficient CloudOps mastery for seamless cloud management

    icon

    Manage

    Automated CI/CD pipeline for seamless deployments

    icon

    Migrate

    Upgrade the journey, Migrate & Modernize seamlessly

    icon

    Modernize

    Simplify compliance complexities with our dedicated services

    icon

    FinOps as a Service

    FinOps as a Service

  • SecOps
    Case Study

    How we built a scalable Odoo solution for TravelTech service provider!

    READ CASESTUDY
    icon

    VAPT

    Vulnerability Assessment and Penetration Testing

    icon

    Source Code Review

    Ensuring source code security ans safe practices to reduce risks

    icon

    Security Consultation

    On demand services for improving server security

    icon

    System Hardening

    Reduced vulnerability and proactive protection

    icon

    Managed SoC

    Monitors and maintains system security. Quick response on incidents.

    icon

    Compliance as a Service

    Regulatory compliance, reduced risk

  • Insights
    Case Study

    How we helped a Private Deemed University in India, save US $3,500/m on hosting charges!

    READ CASESTUDY
    icon

    Blog

    Explore our latest articles and insights

    icon

    Case Studies

    Read about our client success stories

    icon

    Flipbook

    Explore our latest Flipbook

    icon

    Events

    Join us at upcoming events and conferences

    icon

    Webinars

    Watch our educational webinar series

  • Our Story
  • Contact Us

Interested to collaborate?

Get in touch with us!

Ready to elevate your business with certified cloud expertise? Contact us today to learn how our team can help you leverage cloud technology to drive growth, streamline operations, and enhance security.

  • AWSAWS
  • Azure CloudAzure Cloud
  • Google CloudGoogle Cloud
  • Akamai CloudAkamai Cloud
  • OVHOVH
  • Digital OceanDigital Ocean
  • HetznerHetzner
  • Kubernetes Consultancy Services
  • K8s & Cloud native Solutions
  • 24/7 Infrastructure Monitoring
  • DevOps as a Service
  • Cloud CI/CD Solutions
  • White Labeled MSP Support
  • Our story
  • Life@SupportSages
  • Insights
  • Careers
  • Events
  • Contact Us

Connect with us!


LinkedInFacebookXInstagramYouTube

aws partneraws advanced partner
SupportSages

Copyright © 2008 – 2026 SupportSages Pvt Ltd. All Rights Reserved.
Privacy PolicyLegal TermsData ProtectionCookie Policy
Managing AWS ECR Storage

Managing AWS ECR Storage

Arya P B

  • 3 min read
Managing AWS ECR Storage

Generating audio, please wait...

Amazon Elastic Container Registry (ECR) provides a scalable and secure solution for storing, managing, and deploying Docker container images. Over time, however, repositories may accumulate images and grow in size, leading to increased storage costs and potential performance issues. In this blog post, we will explore how to use AWS Lambda and Boto3 to identify ECR repositories exceeding a specified storage limit and discuss strategies for managing their sizes effectively.

Prerequisites:

Before diving into the implementation, make sure you have the following prerequisites in place:

  1. An AWS account with sufficient permissions to access ECR and Lambda services.
  2. Basic knowledge of Python programming.

Implementation:

Let’s break down the provided Python script and discuss its key components:




import boto3

def lambda_handler(event, context):
# Initialize ECR client
ecr_client = boto3.client('ecr')

# Retrieve a list of repositories in the account
repositories = ecr_client.describe_repositories()['repositories']

# Iterate through each repository
for repository in repositories:
repository_name = repository['repositoryName']

# Retrieve image details for the repository
images = ecr_client.describe_images(repositoryName=repository_name).get('imageDetails', [])

# Check if the repository has images
if images:
# Calculate the repository size in gigabytes
repository_size = images[0].get('imageSizeInBytes', 0)
repository_size_gb = repository_size / (1024 ** 3)

# Check if the repository size exceeds the specified limit (5GB in this case)
if repository_size_gb > 5:
print(f"Repository {repository_name} has a size of {repository_size_gb:.2f} GB, exceeding 5GB.")

else:
print(f"Repository {repository_name} has no images.")

return {
'statusCode': 200,
'body': 'Function execution completed successfully.'
}

Explanation:

  1. ECR Client Initialization: The script starts by initializing the ECR client using the boto3 library.
  2. List Repositories: It retrieves a list of ECR repositories associated with the AWS account using the describe_repositories method.
  3. Iterate Through Repositories: The script then iterates through each repository, extracting its name.
  4. Retrieve Image Details: For each repository, it retrieves image details using the describe_images method.
  5. Check Repository Size: If the repository has images, it calculates the total size of the repository in gigabytes and checks whether it exceeds the specified limit (5GB in this case).
  6. Print Results: The script prints information about repositories exceeding the size limit or having no images.
  7. Lambda Function Return: Finally, the Lambda function returns a response indicating the successful execution.

Lambda Setup Steps:

Create a Lambda Function:

  1. Go to the AWS Lambda console.
  2. Click on “Create function.”
  3. Choose “Author from scratch.”
  4. Provide a name for your function, choose the runtime as “Python 3.x,” and set up an execution role with necessary permissions for ECR access.

Once Lambda function is set up, it will automatically run based on the defined trigger. You can monitor its execution and view the results in the CloudWatch Logs.

Conclusion:

By deploying this AWS Lambda function, you can automate the process of identifying ECR repositories with sizes exceeding a predefined limit. You can use environment variables to customize the behavior of your Lambda function. For example, you might set a specific size limit as an environment variable.This proactive approach allows you to manage storage costs more effectively and ensures optimal performance for your containerized applications.

Streamline your ECR management and optimize storage costs! This blog post showed you how to use AWS Lambda and Boto3 to identify oversized ECR repositories. Implement the Python code we provided to automate finding ECR repositories exceeding a set storage limit. Take control of your container image storage and ensure cost-effectiveness today!

  • AWS
  • DevOps

Continue Your Journey With…

DevOps as a Service

DevOps as a Service

Let us do the heavy lifting for you

Promotional banner
Promotional banner

Analyzing AWS IAM Users: Access Key and Password Age

Analyzing AWS IAM Users: Access Key and Password Age
  • DevOps
logo

Analyzing AWS IAM Users: Access Key and Password Age

Analyzing AWS IAM Users: Access Key and Password Age
  • AWS
  • DevOps
logo

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide
  • DevOps
logo

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide
  • AWS
  • DevOps
logo

Posts by Arya P B

Athena