Skip to main content

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:
Tags are immutable. You cannot re-push :latest over an existing image. Push a new, unique tag (for example a build number or content digest) on each deploy.

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

  1. Enable image scanning (default) for security
  2. Use lifecycle rules to control costs
  3. Tag images properly for lifecycle management
  4. Use immutable tags for production
  5. Implement least privilege access
  6. Monitor repository size and costs
  7. 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

  1. Push denied: Check IAM permissions and repository policy
  2. Scan failures: Review scan findings in console
  3. Storage limits: Implement lifecycle rules
  4. 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.