ECR for container image registry in AWS - Time & Space Complexity
We want to understand how the time to push or pull container images to AWS ECR changes as the number of images grows.
How does the number of images affect the operations needed?
Analyze the time complexity of the following operation sequence.
aws ecr create-repository --repository-name my-app
aws ecr batch-check-layer-availability --repository-name my-app --layer-digests layer1 layer2
aws ecr put-image --repository-name my-app --image-tag v1 --image-manifest file://manifest.json
aws ecr list-images --repository-name my-app
aws ecr batch-delete-image --repository-name my-app --image-ids imageTag=v1
This sequence creates a repository, checks image layers, uploads an image, lists images, and deletes an image in ECR.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Uploading images with
put-imageand checking layers withbatch-check-layer-availability. - How many times: Once per image or image layer during push operations.
As the number of images increases, the number of API calls to upload and check layers grows roughly in proportion.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | About 10 uploads and layer checks |
| 100 | About 100 uploads and layer checks |
| 1000 | About 1000 uploads and layer checks |
Pattern observation: The operations grow linearly as the number of images increases.
Time Complexity: O(n)
This means the time to push or manage images grows directly with the number of images.
[X] Wrong: "Uploading multiple images happens all at once, so time stays the same no matter how many images."
[OK] Correct: Each image requires separate API calls and data transfer, so time increases as images increase.
Understanding how operations scale with input size helps you design efficient cloud workflows and explain your reasoning clearly in interviews.
"What if we batch multiple image uploads in one API call? How would the time complexity change?"
Practice
Solution
Step 1: Understand ECR's role
AWS ECR is designed to store container images safely and manage them.Step 2: Differentiate from other services
Running containers is done by ECS or EKS, not ECR. Monitoring and VMs are unrelated.Final Answer:
To store and manage container images securely -> Option AQuick Check:
ECR = Container image storage [OK]
- Confusing ECR with ECS or EKS
- Thinking ECR runs containers
- Assuming ECR monitors resources
my-app?Solution
Step 1: Recall AWS CLI syntax for ECR
The correct command to create a repository isaws ecr create-repository --repository-name <name>.Step 2: Check options for correctness
Options B, C, and D use invalid commands or flags not recognized by AWS CLI.Final Answer:
aws ecr create-repository --repository-name my-app -> Option CQuick Check:
Create repo command = aws ecr create-repository --repository-name my-app [OK]
- Using incorrect command verbs like 'new' or 'make'
- Wrong flag names like '--name' or '--repo'
- Assuming 'init-repository' is valid
imageScanStatus value IN_PROGRESS indicate?{
"imageId": {"imageTag": "v1"},
"imageScanStatus": {"status": "IN_PROGRESS"}
}Solution
Step 1: Understand imageScanStatus meaning
The statusIN_PROGRESSmeans the scan is currently running on the image.Step 2: Eliminate other options
Completed scans showCOMPLETE, failures showFAILED, and disabled scanning shows no status.Final Answer:
The image scan for vulnerabilities is currently running -> Option AQuick Check:
IN_PROGRESS = scan running [OK]
- Assuming IN_PROGRESS means scan passed
- Confusing scan failure with in-progress status
- Thinking scanning is disabled
denied: Your authorization token has expired. What is the most likely fix?Solution
Step 1: Identify cause of authorization token error
ECR login tokens expire after 12 hours, so pushing images requires fresh tokens.Step 2: Refresh credentials properly
Runningaws ecr get-login-passwordand logging in again refreshes the token.Final Answer:
Run aws ecr get-login-password again to refresh credentials -> Option DQuick Check:
Expired token fix = refresh login [OK]
- Deleting repository unnecessarily
- Changing image tag won't fix auth
- Restarting CLI doesn't refresh token
Solution
Step 1: Understand tag immutability
Image tag immutability prevents overwriting images with the same tag, protecting specific versions.Step 2: Differentiate from other features
Lifecycle policies manage image cleanup, VPC endpoints control network access, replication copies images across regions.Final Answer:
Image tag immutability -> Option BQuick Check:
Prevent tag overwrite = immutability [OK]
- Confusing lifecycle policies with immutability
- Thinking VPC endpoints control tags
- Assuming replication affects tag overwrite
Ready to prove it?
Pass the test and this pattern moves unknown
