AWS Amazon ECR Repository

This page shows how to write Terraform and CloudFormation for Amazon ECR Repository and write them securely.

aws_ecrpublic_repository (Terraform)

The Repository in Amazon ECR can be configured in Terraform with the resource name aws_ecrpublic_repository. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

containers.tf#L5
resource "aws_ecrpublic_repository" "falcosidekick" {
  provider = aws.us

  repository_name = "falcosidekick"

  catalog_data {
ecr.tf#L1
resource "aws_ecrpublic_repository" "app" {
  repository_name = "somleng-switch"
  provider = aws.us-east-1

  catalog_data {
    about_text        = "Somleng Switch"
main.tf#L7
resource "aws_ecrpublic_repository" "ecr_payment_cash" {
  provider        = aws.us_east_1
  repository_name = "nautible-app-payment-cash"
}

resource "aws_ecrpublic_repository" "ecr_payment_convenience" {
ecr.tf#L1
resource "aws_ecrpublic_repository" "app" {
  repository_name = "scfm"
  provider = aws.us-east-1

  catalog_data {
    about_text        = "Somleng Simple Call Flow Manager (Somleng SCFM)"
ecr.tf#L1
resource "aws_ecrpublic_repository" "app" {
  repository_name = "somleng"
  provider = aws.us-east-1

  catalog_data {
    about_text        = "Somleng"

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides a Public Elastic Container Registry Repository.

NOTE: This resource can only be used with us-east-1 region.

Tips: Best Practices for The Other AWS Amazon ECR Resources

In addition to the aws_ecr_repository, AWS Amazon ECR has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_ecr_repository

Ensure to enable ECR image scan

It is better to enbale ECR image scan. AWS ECR provides a feature to scan container images and discover vulnerable software.

Review your AWS Amazon ECR settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::ECR::PublicRepository (CloudFormation)

The PublicRepository in ECR can be configured in CloudFormation with the resource name AWS::ECR::PublicRepository. The following sections describe 8 examples of how to use the resource and its parameters.

Example Usage from GitHub

JenkinsImagesECR.yml#L9
    Type: AWS::ECR::PublicRepository
    Properties:
      RepositoryName: "ps-build"
      RepositoryCatalogData:
        UsageText: "This image used exclusively for Percona Jenkins pipelines"
        AboutText: "This image contains all build utilities to create proper builds and execute tests"
ecr.yml#L8
    Type: AWS::ECR::PublicRepository
    Properties:
      RepositoryName: mecab
      RepositoryCatalogData:
        OperatingSystems: [ Linux ]
        Architectures: [ x86-64, "ARM 64" ]
public-repos.yml#L5
    Type: AWS::ECR::PublicRepository
    Properties:
      RepositoryName: "cdn-ops"
      RepositoryCatalogData:
        OperatingSystems:
          - "Linux"
cicd.template.yml#L30
    Type: AWS::ECR::PublicRepository
    Properties:
      RepositoryName: brighid/base
      RepositoryPolicyText:
        Version: 2012-10-17
        Statement:
cicd.template.yml#L30
    Type: AWS::ECR::PublicRepository
    Properties:
      RepositoryName: decrs
      RepositoryPolicyText:
        Version: 2012-10-17
        Statement:
template.json#L50
      "Type": "AWS::ECR::PublicRepository",
      "Properties": {},
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "03695c64-0d50-4216-b237-c0f3fd418239"
        }
awsResouceIconMatches.json#L2928
        "resourceType": "AWS::ECR::PublicRepository",
        "filePath": null
      }
    ]
  },
  {
template.json#L1875
    "AWS::ECR::PublicRepository": {
      "Type": "AWS::ECR::PublicRepository",
      "Properties": {}
    },
    "AWS::MediaConvert::Preset": {
      "Type": "AWS::MediaConvert::Preset",

Parameters

RepositoryCatalogData The details about the repository that are publicly visible in the Amazon ECR Public Gallery. For more information, see Amazon ECR Public repository catalog data in the Amazon ECR Public User Guide.
Required: No
Type: Json
Update requires: No interruption

RepositoryName The name to use for the public repository. The repository name may be specified on its own (such as nginx-web-app) or it can be prepended with a namespace to group the repository into a category (such as project-a/nginx-web-app). If you don't specify a name, AWS CloudFormation generates a unique physical ID and uses that ID for the repository name. For more information, see Name Type.
If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name. Required: No
Type: String
Update requires: Replacement

RepositoryPolicyText The JSON repository policy text to apply to the public repository. For more information, see Amazon ECR Public repository policies in the Amazon ECR Public User Guide.
Required: No
Type: Json
Update requires: No interruption

Tags An array of key-value pairs to apply to this resource.
Required: No
Type: List of Tag
Update requires: No interruption

Explanation in CloudFormation Registry

The AWS::ECR::PublicRepository resource specifies an Amazon Elastic Container Registry Public (Amazon ECR Public) repository, where users can push and pull Docker images, Open Container Initiative (OCI) images, and OCI compatible artifacts. For more information, see Amazon ECR public repositories in the Amazon ECR Public User Guide.

Frequently asked questions

What is AWS Amazon ECR Repository?

AWS Amazon ECR Repository is a resource for Amazon ECR of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon ECR Repository?

For Terraform, the falcosecurity/test-infra, somleng/somleng-switch and nautible/nautible-infra source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the Percona-Lab/jenkins-pipelines, shogo82148/mecab-docker and matsoo5g/aws-cloudformation source code examples are useful. See the CloudFormation Example section for further details.