You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example demonstrates how to create an ECR Public repository alongside retrieving authorization tokens for programmatic image pushing.
Overview
The aws_ecrpublic_authorization_token data source provides authentication tokens needed to push images to ECR Public repositories. This example shows how to use this data source with the ECR Public module for complete CI/CD integration.
Key Features
ECR Public repository creation with catalog data
Authorization token retrieval for Docker authentication
ECR Public repositories must be created in us-east-1 region
Authorization tokens must also be retrieved from us-east-1
This is an AWS service limitation for ECR Public Gallery
Token Expiration
Authorization tokens expire after 12 hours
Tokens should be refreshed for long-running CI/CD processes
Use the token_expires_at output to monitor expiration
Usage
Basic Example
module"public-ecr-with-auth" {
source="lgallard/ecrpublic/aws//examples/with_auth_token"repository_name="my-application"catalog_data_description="My public application container"catalog_data_about_text=<<-EOT # My Application Production-ready container for my public application. EOT
}
CI/CD Integration
# Retrieve outputs
REPO_URI=$(terraform output -raw repository_uri)
AUTH_TOKEN=$(terraform output -raw authorization_token)# Docker login using authorization tokenecho"$AUTH_TOKEN"| docker login --username AWS --password-stdin public.ecr.aws
# Or use AWS CLI (recommended)
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
# Tag and push image
docker tag my-app:latest $REPO_URI:latest
docker push $REPO_URI:latest
bash\n# Tag your image\ndocker tag my-app:latest public.ecr.aws/your-registry/my-app:latest\n\n# Push to ECR Public\ndocker push public.ecr.aws/your-registry/my-app:latest\n