How bluedoors/ecr-metrics works
Main Components
• Command-Line Tool / Script: The core logic lives in src/ecr_metrics/main.py.
• AWS Lambda Deployment: The README provides instructions for deploying the script as a Lambda function (with a note on setting the handler and customizing memory/timeout settings).
• AWS CloudWatch Events: To automate execution on a schedule (e.g., every 30 minutes).
• External AWS Services: Specifically, the AWS ECR API that the script queries.
• Supporting Files: These include configuration (pyproject.toml, .editorconfig, .gitignore), deployment configuration (Dockerfile and template.yml), and tests (in the tests directory), which overall support developing, building, testing, and deploying the project.
Relationships and Interactions
• The core script acts as the bridge between the AWS API and the end user by collecting metrics on repository count, image count per repository, and total image size.
• In an automated setup, the AWS Lambda function executes the script. CloudWatch Events trigger the Lambda function on a predefined schedule.
• Data flows from the AWS ECR service (queried via the AWS API) into the script, which then produces the metrics desired by the user/administrator.
• The Dockerfile and template.yml indicate that there is an option for container-based deployment or infrastructure-as-code deployment, reinforcing the idea of a flexible deployment model.
Architectural Patterns and Design Principles
• Separation of Concerns: Business logic (retrieving and computing metrics) is decoupled from deployment concerns (Lambda/CloudWatch):
• The src directory clearly isolates the application code.
• Deployment-specific details reside in Dockerfile and template.yml.
• Modularity and Testability: The presence of a tests directory with dedicated test files shows the importance placed on verifying functionality independently from the deployment target.