What should the DevOps engineer do next to meet the requirements in the MOST operationally efficient manner?
Create an AWS Lambda function to scan the images in each repository for the number of versions present. Configure the Lambda function to delete older versions of images if the number of images is greater than the desired number of images. Schedule the Lambda function to run automatically at regular intervals,
Create a repository policy that assesses the number of images and deletes older versions if the number of images is greater than the desired number of images. Apply the repository policy to each private repository.
Create an AWS Step Functions state machine Express Workflow to scan the images in each repository for the number of versions present. Configure the Express Workflow to delete older versions of images if the number of images is greater than the desired number of images. Configure the state machine to run every time an image is pushed to a repository.
Push an image into each private repository. In each private repository, create a lifecycle policy preview to delete older versions of images if the number of images is greater than the desired number of images. Test the lifecycle policy and validate the impact. Apply the lifecycle policy to manage the images.
Explanations:
While AWS Lambda can automate the deletion of images, this approach is more complex and less efficient compared to using Amazon ECR’s native lifecycle policies. It requires custom coding, scheduling, and management.
Repository policies do not have built-in capabilities to manage or delete images based on count or age. Amazon ECR lifecycle policies, not repository policies, are intended for such tasks.
AWS Step Functions can automate tasks but is overly complex for this use case. It requires the configuration of a state machine and additional overhead compared to the simpler solution provided by lifecycle policies.
This approach uses Amazon ECR’s built-in lifecycle policies to manage image versions efficiently. It allows for automated deletion of older images based on rules (e.g., number of versions), providing an operationally efficient and straightforward solution.