Overview
The ECR (Elastic Container Registry) Repository resource stores container images with vulnerability scanning and lifecycle management. It integrates with ECS and other AWS services for container deployments.Resource Class
Basic Usage
Default Configuration
All ECR repositories include these defaults:Factory Pattern
Using EcrFactory
With StackBuilder
Image Scanning
Automatic Scanning
Scan Results Integration
Lifecycle Policies
Basic Lifecycle
Advanced Lifecycle Rules
Access Control
Repository Policies
IAM Permissions
Integration with ECS
Basic ECS Integration
With Image Tag Parameter
CI/CD Integration
CodeBuild Integration
GitHub Actions Integration
Encryption
The Fjall
Ecr wrapper accepts only repositoryName. It does not expose
encryption or encryptionKey props. The examples below use the raw CDK
Repository construct directly. For a customer-managed key, instantiate
Repository instead of Ecr.Default Encryption
Customer Managed Key
Outputs
The Ecr construct automatically creates these outputs:Complete Example
Best Practices
- Enable image scanning (default) for security
- Use lifecycle rules to control costs
- Tag images properly for lifecycle management
- Use immutable tags for production
- Implement least privilege access
- Monitor repository size and costs
- Use KMS encryption for sensitive images
Cost Optimisation
Storage Costs
- $0.10 per GB/month for storage
- Use lifecycle rules to remove old images
- Compress images using multi-stage builds
Data Transfer
- Free within same region
- $0.09 per GB for cross-region
- Use VPC endpoints to reduce costs
Example Savings
Monitoring
CloudWatch Metrics
Image Push Events
Troubleshooting
Common Issues
- Push denied: Check IAM permissions and repository policy
- Scan failures: Review scan findings in console
- Storage limits: Implement lifecycle rules
- Pull rate limits: Use VPC endpoints
Debug Commands
Next Steps
ECS Cluster
Run containers from your ECR images on Fargate or EC2.
S3 Bucket
Store objects and static assets alongside your images.
Compute Factory
Compose compute resources with the Fjall pattern factory.
Buildkite Stack
Build and push images through a CI/CD pipeline.