Amazon-Elastic Container Registry
Amazon-Elastic Container Registry
User Guide
API Version 2015-09-21
Amazon ECR User Guide
Amazon's trademarks and trade dress may not be used in connection with any product or service that is not
Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or
discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may
or may not be affiliated with, connected to, or sponsored by Amazon.
Amazon ECR User Guide
Table of Contents
What Is Amazon Elastic Container Registry? .......................................................................................... 1
Components of Amazon ECR ....................................................................................................... 1
How to Get Started with Amazon ECR .......................................................................................... 1
Setting Up ........................................................................................................................................ 2
Sign Up for AWS ........................................................................................................................ 2
Create an IAM User .................................................................................................................... 2
Install the AWS CLI .................................................................................................................... 4
Install Docker ............................................................................................................................ 4
Getting Started using the AWS Management Console ............................................................................. 5
Getting Started using the AWS CLI ....................................................................................................... 6
Install Docker ............................................................................................................................ 6
Step 1: Create a Docker Image .................................................................................................... 7
Step 2: Authenticate to your Default Registry ................................................................................ 8
Step 3: Create a Repository ......................................................................................................... 9
Step 4: Push an Image to Amazon ECR ......................................................................................... 9
Step 5: Pull an Image from Amazon ECR ..................................................................................... 10
Step 6: Delete an Image ........................................................................................................... 11
Step 7: Delete a Repository ....................................................................................................... 11
Registries ......................................................................................................................................... 12
Registry Concepts ..................................................................................................................... 12
Registry Authentication ............................................................................................................. 12
Using the Amazon ECR Credential Helper ............................................................................ 12
Using an Authorization Token ............................................................................................ 12
Using HTTP API Authentication .......................................................................................... 14
Repositories ..................................................................................................................................... 15
Repository Concepts ................................................................................................................. 15
Creating a Repository ............................................................................................................... 15
Viewing Repository Information ................................................................................................. 16
Editing a Repository ................................................................................................................. 17
Deleting a Repository ............................................................................................................... 17
Repository Policies ................................................................................................................... 17
Repository Policies vs IAM Policies ...................................................................................... 18
Setting a Repository Policy Statement ................................................................................ 19
Deleting a Repository Policy Statement .............................................................................. 20
Repository Policy Examples ............................................................................................... 20
Tagging a Repository ................................................................................................................ 23
Tag Basics ....................................................................................................................... 24
Tagging Your Resources .................................................................................................... 24
Tag Restrictions ................................................................................................................ 24
Tagging Your Resources for Billing ...................................................................................... 25
Working with Tags Using the Console ................................................................................. 25
Working with Tags Using the AWS CLI or API ....................................................................... 25
Images ............................................................................................................................................ 27
Pushing an image ..................................................................................................................... 27
Pushing a multi-architecture image ............................................................................................ 28
Pulling an image ...................................................................................................................... 28
Deleting an image .................................................................................................................... 29
Retagging an image ................................................................................................................. 30
Lifecycle Policies ...................................................................................................................... 32
Lifecycle Policy Template .................................................................................................. 32
Lifecycle Policy Parameters ................................................................................................ 32
Lifecycle Policy Evaluation Rules ........................................................................................ 35
Creating a Lifecycle Policy Preview ..................................................................................... 35
Creating a Lifecycle Policy ................................................................................................. 36
Registry
An Amazon ECR registry is provided to each AWS account; you can create image repositories in your
registry and store images in them. For more information, see Amazon ECR Registries (p. 12).
Authorization token
Your Docker client must authenticate to Amazon ECR registries as an AWS user before it can push
and pull images. For more information, see Registry Authentication (p. 12).
Repository
An Amazon ECR image repository contains your Docker or Open Container Initiative (OCI) images.
For more information, see Amazon ECR Repositories (p. 15).
Repository policy
You can control access to your repositories and the images within them with repository policies. For
more information, see Amazon ECR Repository Policies (p. 17).
Image
You can push and pull container images to your repositories. You can use these images locally on
your development system, or you can use them in Amazon ECS task definitions and Amazon EKS pod
specifications. For more information, see Using Amazon ECR Images with Amazon ECS (p. 48) and
Using Amazon ECR Images with Amazon EKS (p. 49).
Complete the following tasks to get set up for Amazon ECR. If you have already completed any of these
steps, you may skip them and move on to installing the custom AWS CLI.
If you have an AWS account already, skip to the next task. If you don't have an AWS account, use the
following procedure to create one.
1. Open https://portal.aws.amazon.com/billing/signup.
2. Follow the online instructions.
Part of the sign-up procedure involves receiving a phone call and entering a verification code on the
phone keypad.
Note your AWS account number, because you'll need it for the next task.
If you signed up for AWS but have not created an IAM user for yourself, you can create one using the IAM
console.
To create an administrator user for yourself and add the user to an administrators group
(console)
1. Use your AWS account email address and password to sign in as the AWS account root user to the
IAM console at https://console.aws.amazon.com/iam/.
Note
We strongly recommend that you adhere to the best practice of using the Administrator
IAM user below and securely lock away the root user credentials. Sign in as the root user
only to perform a few account and service management tasks.
2. In the navigation pane, choose Users and then choose Add user.
3. For User name, enter Administrator.
4. Select the check box next to AWS Management Console access. Then select Custom password, and
then enter your new password in the text box.
5. (Optional) By default, AWS requires the new user to create a new password when first signing in. You
can clear the check box next to User must create a new password at next sign-in to allow the new
user to reset their password after they sign in.
6. Choose Next: Permissions.
7. Under Set permissions, choose Add user to group.
8. Choose Create group.
9. In the Create group dialog box, for Group name enter Administrators.
10. Choose Filter policies, and then select AWS managed -job function to filter the table contents.
11. In the policy list, select the check box for AdministratorAccess. Then choose Create group.
Note
You must activate IAM user and role access to Billing before you can use the
AdministratorAccess permissions to access the AWS Billing and Cost Management
console. To do this, follow the instructions in step 1 of the tutorial about delegating access
to the billing console.
12. Back in the list of groups, select the check box for your new group. Choose Refresh if necessary to
see the group in the list.
13. Choose Next: Tags.
14. (Optional) Add metadata to the user by attaching tags as key-value pairs. For more information
about using tags in IAM, see Tagging IAM Entities in the IAM User Guide.
15. Choose Next: Review to see the list of group memberships to be added to the new user. When you
are ready to proceed, choose Create user.
You can use this same process to create more groups and users and to give your users access to your AWS
account resources. To learn about using policies that restrict user permissions to specific AWS resources,
see Access Management and Example Policies.
To sign in as this new IAM user, sign out of the AWS console, then use the following URL, where
your_aws_account_id is your AWS account number without the hyphens (for example, if your AWS
account number is 1234-5678-9012, your AWS account ID is 123456789012):
https://your_aws_account_id.signin.aws.amazon.com/console/
Enter the IAM user name and password that you just created. When you're signed in, the navigation bar
displays "your_user_name @ your_aws_account_id".
If you don't want the URL for your sign-in page to contain your AWS account ID, you can create an
account alias. From the IAM dashboard, choose Customize and enter an Account Alias, such as your
company name. For more information, see Your AWS Account ID and Its Alias in the IAM User Guide.
To sign in after you create an account alias, use the following URL:
https://your_account_alias.signin.aws.amazon.com/console/
To verify the sign-in link for IAM users for your account, open the IAM console and check under IAM
users sign-in link on the dashboard.
For more information about IAM, see the AWS Identity and Access Management User Guide.
To use the AWS CLI with Amazon ECR, install the latest AWS CLI version (Amazon ECR functionality is
available in the AWS CLI starting with version 1.9.15). You can check your AWS CLI version with the aws
--version command. For information about installing the AWS CLI or upgrading it to the latest version,
see Installing the AWS Command Line Interface in the AWS Command Line Interface User Guide.
Install Docker
To use the Docker CLI with Amazon ECR, you must first install Docker on your system. For information
about installing Docker and getting familiar with the tools, see Getting Started with Amazon ECR using
the AWS CLI (p. 6).
Before you begin, be sure that you've completed the steps in Setting Up with Amazon ECR (p. 2).
A repository is where you store your Docker or Open Container Initiative (OCI) images in Amazon ECR.
Each time you push or pull an image from Amazon ECR, you specify the repository and the registry
location which informs where to push the image to or where to pull it from.
In this section of the wizard, you use the Docker CLI to tag an existing local image (that you have built
from a Dockerfile or pulled from another registry, such as Docker Hub) and then push the tagged image
to your Amazon ECR registry. For more detailed steps on using the Docker CLI, see Getting Started with
Amazon ECR using the AWS CLI (p. 6).
1. Select the repository you created and choose View push commands to view the steps to push an
image to your new repository.
2. Run the login command that authenticates your Docker client to your registry by pasting the
command from the console into a terminal window. This command provides an authorization token
that is valid for 12 hours.
3. (Optional) If you have a Dockerfile for the image to push, build the image and tag it for your new
repository. Pasting the docker build command from the console into a terminal window. Make sure
that you are in the same directory as your Dockerfile.
4. Tag the image with your Amazon ECR registry URI and your new repository by pasting the docker
tag command from the console into a terminal window. The console command assumes that your
image was built from a Dockerfile in the previous step. If you did not build your image from a
Dockerfile, replace the first instance of repository:latest with the image ID or image name of
your local image to push.
5. Push the newly tagged image to your repository by pasting the docker push command into a
terminal window.
6. Choose Close.
The AWS CLI is a unified tool to manage your AWS services. With just one tool to download and
configure, you can control multiple AWS services from the command line and automate them through
scripts. For more information, see AWS Command Line Interface User Guide.
For more information on the other tools available for managing your AWS resources, including the
different AWS SDKs, IDE toolkits, and the Windows PowerShell command line tools, see http://
aws.amazon.com/tools/.
Before you begin, be sure that you've completed the steps in Setting Up with Amazon ECR (p. 2).
Install Docker
Docker is available on many different operating systems, including most modern Linux distributions, like
Ubuntu, and even Mac OSX and Windows. For more information about how to install Docker on your
particular operating system, go to the Docker installation guide.
You don't need a local development system to use Docker. If you are using Amazon EC2 already, you can
launch an Amazon Linux 2 instance and install Docker to get started.
If you already have Docker installed, skip to Step 1: Create a Docker Image (p. 7).
1. Launch an instance with the Amazon Linux 2 AMI. For more information, see Launching an Instance
in the Amazon EC2 User Guide for Linux Instances.
2. Connect to your instance. For more information, see Connect to Your Linux Instance in the Amazon
EC2 User Guide for Linux Instances.
3. Update the installed packages and package cache on your instance.
6. Add the ec2-user to the docker group so you can execute Docker commands without using sudo.
7. Log out and log back in again to pick up the new docker group permissions. You can accomplish
this by closing your current SSH terminal window and reconnecting to your instance in a new one.
Your new SSH session will have the appropriate docker group permissions.
8. Verify that the ec2-user can run Docker commands without sudo.
docker info
Note
In some cases, you may need to reboot your instance to provide permissions for the ec2-
user to access the Docker daemon. Try rebooting your instance if you see the following
error:
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
1. Create a file called Dockerfile. A Dockerfile is a manifest that describes the base image to use
for your Docker image and what you want installed and running on it. For more information about
Dockerfiles, go to the Dockerfile Reference.
touch Dockerfile
2. Edit the Dockerfile you just created and add the following content.
FROM ubuntu:18.04
# Install dependencies
RUN apt-get update && \
apt-get -y install apache2
# Configure apache
RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh && \
echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh && \
echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh && \
echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh && \
chmod 755 /root/run_apache.sh
EXPOSE 80
CMD /root/run_apache.sh
This Dockerfile uses the Ubuntu 18.04 image. The RUN instructions update the package caches,
install some software packages for the web server, and then write the "Hello World!" content to the
web server's document root. The EXPOSE instruction exposes port 80 on the container, and the CMD
instruction starts the web server.
3. Build the Docker image from your Dockerfile.
Note
Some versions of Docker may require the full path to your Dockerfile in the following
command, instead of the relative path shown below.
4. Run docker images to verify that the image was created correctly.
Output:
5. Run the newly built image. The -p 80:80 option maps the exposed port 80 on the container to
port 80 on the host system. For more information about docker run, go to the Docker run reference.
Note
Output from the Apache web server is displayed in the terminal window. You can ignore
the "Could not reliably determine the server's fully qualified domain
name" message.
6. Open a browser and point to the server that is running Docker and hosting your container.
• If you are using an EC2 instance, this is the Public DNS value for the server, which is the same
address you use to connect to the instance with SSH. Make sure that the security group for your
instance allows inbound traffic on port 80.
• If you are running Docker locally, point your browser to http://localhost/.
• If you are using docker-machine on a Windows or Mac computer, find the IP address of the
VirtualBox VM that is hosting Docker with the docker-machine ip command, substituting
machine-name with the name of the docker machine you are using.
docker-machine ip machine-name
You should see a web page with your "Hello World!" statement.
7. Stop the Docker container by typing Ctrl + c.
To authenticate Docker to an Amazon ECR registry with get-login-password, run the aws ecr get-login-
password command. When passing the authentication token to the docker login command, you specify
the AWS username and the Amazon ECR registry URI you want to authenticate to. If authenticating to
multiple registries, you must repeat the command for each registry.
Important
If you receive an error, install or upgrade to the latest version of the AWS CLI. For more
information, see Installing the AWS Command Line Interface in the AWS Command Line
Interface User Guide.
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-
stdin aws_account_id.dkr.ecr.us-east-1.amazonaws.com
Output:
{
"repository": {
"registryId": "123456789012",
"repositoryName": "sample-repo",
"repositoryArn": "arn:aws:ecr:us-east-1:123456789012:repository/sample-repo",
"imageScanningConfiguration": {
"scanOnPush": true
}
}
}
After those prerequisites are met, you can push your image to your newly created repository in the
default registry for your account.
1. List the images you have stored locally to identify the image to tag and push.
docker images
Output:
Output:
After those prerequisites are met, you can pull your image. To pull your example image from Amazon
ECR, run the following command:
Output:
Output:
{
"failures": [],
"imageIds": [
{
"imageTag": "trusty",
"imageDigest":
"sha256:215d7e4121b30157d8839e81c4e0912606fca105775bb0636b95aed25f52c89b"
}
]
}
Output:
{
"repository": {
"registryId": "aws_account_id",
"repositoryName": "ubuntu",
"repositoryArn": "arn:aws:ecr:us-east-1:aws_account_id:repository/ubuntu",
"createdAt": 1457671643.0,
"repositoryUri": "aws_account_id.dkr.ecr.us-east-1.amazonaws.com/ubuntu"
}
}
Registry Concepts
• The URL for your default registry is
https://aws_account_id.dkr.ecr.region.amazonaws.com.
• By default, your account has read and write access to the repositories in your default registry. However,
IAM users require permissions to make calls to the Amazon ECR APIs and to push or pull images
from your repositories. Amazon ECR provides several managed policies to control user access at
varying levels. For more information, see Amazon Elastic Container Registry Identity-Based Policy
Examples (p. 60).
• You must authenticate your Docker client to a registry so that you can use the docker push and
docker pull commands to push and pull images to and from the repositories in that registry. For more
information, see Registry Authentication (p. 12).
• Repositories can be controlled with both IAM user access policies and repository policies. For more
information about repository policies, see Amazon ECR Repository Policies (p. 17).
Registry Authentication
You can use the AWS Management Console, the AWS CLI, or the AWS SDKs to create and manage
repositories. You can also use those methods to perform some actions on images, such as listing or
deleting them. These clients use standard AWS authentication methods. Although technically you can
use the Amazon ECR API to push and pull images, you are much more likely to use the Docker CLI or a
language-specific Docker library.
The Docker CLI does not support native IAM authentication methods. Additional steps must be taken so
that Amazon ECR can authenticate and authorize Docker push and pull requests.
this by retrieving and decoding the authorization token which you can then pipe into a docker login
command to authenticate.
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-
stdin aws_account_id.dkr.ecr.us-east-1.amazonaws.com
1. Run the aws ecr get-login command. The example below is for the default registry associated
with the account making the request. To access other account registries, use the --registry-ids
aws_account_id option. For more information, see get-login in the AWS CLI Command Reference.
The resulting output is a docker login command that you use to authenticate your Docker client to
your Amazon ECR registry.
2. Copy and paste the docker login command into a terminal to authenticate your Docker CLI to the
registry. This command provides an authorization token that is valid for the specified registry for 12
hours.
Note
If you are using Windows PowerShell, copying and pasting long strings like this does not
work. Use the following command instead.
Important
When you execute this docker login command, the command string can be visible to other
users on your system in a process list (ps -e) display. Because the docker login command
contains authentication credentials, there is a risk that other users on your system could
view them this way. They could use the credentials to gain push and pull access to your
repositories. If you are not on a secure system, you should use the ecr get-login-password
command as described above.
1. Retrieve an authorization token with the AWS CLI and set it to an environment variable.
2. To authenticate to the API, pass the $TOKEN variable to the -H option of curl. For example, the
following command lists the image tags in an Amazon ECR repository. For more information, see the
Docker Registry HTTP API reference documentation.
Output:
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Thu, 04 Jan 2018 16:06:59 GMT
Docker-Distribution-Api-Version: registry/2.0
Content-Length: 50
Connection: keep-alive
{"name":"amazonlinux","tags":["2017.09","latest"]}
Topics
• Repository Concepts (p. 15)
• Creating a Repository (p. 15)
• Viewing Repository Information (p. 16)
• Editing a Repository (p. 17)
• Deleting a Repository (p. 17)
• Amazon ECR Repository Policies (p. 17)
• Tagging an Amazon ECR Repository (p. 23)
Repository Concepts
• By default, your account has read and write access to the repositories in your default registry
(aws_account_id.dkr.ecr.region.amazonaws.com). However, IAM users require permissions
to make calls to the Amazon ECR APIs and to push or pull images from your repositories. Amazon ECR
provides several managed policies to control user access at varying levels; for more information, see
Amazon Elastic Container Registry Identity-Based Policy Examples (p. 60).
• Repositories can be controlled with both IAM user access policies and repository policies. For more
information, see Amazon ECR Repository Policies (p. 17).
• Repository names can support namespaces, which you can use to group similar repositories. For
example if there are several teams using the same registry, Team A could use the team-a namespace
while Team B uses the team-b namespace. Each team could have their own image called web-
app, but because they are each prefaced with the team namespace, the two images can be used
simultaneously without interference. Team A's image would be called team-a/web-app, while Team
B's image would be called team-b/web-app.
Creating a Repository
Before you can push your Docker images to Amazon ECR, you must create a repository to store them in.
You can create Amazon ECR repositories with the AWS Management Console, or with the AWS CLI and
AWS SDKs.
To create a repository
a. Run the login command that authenticates your Docker client to your registry by pasting the
command from the console into a terminal window. This command provides an authorization
token that is valid for 12 hours.
b. (Optional) If you have a Dockerfile for the image to push, build the image and tag it for your
new repository. Pasting the docker build command from the console into a terminal window.
Make sure that you are in the same directory as your Dockerfile.
c. Tag the image with your Amazon ECR registry URI and your new repository by pasting the
docker tag command from the console into a terminal window. The console command assumes
that your image was built from a Dockerfile in the previous step. If you did not build your image
from a Dockerfile, replace the first instance of repository:latest with the image ID or
image name of your local image to push.
d. Push the newly tagged image to your repository by pasting the docker push command into a
terminal window.
e. Choose Close.
Note
Beginning with Docker version 1.9, the Docker client compresses image layers before
pushing them to a V2 Docker registry. The output of the docker images command shows the
uncompressed image size, so it may return a larger image size than the image sizes shown in the
AWS Management Console.
• Choose Images to view information about the images in the repository. If there are untagged
images that you would like to delete, you can select the box to the left of the repositories to
delete and choose Delete. For more information, see Deleting an image (p. 29).
• Choose Permissions to view the repository policies that are applied to the repository. For more
information, see Amazon ECR Repository Policies (p. 17).
• Choose Lifecycle Policy to view the lifecycle policy rules that are applied to the repository. The
lifecycle events history is also viewed here. For more information, see Amazon ECR Lifecycle
Policies (p. 32).
• Choose Tags to view the metadata tags that are applied to the repository.
Editing a Repository
Existing repositories can be edited to change its image tag mutability and image scanning settings.
To edit a repository
Deleting a Repository
If you are done using a repository, you can delete it. When you delete a repository in the AWS
Management Console, all of the images contained in the repository are also deleted; this cannot be
undone.
To delete a repository
can perform on it. By default, only the repository owner has access to a repository. You can apply a policy
document that allow additional permissions to your repository.
Both Amazon ECR repository policies and IAM policies are used when determining which actions a
specific IAM user or role may perform on a repository. If a user or role is allowed to perform an action
through a repository policy but is denied permission through an IAM policy (or vice versa) then the
action will be denied. A user or role only needs to be allowed permission for an action through either a
repository policy or an IAM policy but not both for the action to be allowed.
Important
Amazon ECR requires that users have allow permissions to the ecr:GetAuthorizationToken
API through an IAM policy before they can authenticate to a registry and push or pull any
images from any Amazon ECR repository. Amazon ECR provides several managed IAM policies
to control user access at varying levels; for more information, see Amazon Elastic Container
Registry Identity-Based Policy Examples (p. 60).
You can use either of these policy types to control access to your repositories, as shown in the following
examples.
This example shows an Amazon ECR repository policy, which allows for a specific IAM user to describe
the repository and the images within the repository:
{
"Version": "2008-10-17",
"Statement": [{
"Sid": "ECR Repository Policy",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:user/MyUsername"
},
"Action": [
"ecr:DescribeImages",
"ecr:DescribeRepositories"
]
}]
}
This example shows an IAM policy that achieves the same goal as above, by scoping the policy to a
repository (specified by the full ARN of the repository) using the resource parameter:
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "ECR Repository Policy",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:user/MyUsername"
},
"Action": [
"ecr:DescribeImages",
"ecr:DescribeRepositories"
],
"Resource": [
"arn:aws:ecr:region:123456789012:repository/MyRepository"
]
}]
}
Topics
• Setting a Repository Policy Statement (p. 19)
• Deleting a Repository Policy Statement (p. 20)
• Amazon ECR Repository Policy Examples (p. 20)
• You can apply the statement to all authenticated AWS users by selecting the Everyone (*) check
box.
• For Service principal, specify the service principal name (for example, ecs.amazonaws.com) to
apply the statement to a specific service.
• For AWS Account IDs, specify an AWS account number (for example, 111122223333) to apply the
statement to all users under a specific AWS account. Multiple accounts can be specified by using a
comma delimited list.
• For IAM Entities, select the roles or users under your AWS account to apply the statement to.
Note
For more complicated repository policies that are not currently supported in the AWS
Management Console, you can apply the policy with the set-repository-policy AWS CLI
command.
10. For Actions, choose the scope of the Amazon ECR API operations that the policy statement should
apply to from the list of individual API operations.
11. When you are finished, choose Save to set the policy.
12. Repeat the previous step for each repository policy to add.
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPushPull",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::123456789012:user/push-pull-user-1",
"arn:aws:iam::123456789012:user/push-pull-user-2"
]
},
"Action": [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload"
]
}
]
}
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowCrossAccountPush",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:root"
},
"Action": [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchCheckLayerAvailability",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload"
]
}
]
}
The following repository policy allows some IAM users to pull images (pull-user-1 and pull-user-2)
while providing full access to another (admin-user).
Note
For more complicated repository policies that are not currently supported in the AWS
Management Console, you can apply the policy with the set-repository-policy AWS CLI
command.
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPull",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::123456789012:user/pull-user-1",
"arn:aws:iam::123456789012:user/pull-user-2"
]
},
"Action": [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage"
]
},
{
"Sid": "AllowAll",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:user/admin-user"
},
"Action": [
"ecr:*"
]
}
]
}
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPull",
"Effect": "Allow",
"Principal": "*",
"Action": [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage"
]
}
]
}
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "DenyPull",
"Effect": "Deny",
"Principal": "*",
"Action": [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage"
]
}
]
}
The condition in this statement identifies the 54.240.143.* range of allowed Internet Protocol version
4 (IPv4) IP addresses, with one exception: 54.240.143.188.
The Condition block uses the IpAddress and NotIpAddress conditions and the aws:SourceIp
condition key, which is an AWS-wide condition key. For more information about these condition keys, see
AWS Global Condition Context Keys. Theaws:sourceIp IPv4 values use the standard CIDR notation. For
more information, see IP Address Condition Operators in the IAM User Guide.
"Version": "2012-10-17",
"Id": "ECRPolicyId1",
"Statement": [
{
"Sid": "IPAllow",
"Effect": "Allow",
"Principal": "*",
"Action": "ecr:*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": "54.240.143.188/32"
},
"IpAddress": {
"aws:SourceIp": "54.240.143.0/24"
}
}
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CodeBuildAccess",
"Effect": "Allow",
"Principal": {
"Service": "codebuild.amazonaws.com"
},
"Action": [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer"
]
}
]
}
Contents
• Tag Basics (p. 24)
• Tagging Your Resources (p. 24)
• Tag Restrictions (p. 24)
• Tagging Your Resources for Billing (p. 25)
• Working with Tags Using the Console (p. 25)
• Working with Tags Using the AWS CLI or API (p. 25)
Tag Basics
A tag is a label that you assign to an AWS resource. Each tag consists of a key and an optional value, both
of which you define.
Tags enable you to categorize your AWS resources in different ways, for example, by purpose, owner, or
environment. This is useful when you have many resources of the same type—you can quickly identify a
specific resource based on the tags you've assigned to it. For example, you could define a set of tags for
your account's Amazon ECR repositories that helps you track each repo's owner.
We recommend that you devise a set of tag keys that meets your needs. Using a consistent set of tag
keys makes it easier for you to manage your resources. You can search and filter the resources based on
the tags you add.
Tags don't have any semantic meaning to Amazon ECR and are interpreted strictly as a string of
characters. Also, tags are not automatically assigned to your resources. You can edit tag keys and values,
and you can remove tags from a resource at any time. You can set the value of a tag to an empty string,
but you can't set the value of a tag to null. If you add a tag that has the same key as an existing tag on
that resource, the new value overwrites the old value. If you delete a resource, any tags for the resource
are also deleted.
You can work with tags using the AWS Management Console, the AWS CLI, and the Amazon ECR API.
If you're using AWS Identity and Access Management (IAM), you can control which users in your AWS
account have permission to create, edit, or delete tags.
If you're using the Amazon ECR console, you can apply tags to new resources when they are created or
existing resources by using the Tags option on the navigation pane at any time.
If you're using the Amazon ECR API, the AWS CLI, or an AWS SDK, you can apply tags to new repositories
using the tags parameter on the CreateRepository API action or use the TagResource API action to
apply tags to existing resources. For more information, see TagResource.
Additionally, if tags cannot be applied during repository creation, we roll back the repository creation
process. This ensures that repositories are either created with tags or not created at all, and that no
repositories are left untagged at any time. By tagging repositories at the time of creation, you can
eliminate the need to run custom tagging scripts after repository creation.
Tag Restrictions
The following basic restrictions apply to tags:
• Don't use the aws: prefix for either keys or values; it's reserved for AWS use. You can't edit or delete
tag keys or values with this prefix. Tags with this prefix do not count against your tags per resource
limit.
To see the cost of your combined resources, you can organize your billing information based on resources
that have the same tag key values. For example, you can tag several resources with a specific application
name, and then organize your billing information to see the total cost of that application across several
services. For more information about setting up a cost allocation report with tags, see The Monthly Cost
Allocation Report in the AWS Billing and Cost Management User Guide.
Note
If you've just enabled reporting, data for the current month is available for viewing after 24
hours.
When you select a specific repository in the Amazon ECR console, you can view the tags by selecting
Tags in the navigation pane.
The following examples show how to manage tags using the AWS CLI.
The following command lists the tags associated with an existing repository.
The following command creates a repository named test-repo and adds a tag with key team and value
devs.
Images
Amazon Elastic Container Registry (Amazon ECR) stores Docker and Open Container Initiative (OCI)
images in image repositories. You can use the Docker CLI to push and pull images from your repositories.
Important
Amazon ECR requires that users have allow permissions to the ecr:GetAuthorizationToken
API through an IAM policy before they can authenticate to a registry and push or pull any
images from any Amazon ECR repository. Amazon ECR provides several managed IAM policies
to control user access at varying levels; for more information, see Amazon Elastic Container
Registry Identity-Based Policy Examples (p. 60).
Pushing an image
You can push your Docker or Open Container Initiative (OCI) images to an Amazon ECR repository with
the docker push command.
Important
Amazon ECR requires that users have allow permissions to the ecr:GetAuthorizationToken
API through an IAM policy before they can authenticate to a registry and push or pull any
images from any Amazon ECR repository. Amazon ECR provides several managed IAM policies
to control user access at varying levels; for more information, see Amazon Elastic Container
Registry Identity-Based Policy Examples (p. 60).
Amazon ECR also supports creating and pushing Docker manifest lists which are used for multi-
architecture images. Each image referenced in a manifest list much already be pushed to your repository.
For more information, see Pushing a multi-architecture image (p. 28).
To push a Docker or Open Container Initiative (OCI) image to an Amazon ECR repository
1. Authenticate your Docker client to the Amazon ECR registry to which you intend to push your image.
Authentication tokens must be obtained for each registry used, and the tokens are valid for 12
hours. For more information, see Registry Authentication (p. 12).
2. If your image repository does not exist in the registry you intend to push to yet, create it. For more
information, see Creating a Repository (p. 15).
3. Identify the image to push. Run the docker images command to list the images on your system.
docker images
You can identify an image with the repository:tag value or the image ID in the resulting
command output.
4. Tag your image with the Amazon ECR registry, repository, and optional image tag name combination
to use. The registry format is aws_account_id.dkr.ecr.region.amazonaws.com. The
repository name should match the repository that you created for your image. If you omit the image
tag, we assume that the tag is latest.
6. (Optional) Apply any additional tags to your image and push those tags to Amazon ECR by repeating
Step 4 (p. 27) and Step 5 (p. 27). You can apply up to 100 tags per image in Amazon ECR.
A manifest list can be pulled or referenced in an Amazon ECS task definition or Amazon EKS pod spec
like other Amazon ECR images.
The following steps can be used to create and push a Docker manifest list to an Amazon ECR repository.
You must already have the images pushed to your repository to reference in the Docker manifest. For
information on pushing an image, see Pushing an image (p. 27).
1. Authenticate your Docker client to the Amazon ECR registry to which you intend to push your image.
Authentication tokens must be obtained for each registry used, and the tokens are valid for 12
hours. For more information, see Registry Authentication (p. 12).
2. List the images in your repository, confirming the image tags.
3. Create the Docker manifest list. The manifest create command verifies that the referenced
images are already in your repository and creates the manifest locally.
4. (Optional) Inspect the Docker manifest list. This enables you to confirm the size and digest for each
image manifest referenced in the manifest list.
Pulling an image
If you would like to run a Docker image that is available in Amazon ECR, you can pull it to your local
environment with the docker pull command. You can do this from either your default registry or from
a registry associated with another AWS account. To use an Amazon ECR image in an Amazon ECS task
definition, see Using Amazon ECR Images with Amazon ECS (p. 48).
Important
Amazon ECR requires that users have allow permissions to the ecr:GetAuthorizationToken
API through an IAM policy before they can authenticate to a registry and push or pull any
images from any Amazon ECR repository. Amazon ECR provides several managed IAM policies
to control user access at varying levels; for more information, see Amazon Elastic Container
Registry Identity-Based Policy Examples (p. 60).
1. Authenticate your Docker client to the Amazon ECR registry that you intend to pull your image
from. Authentication tokens must be obtained for each registry used, and the tokens are valid for 12
hours. For more information, see Registry Authentication (p. 12).
2. (Optional) Identify the image to pull.
• You can list the repositories in a registry with the aws ecr describe-repositories command:
The example repository above has an image tagged as latest and 2016.09, with the image
digest
sha256:f1d4ae3f7261a72e98c6ebefe9985cf10a0ea5bd762585a43e0700ed99863807.
3. Pull the image using the docker pull command. The image name format should be
registry/repository[:tag] to pull by tag, or registry/repository[@digest] to pull by
digest.
Important
If you receive a repository-url not found: does not exist or no pull
access error, you may need to authenticate your Docker client with Amazon ECR. For more
information, see Registry Authentication (p. 12).
Deleting an image
If you are done using an image, you can delete it from your repository. You can delete an image using the
AWS Management Console, or the AWS CLI.
Note
If you are done with a repository, you can delete the entire repository and all of the images
within it. For more information, see Deleting a Repository (p. 17).
6. In the Delete image(s) dialog box, verify that the selected images should be deleted and choose
Delete.
1. List the images in your repository so that you can identify them by image tag or digest.
2. (Optional) Delete any unwanted tags for the image by specifying the tag of the image you want to
delete.
Note
When you delete the last tag for an image, the image is deleted.
Retagging an image
With Docker Image Manifest V2 Schema 2 images, you can use the --image-tag option of the put-
image command to retag an existing image. You can retag without pulling or pushing the image with
Docker. For larger images, this process saves a considerable amount of network bandwidth and time
required to retag an image.
1. Use the batch-get-image command to get the image manifest for the image to retag and write it
to an environment variable. In this example, the manifest for an image with the tag, latest, in the
repository, amazonlinux, is written to the environment variable, MANIFEST.
2. Use the --image-tag option of the put-image command to put the image manifest to Amazon
ECR with a new tag. In this example, the image is tagged as 2017.03.
Note
If the --image-tag option is not available in your version of the AWS CLI, upgrade to the
latest version. For more information, see Installing the AWS Command Line Interface in the
AWS Command Line Interface User Guide.
3. Verify that your new image tag is attached to your image. In the output below, the image has the
tags latest and 2017.03.
Output:
{
"imageDetails": [
{
"imageSizeInBytes": 98755613,
"imageDigest":
"sha256:8d00af8f076eb15a33019c2a3e7f1f655375681c4e5be157a2685dfe6f247227",
"imageTags": [
"latest",
"2017.03"
],
"registryId": "aws_account_id",
"repositoryName": "amazonlinux",
"imagePushedAt": 1499287667.0
}
]
}
1. Use the Get-ECRImageBatch cmdlet to get the description of the image to retag and write it
to an environment variable. In this example, an image with the tag, latest, in the repository,
amazonlinux, is written to the environment variable, $Image.
Note
If you don't have the Get-ECRImageBatch cmdlet available on your system, see Setting
up the AWS Tools for Windows PowerShell in the AWS Tools for Windows PowerShell User
Guide.
$Manifest = $Image.Images[0].ImageManifest
3. Use the -ImageTag option of the Write-ECRImage cmdlet to put the image manifest to Amazon
ECR with a new tag. In this example, the image is tagged as 2017.09.
4. Verify that your new image tag is attached to your image. In the output below, the image has the
tags latest and 2017.09.
Output:
ImageDigest ImageTag
API Version 2015-09-21
31
Amazon ECR User Guide
Lifecycle Policies
----------- --------
sha256:359b948ea8866817e94765822787cd482279eed0c17bc674a7707f4256d5d497 latest
sha256:359b948ea8866817e94765822787cd482279eed0c17bc674a7707f4256d5d497 2017.09
Topics
• Lifecycle Policy Template (p. 32)
• Lifecycle Policy Parameters (p. 32)
• Lifecycle Policy Evaluation Rules (p. 35)
• Creating a Lifecycle Policy Preview (p. 35)
• Creating a Lifecycle Policy (p. 36)
• Examples of Lifecycle Policies (p. 36)
{
"rules": [
{
"rulePriority": integer,
"description": "string",
"selection": {
"tagStatus": "tagged"|"untagged"|"any",
"tagPrefixList": list<string>,
"countType": "imageCountMoreThan"|"sinceImagePushed",
"countUnit": "string",
"countNumber": integer
},
"action": {
"type": "expire"
}
}
]
}
Note
The tagPrefixList parameter is only used if tagStatus is tagged. The countUnit
parameter is only used if countType is sinceImagePushed. The countNumber parameter is
only used if countType is set to imageCountMoreThan.
Topics
• Rule Priority (p. 33)
• Description (p. 33)
• Tag Status (p. 33)
• Tag Prefix List (p. 33)
• Count Type (p. 34)
• Count Unit (p. 34)
• Count Number (p. 34)
• Action (p. 34)
Rule Priority
rulePriority
Type: integer
Required: yes
Sets the order in which rules are evaluated, lowest to highest. A lifecycle policy rule with a priority
of 1 will be acted upon first, a rule with priority of 2 will be next, and so on. When you add rules to a
lifecycle policy, you must give them each a unique value for rulePriority. Values do not need to
be sequential across rules in a policy. A rule with a tagStatus value of any must have the highest
value for rulePriority and be evaluated last.
Description
description
Type: string
Required: no
Tag Status
tagStatus
Type: string
Required: yes
Determines whether the lifecycle policy rule that you are adding specifies a tag for an image.
Acceptable options are tagged, untagged, or any. If you specify any, then all images have the rule
applied to them. If you specify tagged, then you must also specify a tagPrefixList value. If you
specify untagged, then you must omit tagPrefixList.
Type: list[string]
Only used if you specified "tagStatus": "tagged". You must specify a comma-separated list of
image tag prefixes on which to take action with your lifecycle policy. For example, if your images are
tagged as prod, prod1, prod2, and so on, you would use the tag prefix prod to specify all of them.
If you specify multiple tags, only the images with all specified tags are selected.
Count Type
countType
Type: string
Required: yes
Count Unit
countUnit
Type: string
Specify a count unit of days to indicate that as the unit of time, in addition to countNumber, which
is the number of days.
This should only be specified when countType is sinceImagePushed; an error will occur if you
specify a count unit when countType is any other value.
Count Number
countNumber
Type: integer
Required: yes
Specify a count number. Acceptable values are positive integers (0 is not an accepted value).
If the countType used is imageCountMoreThan, then the value is the maximum number of images
that you want to retain in your repository. If the countType used is sinceImagePushed, then the
value is the maximum age limit for your images.
Action
type
Type: string
Required: yes
9. To run the lifecycle policy preview, choose Save and run test.
10. Under Image matches for test lifecycle rules, review the impact of your lifecycle policy preview.
11. If you are satisfied with the preview results, choose Apply as lifecycle policy to create a lifecycle
policy with the specified rules.
Note
You should expect that after creating a lifecycle policy, the affected images are expired within
24 hours.
1. Obtain the ID of the repository for which to create the lifecycle policy:
Topics
• Filtering on Image Age (p. 37)
• Filtering on Image Count (p. 37)
• Filtering on Multiple Rules (p. 37)
• Filtering on Multiple Tags in a Single Rule (p. 39)
• Filtering on All Images (p. 41)
{
"rules": [
{
"rulePriority": 1,
"description": "Expire images older than 14 days",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": 14
},
"action": {
"type": "expire"
}
}
]
}
{
"rules": [
{
"rulePriority": 1,
"description": "Keep only one untagged image, expire all others",
"selection": {
"tagStatus": "untagged",
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
}
]
}
Example A
Repository contents:
{
"rules": [
{
"rulePriority": 1,
"description": "Rule 1",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["prod"],
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
},
{
"rulePriority": 2,
"description": "Rule 2",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["beta"],
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
}
]
}
• Rule 1 identifies images tagged with prefix prod. It should mark images, starting with the oldest, until
there is one or fewer images remaining that match. It marks Image A for expiration.
• Rule 2 identifies images tagged with prefix beta. It should mark images, starting with the oldest, until
there is one or fewer images remaining that match. It marks both Image A and Image B for expiration.
However, Image A has already been seen by Rule 1 and if Image B were expired it would violate Rule 1
and thus is skipped.
• Result: Image A is expired.
Example B
This is the same repository as the previous example but the rule priority order is changed to illustrate the
outcome.
Repository contents:
{
"rules": [
{
"rulePriority": 1,
"description": "Rule 1",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["beta"],
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
},
{
"rulePriority": 2,
"description": "Rule 2",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["prod"],
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
}
]
}
• Rule 1 identifies images tagged with beta. It should mark images, starting with the oldest, until there
is one or fewer images remaining that match. It sees all three images and would mark Image A and
Image B for expiration.
• Rule 2 identifies images tagged with prod. It should mark images, starting with the oldest, until there
is one or fewer images remaining that match. It would see no images because all available images were
already seen by Rule 1 and thus would mark no additional images.
• Result: Images A and B are expired.
Example A
When multiple tag prefixes are specified on a single rule, images must match all listed tag prefixes.
Repository contents:
{
"rules": [
{
"rulePriority": 1,
"description": "Rule 1",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["alpha", "beta"],
"countType": "sinceImagePushed",
"countNumber": 5,
"countUnit": "days"
},
"action": {
"type": "expire"
}
}
]
}
• Rule 1 identifies images tagged with alpha and beta. It sees images C and F. It should mark images
that are older than five days, which would be Image C.
• Result: Image C is expired.
Example B
The following example illustrates that tags are not exclusive.
Repository contents:
{
"rules": [
{
"rulePriority": 1,
"description": "Rule 1",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["alpha", "beta"],
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
}
]
}
• Rule 1 identifies images tagged with alpha and beta. It sees all images. It should mark images,
starting with the oldest, until there is one or fewer images remaining that match. It marks image A and
B for expiration.
• Result: Images A and B are expired.
Example A
The following shows the lifecycle policy syntax for a policy that applies to all rules but keeps only one
image and expires all others.
Repository contents:
{
"rules": [
{
"rulePriority": 1,
"description": "Rule 1",
"selection": {
"tagStatus": "any",
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
}
]
}
• Rule 1 identifies all images. It sees images A, B, C, and D. It should expire all images other than the
newest one. It marks images A, B, and C for expiration.
• Result: Images A, B, and C are expired.
Example B
The following example illustrates a lifecycle policy that combines all the rule types in a single policy.
Repository contents:
{
"rules": [
{
"rulePriority": 1,
"description": "Rule 1",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["alpha"],
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
},
{
"rulePriority": 2,
"description": "Rule 2",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "day",
"countNumber": 1
},
"action": {
"type": "expire"
}
},
{
"rulePriority": 3,
"description": "Rule 3",
"selection": {
"tagStatus": "any",
"countType": "imageCountMoreThan",
"countNumber": 1
},
"action": {
"type": "expire"
}
}
]
}
• Rule 1 identifies images tagged with alpha. It identifies images A and C. It should keep the newest
image and mark the rest for expiration. It marks image A for expiration.
• Rule 2 identifies untagged images. It identifies images B and E. It should mark all images older than
one day for expiration. It marks image B for expiration.
• Rule 3 identifies all images. It identifies images A, B, C, D, and E. It should keep the newest image and
mark the rest for expiration. However, it can't mark images A, B, C, or E because they were identified by
higher priority rules. It marks image D for expiration.
• Result: Images A, B, and D are expired.
You can use the AWS Management Console and AWS CLI tools to set image tag mutability for either a
new repository during creation or for an existing repository at any time. For console steps, see Creating a
Repository (p. 15) and Editing a Repository (p. 17).
Use one of the following commands to create a new image repository with immutable tags configured.
Use one of the following commands to update the image tag mutability settings for an existing
repository.
Image scanning
Amazon ECR image scanning helps in identifying software vulnerabilities in your container images.
Amazon ECR uses the Common Vulnerabilities and Exposures (CVEs) database from the open source
CoreOS Clair project and provides you with a list of scan findings. You can review the scan findings for
information about the security of the container images that are being deployed. For more information
about CoreOS Clair, see CoreOS Clair.
Amazon ECR uses the severity for a CVE from the upstream distribution source if available, otherwise we
use the Common Vulnerability Scoring System (CVSS) score. The CVSS score can be used to obtain the
NVD vulnerability severity rating. For more information, see NVD Vulnerability Severity Ratings.
You can manually scan container images stored in Amazon ECR, or you can configure your repositories
to scan images when you push them to a repository. The last completed image scan findings can
be retrieved for each image. Amazon ECR sends an event to Amazon EventBridge (formerly called
CloudWatch Events) when an image scan is completed. For more information, see Amazon ECR Events
and EventBridge (p. 74).
For troubleshooting details for some common issues when scanning images, see Troubleshooting Image
Scanning Issues (p. 94).
Topics
• Configuring a Repository to Scan on Push (p. 44)
• Manually Scanning an Image (p. 45)
• Retrieving Scan Findings (p. 46)
Topics
• Creating a New Repository to Scan on Push (p. 44)
• Configure an Existing Repository to Scan on Push (p. 44)
For AWS Management Console steps, see Creating a Repository (p. 15).
To create a repository configured for scan on push (AWS Tools for Windows PowerShell)
Use the following command to create a new repository with image scan on push configured.
For AWS Management Console steps, see Editing a Repository (p. 17).
Use the following command to edit the image scanning settings of an existing repository.
Note
To disable image scan on push for a repository, specify scanOnPush=false.
To edit the settings of an existing repository (AWS Tools for Windows PowerShell)
Use the following command to edit the image scanning settings of an existing repository.
For troubleshooting details for some common issues when scanning images, see Troubleshooting Image
Scanning Issues (p. 94).
For troubleshooting details for some common issues when scanning images, see Troubleshooting Image
Scanning Issues (p. 94).
• Docker Image Manifest V2 Schema 1 (used with Docker version 1.9 and older)
• Docker Image Manifest V2 Schema 2 (used with Docker version 1.10 and newer)
• Open Container Initiative (OCI) Specifications (v1.0 and up)
Support for Docker Image Manifest V2 Schema 2 provides the following functionality:
When you push an image to Amazon ECR with Docker version 1.9 or older, the image manifest format
is stored as Docker Image Manifest V2 Schema 1. When you push an image to Amazon ECR with Docker
version 1.10 or newer, the image manifest format is stored as Docker Image Manifest V2 Schema 2.
When you pull an image from Amazon ECR by tag, Amazon ECR returns the image manifest format that
is stored in the repository. The format is returned only if that format is understood by the client. If the
stored image manifest format is not understood by the client, Amazon ECR converts the image manifest
into a format that is understood by the client. For example, if a Docker 1.9 client requests an image
manifest that is stored as Docker Image Manifest V2 Schema 2, Amazon ECR returns the manifest in
the Docker Image Manifest V2 Schema 1 format. The table below describes the available conversions
supported by Amazon ECR when an image is pulled by tag:
Schema requested by Pushed to ECR as V2, Pushed to ECR as V2, Pushed to ECR as OCI
client schema 1 schema 2
Important
If you pull an image by digest, there is no translation available; your client must understand the
image manifest format that is stored in Amazon ECR. If you request a Docker Image Manifest
V2 Schema 2 image by digest on a Docker 1.9 or older client, the image pull fails. For more
information, see Registry compatibility in the Docker documentation.
In this example, if you request the same image by tag, Amazon ECR translates the image
manifest into a format that the client can understand. The image pull succeeds.
• Your container instances must be using at least version 1.7.0 of the Amazon ECS container agent. The
latest version of the Amazon ECS–optimized AMI supports ECR images in task definitions. For more
information, including the latest Amazon ECS–optimized AMI IDs, see Amazon ECS Container Agent
Versions in the Amazon Elastic Container Service Developer Guide.
• The Amazon ECS container instance role (ecsInstanceRole) that you use with your container
instances must possess the following IAM policy permissions for Amazon ECR.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:GetAuthorizationToken"
],
"Resource": "*"
}
]
}
• The Amazon EKS worker node IAM role (NodeInstanceRole) that you use with your worker nodes
must possess the following IAM policy permissions for Amazon ECR.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:GetAuthorizationToken"
],
"Resource": "*"
}
]
}
Note
If you used eksctl or the AWS CloudFormation templates in Getting Started with Amazon
EKS to create your cluster and worker node groups, these IAM permissions are applied to your
worker node IAM role by default.
• When referencing an image from Amazon ECR, you must use the full registry/repository:tag
naming for the image. For example, aws_account_id.dkr.ecr.region.amazonaws.com/my-
web-app:latest.
You can use the Amazon Linux container image in your local development environment and then push
your application to the AWS Cloud using Amazon ECS. For more information, see Using Amazon ECR
Images with Amazon ECS (p. 48).
The Amazon Linux container image is available in Amazon ECR and on Docker Hub. Support for the
Amazon Linux container image can be found by visiting the AWS developer forums.
1. Authenticate your Docker client to the Amazon Linux container image Amazon ECR
registry. Authentication tokens are valid for 12 hours. For more information, see Registry
Authentication (p. 12).
Note
The get-login-password command is available in the AWS CLI starting with version
1.17.10. For more information, see Installing the AWS Command Line Interface in the AWS
Command Line Interface User Guide.
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-
stdin 137112412989.dkr.ecr.us-east-1.amazonaws.com
Output:
Login succeeded
Important
If you receive an error, install or upgrade to the latest version of the AWS CLI. For more
information, see Installing the AWS Command Line Interface in the AWS Command Line
Interface User Guide.
2. (Optional) You can list the images within the Amazon Linux repository with the aws ecr list-images
command. The latest tag always corresponds with the latest Amazon Linux container image that is
available.
3. Pull the Amazon Linux container image using the docker pull command.
1. Pull the Amazon Linux container image using the docker pull command.
Security is a shared responsibility between AWS and you. The shared responsibility model describes this
as security of the cloud and security in the cloud:
• Security of the cloud – AWS is responsible for protecting the infrastructure that runs AWS services in
the AWS Cloud. AWS also provides you with services that you can use securely. Third-party auditors
regularly test and verify the effectiveness of our security as part of the AWS compliance programs.
To learn about the compliance programs that apply to Amazon ECR, see AWS Services in Scope by
Compliance Program.
• Security in the cloud – Your responsibility is determined by the AWS service that you use. You are also
responsible for other factors including the sensitivity of your data, your company’s requirements, and
applicable laws and regulations.
This documentation helps you understand how to apply the shared responsibility model when using
Amazon ECR. The following topics show you how to configure Amazon ECR to meet your security and
compliance objectives. You also learn how to use other AWS services that help you to monitor and secure
your Amazon ECR resources.
Topics
• Identity and Access Management for Amazon Elastic Container Registry (p. 51)
• Compliance Validation for Amazon Elastic Container Registry (p. 65)
• Infrastructure Security in Amazon Elastic Container Registry (p. 66)
Topics
• Audience (p. 52)
• Authenticating With Identities (p. 52)
• Managing Access Using Policies (p. 54)
• How Amazon Elastic Container Registry Works with IAM (p. 55)
• Amazon ECR Managed Policies (p. 58)
• Amazon Elastic Container Registry Identity-Based Policy Examples (p. 60)
• Using Tag-Based Access Control (p. 62)
• Troubleshooting Amazon Elastic Container Registry Identity and Access (p. 64)
Audience
How you use AWS Identity and Access Management (IAM) differs, depending on the work you do in
Amazon ECR.
Service user – If you use the Amazon ECR service to do your job, then your administrator provides you
with the credentials and permissions that you need. As you use more Amazon ECR features to do your
work, you might need additional permissions. Understanding how access is managed can help you
request the right permissions from your administrator. If you cannot access a feature in Amazon ECR, see
Troubleshooting Amazon Elastic Container Registry Identity and Access (p. 64).
Service administrator – If you're in charge of Amazon ECR resources at your company, you probably
have full access to Amazon ECR. It's your job to determine which Amazon ECR features and resources
your employees should access. You must then submit requests to your IAM administrator to change the
permissions of your service users. Review the information on this page to understand the basic concepts
of IAM. To learn more about how your company can use IAM with Amazon ECR, see How Amazon Elastic
Container Registry Works with IAM (p. 55).
IAM administrator – If you're an IAM administrator, you might want to learn details about how you can
write policies to manage access to Amazon ECR. To view example Amazon ECR identity-based policies
that you can use in IAM, see Amazon Elastic Container Registry Identity-Based Policy Examples (p. 60).
You must be authenticated (signed in to AWS) as the AWS account root user, an IAM user, or by assuming
an IAM role. You can also use your company's single sign-on authentication, or even sign in using Google
or Facebook. In these cases, your administrator previously set up identity federation using IAM roles.
When you access AWS using credentials from another company, you are assuming a role indirectly.
To sign in directly to the AWS Management Console, use your password with your root user email or your
IAM user name. You can access AWS programmatically using your root user or IAM user access keys. AWS
provides SDK and command line tools to cryptographically sign your request using your credentials. If
you don’t use AWS tools, you must sign the request yourself. Do this using Signature Version 4, a protocol
for authenticating inbound API requests. For more information about authenticating requests, see
Signature Version 4 Signing Process in the AWS General Reference.
Regardless of the authentication method that you use, you might also be required to provide additional
security information. For example, AWS recommends that you use multi-factor authentication (MFA) to
increase the security of your account. To learn more, see Using Multi-Factor Authentication (MFA) in AWS
in the IAM User Guide.
An IAM group is an identity that specifies a collection of IAM users. You can't sign in as a group. You
can use groups to specify permissions for multiple users at a time. Groups make permissions easier to
manage for large sets of users. For example, you could have a group named IAMAdmins and give that
group permissions to administer IAM resources.
Users are different from roles. A user is uniquely associated with one person or application, but a role
is intended to be assumable by anyone who needs it. Users have permanent long-term credentials, but
roles provide temporary credentials. To learn more, see When to Create an IAM User (Instead of a Role) in
the IAM User Guide.
IAM Roles
An IAM role is an identity within your AWS account that has specific permissions. It is similar to an IAM
user, but is not associated with a specific person. You can temporarily assume an IAM role in the AWS
Management Console by switching roles. You can assume a role by calling an AWS CLI or AWS API
operation or by using a custom URL. For more information about methods for using roles, see Using IAM
Roles in the IAM User Guide.
IAM roles with temporary credentials are useful in the following situations:
• Temporary IAM user permissions – An IAM user can assume an IAM role to temporarily take on
different permissions for a specific task.
• Federated user access – Instead of creating an IAM user, you can use existing identities from AWS
Directory Service, your enterprise user directory, or a web identity provider. These are known as
federated users. AWS assigns a role to a federated user when access is requested through an identity
provider. For more information about federated users, see Federated Users and Roles in the IAM User
Guide.
• Cross-account access – You can use an IAM role to allow someone (a trusted principal) in a different
account to access resources in your account. Roles are the primary way to grant cross-account access.
However, with some AWS services, you can attach a policy directly to a resource (instead of using a role
as a proxy). To learn the difference between roles and resource-based policies for cross-account access,
see How IAM Roles Differ from Resource-based Policies in the IAM User Guide.
• AWS service access – A service role is an IAM role that a service assumes to perform actions in your
account on your behalf. When you set up some AWS service environments, you must define a role
for the service to assume. This service role must include all the permissions that are required for the
service to access the AWS resources that it needs. Service roles vary from service to service, but many
allow you to choose your permissions as long as you meet the documented requirements for that
service. Service roles provide access only within your account and cannot be used to grant access
to services in other accounts. You can create, modify, and delete a service role from within IAM. For
example, you can create a role that allows Amazon Redshift to access an Amazon S3 bucket on your
behalf and then load data from that bucket into an Amazon Redshift cluster. For more information, see
Creating a Role to Delegate Permissions to an AWS Service in the IAM User Guide.
• Applications running on Amazon EC2 – You can use an IAM role to manage temporary credentials
for applications that are running on an EC2 instance and making AWS CLI or AWS API requests.
This is preferable to storing access keys within the EC2 instance. To assign an AWS role to an EC2
instance and make it available to all of its applications, you create an instance profile that is attached
to the instance. An instance profile contains the role and enables programs that are running on the
EC2 instance to get temporary credentials. For more information, see Using an IAM Role to Grant
Permissions to Applications Running on Amazon EC2 Instances in the IAM User Guide.
To learn whether to use IAM roles, see When to Create an IAM Role (Instead of a User) in the IAM User
Guide.
An IAM administrator can use policies to specify who has access to AWS resources, and what actions
they can perform on those resources. Every IAM entity (user or role) starts with no permissions. In other
words, by default, users can do nothing, not even change their own password. To give a user permission
to do something, an administrator must attach a permissions policy to a user. Or the administrator can
add the user to a group that has the intended permissions. When an administrator gives permissions to a
group, all users in that group are granted those permissions.
IAM policies define permissions for an action regardless of the method that you use to perform the
operation. For example, suppose that you have a policy that allows the iam:GetRole action. A user with
that policy can get role information from the AWS Management Console, the AWS CLI, or the AWS API.
Identity-Based Policies
Identity-based policies are JSON permissions policy documents that you can attach to an identity, such
as an IAM user, role, or group. These policies control what actions that identity can perform, on which
resources, and under what conditions. To learn how to create an identity-based policy, see Creating IAM
Policies in the IAM User Guide.
Identity-based policies can be further categorized as inline policies or managed policies. Inline policies
are embedded directly into a single user, group, or role. Managed policies are standalone policies that
you can attach to multiple users, groups, and roles in your AWS account. Managed policies include AWS
managed policies and customer managed policies. To learn how to choose between a managed policy or
an inline policy, see Choosing Between Managed Policies and Inline Policies in the IAM User Guide.
Resource-Based Policies
Resource-based policies are JSON policy documents that you attach to a resource such as an Amazon S3
bucket. Service administrators can use these policies to define what actions a specified principal (account
member, user, or role) can perform on that resource and under what conditions. Resource-based policies
are inline policies. There are no managed resource-based policies.
• Permissions boundaries – A permissions boundary is an advanced feature in which you set the
maximum permissions that an identity-based policy can grant to an IAM entity (IAM user or role).
You can set a permissions boundary for an entity. The resulting permissions are the intersection of
entity's identity-based policies and its permissions boundaries. Resource-based policies that specify
the user or role in the Principal field are not limited by the permissions boundary. An explicit deny
in any of these policies overrides the allow. For more information about permissions boundaries, see
Permissions Boundaries for IAM Entities in the IAM User Guide.
• Service control policies (SCPs) – SCPs are JSON policies that specify the maximum permissions for
an organization or organizational unit (OU) in AWS Organizations. AWS Organizations is a service for
grouping and centrally managing multiple AWS accounts that your business owns. If you enable all
features in an organization, then you can apply service control policies (SCPs) to any or all of your
accounts. The SCP limits permissions for entities in member accounts, including each AWS account
root user. For more information about Organizations and SCPs, see How SCPs Work in the AWS
Organizations User Guide.
• Session policies – Session policies are advanced policies that you pass as a parameter when you
programmatically create a temporary session for a role or federated user. The resulting session's
permissions are the intersection of the user or role's identity-based policies and the session policies.
Permissions can also come from a resource-based policy. An explicit deny in any of these policies
overrides the allow. For more information, see Session Policies in the IAM User Guide.
Topics
• Amazon ECR Identity-Based Policies (p. 55)
• Amazon ECR Resource-Based Policies (p. 57)
• Authorization Based on Amazon ECR Tags (p. 57)
• Amazon ECR IAM Roles (p. 58)
Actions
The Action element of an IAM identity-based policy describes the specific action or actions that will be
allowed or denied by the policy. Policy actions usually have the same name as the associated AWS API
operation. The action is used in a policy to grant permissions to perform the associated operation.
Policy actions in Amazon ECR use the following prefix before the action: ecr:. For example, to grant
someone permission to create an Amazon ECR repository with the Amazon ECR CreateRepository
API operation, you include the ecr:CreateRepository action in their policy. Policy statements must
include either an Action or NotAction element. Amazon ECR defines its own set of actions that
describe tasks that you can perform with this service.
To specify multiple actions in a single statement, separate them with commas as follows:
"Action": [
"ecr:action1",
"ecr:action2"
You can specify multiple actions using wildcards (*). For example, to specify all actions that begin with
the word Describe, include the following action:
"Action": "ecr:Describe*"
To see a list of Amazon ECR actions, see Actions, Resources, and Condition Keys for Amazon Elastic
Container Registry in the IAM User Guide.
Resources
The Resource element specifies the object or objects to which the action applies. Statements must
include either a Resource or a NotResource element. You specify a resource using an ARN or using the
wildcard (*) to indicate that the statement applies to all resources.
arn:${Partition}:ecr:${Region}:${Account}:repository/${Repository-name}
For more information about the format of ARNs, see Amazon Resource Names (ARNs) and AWS Service
Namespaces.
For example, to specify the my-repo repository in the us-east-1 Region in your statement, use the
following ARN:
"Resource": "arn:aws:ecr:us-east-1:123456789012:repository/my-repo"
To specify all repositories that belong to a specific account, use the wildcard (*):
"Resource": "arn:aws:ecr:us-east-1:123456789012:repository/*"
To specify multiple resources in a single statement, separate the ARNs with commas.
"Resource": [
"resource1",
"resource2"
To see a list of Amazon ECR resource types and their ARNs, see Resources Defined by Amazon Elastic
Container Registry in the IAM User Guide. To learn with which actions you can specify the ARN of each
resource, see Actions Defined by Amazon Elastic Container Registry.
Condition Keys
The Condition element (or Condition block) lets you specify conditions in which a statement is in
effect. The Condition element is optional. You can build conditional expressions that use condition
operators, such as equals or less than, to match the condition in the policy with values in the request.
If you specify multiple Condition elements in a statement, or multiple keys in a single Condition
element, AWS evaluates them using a logical AND operation. If you specify multiple values for a single
condition key, AWS evaluates the condition using a logical OR operation. All of the conditions must be
met before the statement's permissions are granted.
You can also use placeholder variables when you specify conditions. For example, you can grant an IAM
user permission to access a resource only if it is tagged with their IAM user name. For more information,
see IAM Policy Elements: Variables and Tags in the IAM User Guide.
Amazon ECR defines its own set of condition keys and also supports using some global condition keys. To
see all AWS global condition keys, see AWS Global Condition Context Keys in the IAM User Guide.
Most Amazon ECR actions support the aws:ResourceTag and ecr:ResourceTag condition keys. For
more information, see Using Tag-Based Access Control (p. 62).
To see a list of Amazon ECR condition keys, see Condition Keys Defined by Amazon Elastic Container
Registry in the IAM User Guide. To learn with which actions and resources you can use a condition key, see
Actions Defined by Amazon Elastic Container Registry.
Examples
To view examples of Amazon ECR identity-based policies, see Amazon Elastic Container Registry Identity-
Based Policy Examples (p. 60).
To enable cross-account access, you can specify an entire account or IAM entities in another account as
the principal in a resource-based policy. Adding a cross-account principal to a resource-based policy is
only half of establishing the trust relationship. When the principal and the resource are in different AWS
accounts, you must also grant the principal entity permission to access the resource. Grant permission by
attaching an identity-based policy to the entity. However, if a resource-based policy grants access to a
principal in the same account, no additional identity-based policy is required. For more information, see
How IAM Roles Differ from Resource-based Policies in the IAM User Guide.
The Amazon ECR service supports only one type of resource-based policy called a repository policy,
which is attached to a repository. This policy defines which principal entities (accounts, users, roles, and
federated users) can perform actions on the repository.
To learn how to attach a resource-based policy to a repository, see Amazon ECR Repository
Policies (p. 17).
Examples
To view examples of Amazon ECR resource-based policies, see Amazon ECR Repository Policy
Examples (p. 20),
To view an example identity-based policy for limiting access to a resource based on the tags on that
resource, see Using Tag-Based Access Control (p. 62).
Service-Linked Roles
Service-linked roles allow AWS services to access resources in other services to complete an action on
your behalf. Service-linked roles appear in your IAM account and are owned by the service. An IAM
administrator can view but not edit the permissions for service-linked roles.
Topics
• AmazonEC2ContainerRegistryFullAccess (p. 58)
• AmazonEC2ContainerRegistryPowerUser (p. 59)
• AmazonEC2ContainerRegistryReadOnly (p. 59)
AmazonEC2ContainerRegistryFullAccess
This managed policy is a starting point for customers who are looking to provide an IAM user
or role with full administrator access to manage their use of Amazon ECR. The Amazon ECR
Lifecycle Policies feature enables customers to specify the lifecycle management of images in a
repository. Lifecycle policy events are reported as CloudTrail events, and Amazon ECR is integrated
with AWS CloudTrail to display a customer's lifecycle policy events directly in the Amazon ECR
console. The AmazonEC2ContainerRegistryFullAccess managed IAM policy includes the
cloudtrail:LookupEvents permission to facilitate this behavior.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:*",
"cloudtrail:LookupEvents"
],
"Resource": "*"
}
]
}
AmazonEC2ContainerRegistryPowerUser
This managed policy allows power user access to Amazon ECR, which allows read and write access to
repositories, but does not allow users to delete repositories or change the policy documents applied to
them.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:GetLifecyclePolicy",
"ecr:GetLifecyclePolicyPreview",
"ecr:ListTagsForResource",
"ecr:DescribeImageScanFindings",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:PutImage"
],
"Resource": "*"
}
]
}
AmazonEC2ContainerRegistryReadOnly
This managed policy allows read-only access to Amazon ECR, such as the ability to list repositories and
the images within the repositories, and also to pull images from Amazon ECR with the Docker CLI.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:GetLifecyclePolicy",
"ecr:GetLifecyclePolicyPreview",
"ecr:ListTagsForResource",
"ecr:DescribeImageScanFindings"
],
"Resource": "*"
}
]
}
To learn how to create an IAM identity-based policy using these example JSON policy documents, see
Creating Policies on the JSON Tab in the IAM User Guide.
Topics
• Policy Best Practices (p. 60)
• Using the Amazon ECR Console (p. 60)
• Allow Users to View Their Own Permissions (p. 61)
• Accessing One Amazon ECR Repository (p. 62)
• Get Started Using AWS Managed Policies – To start using Amazon ECR quickly, use AWS managed
policies to give your employees the permissions they need. These policies are already available in
your account and are maintained and updated by AWS. For more information, see Get Started Using
Permissions With AWS Managed Policies in the IAM User Guide.
• Grant Least Privilege – When you create custom policies, grant only the permissions required
to perform a task. Start with a minimum set of permissions and grant additional permissions as
necessary. Doing so is more secure than starting with permissions that are too lenient and then trying
to tighten them later. For more information, see Grant Least Privilege in the IAM User Guide.
• Enable MFA for Sensitive Operations – For extra security, require IAM users to use multi-factor
authentication (MFA) to access sensitive resources or API operations. For more information, see Using
Multi-Factor Authentication (MFA) in AWS in the IAM User Guide.
• Use Policy Conditions for Extra Security – To the extent that it's practical, define the conditions under
which your identity-based policies allow access to a resource. For example, you can write conditions to
specify a range of allowable IP addresses that a request must come from. You can also write conditions
to allow requests only within a specified date or time range, or to require the use of SSL or MFA. For
more information, see IAM JSON Policy Elements: Condition in the IAM User Guide.
To ensure that those entities can still use the Amazon ECR console, add the
AmazonEC2ContainerRegistryReadOnly AWS managed policy to the entities. For more information,
see Adding Permissions to a User in the IAM User Guide:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:GetLifecyclePolicy",
"ecr:GetLifecyclePolicyPreview",
"ecr:ListTagsForResource",
"ecr:DescribeImageScanFindings"
],
"Resource": "*"
}
]
}
You don't need to allow minimum console permissions for users that are making calls only to the AWS
CLI or the AWS API. Instead, allow access to only the actions that match the API operation that you're
trying to perform.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ViewOwnUserInfo",
"Effect": "Allow",
"Action": [
"iam:GetUserPolicy",
"iam:ListGroupsForUser",
"iam:ListAttachedUserPolicies",
"iam:ListUserPolicies",
"iam:GetUser"
],
"Resource": ["arn:aws:iam::*:user/${aws:username}"]
},
{
"Sid": "NavigateInConsole",
"Effect": "Allow",
"Action": [
"iam:GetGroupPolicy",
"iam:GetPolicyVersion",
"iam:GetPolicy",
"iam:ListAttachedGroupPolicies",
"iam:ListGroupPolicies",
"iam:ListPolicyVersions",
"iam:ListPolicies",
"iam:ListUsers"
],
"Resource": "*"
}
]
}
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"ListImagesInRepository",
"Effect":"Allow",
"Action":[
"ecr:ListImages"
],
"Resource":"arn:aws:ecr:us-east-1:123456789012:repository/my-repo"
},
{
"Sid":"GetAuthorizationToken",
"Effect":"Allow",
"Action":[
"ecr:GetAuthorizationToken"
],
"Resource":"*"
},
{
"Sid":"ManageRepositoryContents",
"Effect":"Allow",
"Action":[
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:PutImage"
],
"Resource":"arn:aws:ecr:us-east-1:123456789012:repository/my-repo"
}
]
}
To enable users to tag repositories on creation, they must have permissions to use the action that creates
the resource (for example, ecr:CreateRepository). If tags are specified in the resource-creating
You can used tag-based access control through IAM policies. The following are examples.
The following policy would only allow an IAM user to create or tag a repository as
key=environment,value=dev.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCreateTaggedRepository",
"Effect": "Allow",
"Action": [
"ecr:CreateRepository"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:RequestTag/environment": "dev"
}
}
},
{
"Sid": "AllowTagRepository",
"Effect": "Allow",
"Action": [
"ecr:TagResource"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:RequestTag/environment": "dev"
}
}
}
]
}
The following policy would allow an IAM user access to all repositories unless they were tagged as
key=environment,value=prod.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ecr:*",
"Resource": "*"
},
{
"Effect": "Deny",
"Action": "ecr:*",
"Resource": "*",
"Condition": {
"StringEquals": {
"ecr:ResourceTag/environment": "prod"
}
}
}
]
}
Topics
• I Am Not Authorized to Perform an Action in Amazon ECR (p. 64)
• I Am Not Authorized to Perform iam:PassRole (p. 64)
• I Want to View My Access Keys (p. 64)
• I'm an Administrator and Want to Allow Others to Access Amazon ECR (p. 65)
• I Want to Allow People Outside of My AWS Account to Access My Amazon ECR Resources (p. 65)
The following example error occurs when the mateojackson IAM user tries to use the console to view
details about a repository but does not have ecr:DescribeRepositories permissions.
In this case, Mateo asks his administrator to update his policies to allow him to access the my-repo
resource using the ecr:DescribeRepositories action.
Some AWS services allow you to pass an existing role to that service, instead of creating a new service
role or service-linked role. To do this, you must have permissions to pass the role to the service.
The following example error occurs when an IAM user named marymajor tries to use the console to
perform an action in Amazon ECR. However, the action requires the service to have permissions granted
by a service role. Mary does not have permissions to pass the role to the service.
In this case, Mary asks her administrator to update her policies to allow her to perform the
iam:PassRole action.
Access keys consist of two parts: an access key ID (for example, AKIAIOSFODNN7EXAMPLE) and a secret
access key (for example, wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY). Like a user name and
password, you must use both the access key ID and secret access key together to authenticate your
requests. Manage your access keys as securely as you do your user name and password.
Important
Do not provide your access keys to a third party, even to help find your canonical user ID. By
doing this, you might give someone permanent access to your account.
When you create an access key pair, you are prompted to save the access key ID and secret access key in
a secure location. The secret access key is available only at the time you create it. If you lose your secret
access key, you must add new access keys to your IAM user. You can have a maximum of two access keys.
If you already have two, you must delete one key pair before creating a new one. To view instructions,
see Managing Access Keys in the IAM User Guide.
To get started right away, see Creating Your First IAM Delegated User and Group in the IAM User Guide.
• To learn whether Amazon ECR supports these features, see How Amazon Elastic Container Registry
Works with IAM (p. 55).
• To learn how to provide access to your resources across AWS accounts that you own, see Providing
Access to an IAM User in Another AWS Account That You Own in the IAM User Guide.
• To learn how to provide access to your resources to third-party AWS accounts, see Providing Access to
AWS Accounts Owned by Third Parties in the IAM User Guide.
• To learn how to provide access through identity federation, see Providing Access to Externally
Authenticated Users (Identity Federation) in the IAM User Guide.
• To learn the difference between using roles and resource-based policies for cross-account access, see
How IAM Roles Differ from Resource-based Policies in the IAM User Guide.
For a list of AWS services in scope of specific compliance programs, see AWS Services in Scope by
Compliance Program. For general information, see AWS Compliance Programs.
You can download third-party audit reports using AWS Artifact. For more information, see Downloading
Reports in AWS Artifact.
Your compliance responsibility when using Amazon ECR is determined by the sensitivity of your data,
your company's compliance objectives, and applicable laws and regulations. AWS provides the following
resources to help with compliance:
• Security and Compliance Quick Start Guides – These deployment guides discuss architectural
considerations and provide steps for deploying security- and compliance-focused baseline
environments on AWS.
• Architecting for HIPAA Security and Compliance Whitepaper – This whitepaper describes how
companies can use AWS to create HIPAA-compliant applications.
• AWS Compliance Resources – This collection of workbooks and guides might apply to your industry
and location.
• Evaluating Resources with Rules in the AWS Config Developer Guide – The AWS Config service assesses
how well your resource configurations comply with internal practices, industry guidelines, and
regulations.
• AWS Security Hub – This AWS service provides a comprehensive view of your security state within AWS
that helps you check your compliance with security industry standards and best practices.
You use AWS published API calls to access Amazon ECR through the network. Clients must support
Transport Layer Security (TLS) 1.0 or later. We recommend TLS 1.2 or later. Clients must also support
cipher suites with perfect forward secrecy (PFS) such as Ephemeral Diffie-Hellman (DHE) or Elliptic Curve
Ephemeral Diffie-Hellman (ECDHE). Most modern systems such as Java 7 and later support these modes.
Additionally, requests must be signed by using an access key ID and a secret access key that is associated
with an IAM principal. Or you can use the AWS Security Token Service (AWS STS) to generate temporary
security credentials to sign requests.
You can call these API operations from any network location, but Amazon ECR does support resource-
based access policies, which can include restrictions based on the source IP address. You can also use
Amazon ECR policies to control access from specific Amazon Virtual Private Cloud (Amazon VPC)
endpoints or specific VPCs. Effectively, this isolates network access to a given Amazon ECR resource from
only the specific VPC within the AWS network. For more information, see Amazon ECR Interface VPC
Endpoints (AWS PrivateLink) (p. 66).
For more information about AWS PrivateLink and VPC endpoints, see VPC Endpoints in the Amazon VPC
User Guide.
Topics
• Considerations for Amazon ECR VPC Endpoints (p. 67)
• Create the VPC Endpoint for Amazon ECR (p. 67)
• Create the Amazon S3 Gateway Endpoint (p. 68)
• Create the CloudWatch Logs Endpoint (p. 69)
• Create an Endpoint Policy for your Amazon ECR VPC Endpoint (p. 69)
• To allow your Amazon ECS tasks that use the EC2 launch type to pull private images from Amazon
ECR, ensure that you also create the interface VPC endpoints for Amazon ECS. For more information,
see Interface VPC Endpoints (AWS PrivateLink) in the Amazon Elastic Container Service Developer Guide.
Important
Amazon ECS tasks that use the Fargate launch type don't require the Amazon ECS interface
VPC endpoints.
• Amazon ECS tasks using the Fargate launch type and platform version 1.3.0 or earlier only require the
com.amazonaws.region.ecr.dkr Amazon ECR VPC endpoint and the Amazon S3 gateway endpoint to
take advantage of this feature.
• Amazon ECS tasks using the Fargate launch type and platform version 1.4.0 or later require the
com.amazonaws.region.ecr.dkr and com.amazonaws.region.ecr.api Amazon ECR VPC endpoints
and the Amazon S3 gateway endpoint to take advantage of this feature.
• Amazon ECS tasks using the Fargate launch type that pull container images from Amazon ECR can
restrict access to the specific VPC their tasks use and to the VPC endpoint the service uses by adding
condition keys to their task execution role. For more information, see Amazon ECS Task Execution IAM
Role in the Amazon Elastic Container Service Developer Guide.
• VPC endpoints currently don't support cross-Region requests. Ensure that you create your endpoint in
the same Region where you plan to issue your API calls to Amazon ECR.
• VPC endpoints only support Amazon provided DNS through Amazon Route 53. If you want to use your
own DNS, you can use conditional DNS forwarding. For more information, see DHCP Options Sets in
the Amazon VPC User Guide.
• The security group attached to the VPC endpoint must allow incoming connections on port 443 from
the private subnet of the VPC.
• If your containers have existing connections to Amazon S3, their connections might be briefly
interrupted when you add the Amazon S3 gateway endpoint. If you want to avoid this interruption,
create a new VPC that uses the Amazon S3 gateway endpoint and then migrate your Amazon ECS
cluster and its containers into the new VPC.
If your Amazon ECS tasks use the EC2 launch type, both of the following endpoints are required. The
order that the endpoints are created in doesn't matter. If your tasks are using the Fargate launch type,
only the com.amazonaws.region.ecr.dkr endpoint is required.
com.amazonaws.region.ecr.api
Note
The specified region represents the Region identifier for an AWS Region supported by
Amazon ECR, such as us-east-2 for the US East (Ohio) Region.
This endpoint is used for calls to the Amazon ECR API. API actions such as DescribeImages and
CreateRepositories go to this endpoint.
When the com.amazonaws.region.ecr.api endpoint is created, you have the option to enable
a private DNS hostname. Enable this hostname by selecting Enable Private DNS Name in the VPC
console when you create the VPC endpoint. If you enable a private DNS hostname for the VPC
endpoint, update your SDK or AWS CLI to the latest version so that specifying an endpoint URL
when using the SDK or AWS CLI isn't necessary.
If you enable a private DNS hostname and are using an SDK or AWS CLI version released before
January 24, 2019, you must use the --endpoint-url parameter to specify the interface endpoints.
The following example CLI command shows the format of the endpoint URL.
If you don't enable a private DNS hostname for the VPC endpoint, you must use the --endpoint-
url parameter specifying the VPC endpoint ID for the interface endpoint. Following is the format
for the endpoint URL.
com.amazonaws.region.ecr.dkr
This endpoint is used for the Docker Registry APIs. Docker client commands such as push and pull
use this endpoint.
When you create the com.amazonaws.region.ecr.dkr endpoint, you must enable a private
DNS hostname. To do this, ensure that the Enable Private DNS Name option is selected in the VPC
console when you create the VPC endpoint.
arn:aws:s3:::prod-region-starport-layer-bucket/*
Use the Creating a Gateway Endpoint procedure in the Amazon VPC User Guide to create the following
Amazon S3 gateway endpoint for the Amazon ECR service. When you create the endpoint, be sure to
select the route tables for your VPC.
com.amazonaws.region.s3
The Amazon S3 gateway endpoint uses an IAM policy document to limit access to the service. The
Full Access policy can be used because any restrictions that you have put in your task IAM roles
or other IAM user policies still apply on top of this policy. If you want to limit Amazon S3 bucket
access to the minimum required permissions for using Amazon ECR, see Minimum Amazon S3 Bucket
Permissions for Amazon ECR (p. 69).
The following table describes the Amazon S3 bucket policy permissions needed by Amazon ECR.
Permission Description
Example
The following example illustrates how to provide access to the Amazon S3 buckets required for Amazon
ECR operations.
{
"Statement": [
{
"Sid": "Access-to-specific-bucket-only",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::prod-region-starport-layer-bucket/*"]
}
]
}
We recommend creating a single IAM resource policy and attaching it to both of the Amazon ECR VPC
endpoints.
The following is an example of an endpoint policy for Amazon ECR. This policy enables a specific IAM
role to pull images from Amazon ECR.
{
"Statement": [{
"Sid": "AllowPull",
"Principal": {
"AWS": "arn:aws:iam::1234567890:role/role_name"
},
"Action": [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer"
],
"Effect": "Allow",
"Resource": "*"
}]
}
The following endpoint policy example prevents a specified repository from being deleted.
{
"Statement": [{
"Sid": "AllowAll",
"Principal": "*",
"Action": "*",
"Effect": "Allow",
"Resource": "*"
},
{
"Sid": "PreventDelete",
"Principal": "*",
"Action": "ecr:DeleteRepository",
"Effect": "Deny",
"Resource": "arn:aws:ecr:region:1234567890:repository/repository_name"
}
]
}
The following endpoint policy example combines the two previous examples into a single policy.
{
"Statement": [{
"Sid": "AllowAll",
"Effect": "Allow",
"Principal": "*",
"Action": "*",
"Resource": "*"
},
{
"Sid": "PreventDelete",
"Effect": "Deny",
"Principal": "*",
"Action": "ecr:DeleteRepository",
"Resource": "arn:aws:ecr:region:1234567890:repository/repository_name"
},
{
"Sid": "AllowPull",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::1234567890:role/role_name"
},
"Action": [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer"
],
"Resource": "*"
}
]
}
Amazon ECR provides metrics based on your API usage for authorization, image push, and image pull
actions.
Monitoring is an important part of maintaining the reliability, availability, and performance of Amazon
ECR and your AWS solutions. We recommend that you collect monitoring data from the resources that
make up your AWS solution so that you can more easily debug a multi-point failure if one occurs. Before
you start monitoring Amazon ECR, however, you should create a monitoring plan that includes answers
to the following questions:
The next step is to establish a baseline for normal Amazon ECR performance in your environment by
measuring performance at various times and under different load conditions. As you monitor Amazon
ECR, store historical monitoring data so that you can compare it with new performance data, identify
normal performance patterns and performance anomalies, and devise methods to address issues.
Topics
• Visualizing Your Service Quotas and Setting Alarms (p. 72)
• Amazon ECR Usage Metrics (p. 73)
• Amazon ECR Usage Reports (p. 74)
• Amazon ECR Events and EventBridge (p. 74)
• Logging Amazon ECR Actions with AWS CloudTrail (p. 76)
A new line is added to the graph, displaying the service quota for the resource represented in
the metric.
6. To see your current usage as a percentage of the quota, add a new expression or change the current
SERVICE_QUOTA expression. For the new expression, use m1/60/SERVICE_QUOTA(m1)*100.
7. (Optional) To set an alarm that notifies you if you approach the service quota, do the following:
a. On the m1/60/SERVICE_QUOTA(m1)*100 row, under Actions, choose the alarm icon. It looks
like a bell.
Amazon ECR usage metrics correspond to AWS service quotas. You can configure alarms that alert you
when your usage approaches a service quota. For more information about Amazon ECR service quotas,
see Amazon ECR service quotas (p. 84).
Metric Description
CallCount The number of API action calls from your account. The resources are
defined by the dimensions associated with the metric.
The most useful statistic for this metric is SUM, which represents the
sum of the values from all contributors during the period defined.
The following dimensions are used to refine the usage metrics that are published by Amazon ECR.
Dimension Description
Service The name of the AWS service containing the resource. For Amazon
ECR usage metrics, the value for this dimension is ECR.
Type The type of entity that is being reported. Currently, the only valid
value for Amazon ECR usage metrics is API.
Resource The type of resource that is running. Currently, Amazon ECR returns
information on your API usage for the following API actions.
• GetAuthorizationToken
• BatchCheckLayerAvailability
• InitiateLayerUpload
• UploadLayerPart
• CompleteLayerUpload
• PutImage
• BatchGetImage
• GetDownloadUrlForLayer
Class The class of resource being tracked. Currently, Amazon ECR does
not use the class dimension.
Use Cost Explorer to view charts of your usage and costs. You can view data from the previous 13
months and forecast how much you are likely to spend for the next three months. You can use Cost
Explorer to see patterns in how much you spend on AWS resources over time, identify areas that need
further inquiry, and see trends that you can use to understand your costs. You also can specify time
ranges for the data and view time data by day or by month.
The metering data in your Cost and Usage Reports shows usage across all of your Amazon ECR
repositories. For more information, see Tagging Your Resources for Billing (p. 25).
For more information about creating an AWS Cost and Usage Report, see AWS Cost and Usage Report in
the AWS Billing and Cost Management User Guide.
For more information, see Getting Started with Amazon EventBridge in the Amazon EventBridge User
Guide.
The following event is sent when each image push is completed. For more information, see Pushing an
image (p. 27).
{
"version": "0",
"id": "13cde686-328b-6117-af20-0e5566167482",
"detail-type": "ECR Image Action",
"source": "aws.ecr",
"account": "123456789012",
"time": "2019-11-16T01:54:34Z",
"region": "us-west-2",
"resources": [],
"detail": {
"result": "SUCCESS",
"repository-name": "my-repo",
"image-digest":
"sha256:7f5b2640fe6fb4f46592dfd3410c4a79dac4f89e4782432e0378abcd1234",
"action-type": "PUSH",
"image-tag": "latest"
}
}
The following event is sent when each image scan is completed. The finding-severity-counts
parameter will only return a value for a severity level if one exists. For example, if the image contains
no findings at CRITICAL level, then no critical count is returned. For more information, see Image
scanning (p. 43).
{
"version": "0",
"id": "85fc3613-e913-7fc4-a80c-a3753e4aa9ae",
"detail-type": "ECR Image Scan",
"source": "aws.ecr",
"account": "123456789012",
"time": "2019-10-29T02:36:48Z",
"region": "us-east-1",
"resources": [
"arn:aws:ecr:us-east-1:123456789012:repository/my-repo"
],
"detail": {
"scan-status": "COMPLETE",
"repository-name": "my-repo",
"finding-severity-counts": {
"CRITICAL": 10,
"MEDIUM”: 9
},
"image-digest":
"sha256:7f5b2640fe6fb4f46592dfd3410c4a79dac4f89e4782432e0378abcd1234",
"image-tags": []
}
}
The following event is sent when an image is deleted. For more information, see Deleting an
image (p. 29).
{
"version": "0",
"id": "dd3b46cb-2c74-f49e-393b-28286b67279d",
"detail-type": "ECR Image Action",
"source": "aws.ecr",
"account": "123456789012",
"time": "2019-11-16T02:01:05Z",
"region": "us-west-2",
"resources": [],
"detail": {
"result": "SUCCESS",
"repository-name": "my-repo",
"image-digest":
"sha256:7f5b2640fe6fb4f46592dfd3410c4a79dac4f89e4782432e0378abcd1234",
"action-type": "DELETE",
"image-tag": "latest"
}
}
• All API calls, including calls from the Amazon ECR console
• All actions taken due to lifecycle policy rules, including both successful and unsuccessful actions
When a trail is created, you can enable continuous delivery of CloudTrail events to an Amazon S3 bucket,
including events for Amazon ECR. If you don't configure a trail, you can still view the most recent events
in the CloudTrail console in Event history. Using this information, you can determine the request that
was made to Amazon ECR, the originating IP address, who made the request, when it was made, and
additional details.
For an ongoing record of events in your AWS account, including events for Amazon ECR, create a trail.
A trail enables CloudTrail to deliver log files to an Amazon S3 bucket. When you create a trail in the
console, you can apply the trail to a single Region or to all Regions. The trail logs events in the AWS
partition and delivers the log files to the Amazon S3 bucket that you specify. Additionally, you can
configure other AWS services to analyze and act upon the event data collected in CloudTrail logs. For
more information, see:
All Amazon ECR API actions are logged by CloudTrail and are documented in the Amazon Elastic
Container Registry API Reference. When you perform common tasks, sections are generated in the
CloudTrail log files for each API action that is part of that task. For example, when you create a
repository, GetAuthorizationToken, CreateRepository and SetRepositoryPolicy sections are
generated in the CloudTrail log files. When you push an image to a repository, InitiateLayerUpload,
UploadLayerPart, CompleteLayerUpload, and PutImage sections are generated. When you pull an
image, GetDownloadUrlForLayer and BatchGetImage sections are generated. For examples of these
common tasks, see CloudTrail Log Entry Examples (p. 77).
Every event or log entry contains information about who generated the request. The identity
information helps you determine the following:
• Whether the request was made with root or IAM user credentials
• Whether the request was made with temporary security credentials for a role or federated user
• Whether the request was made by another AWS service
Topics
• Example: Create Repository Action (p. 78)
• Example: Image Push Action (p. 78)
• Example: Image Pull Action (p. 81)
{
"eventVersion": "1.04",
"userIdentity": {
"type": "AssumedRole",
"principalId": "AIDACKCEVSQ6C2EXAMPLE:account_name",
"arn": "arn:aws:sts::123456789012:user/Mary_Major",
"accountId": "123456789012",
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"sessionContext": {
"attributes": {
"mfaAuthenticated": "false",
"creationDate": "2018-07-11T21:54:07Z"
},
"sessionIssuer": {
"type": "Role",
"principalId": "AIDACKCEVSQ6C2EXAMPLE",
"arn": "arn:aws:iam::123456789012:role/Admin",
"accountId": "123456789012",
"userName": "Admin"
}
}
},
"eventTime": "2018-07-11T22:17:43Z",
"eventSource": "ecr.amazonaws.com",
"eventName": "CreateRepository",
"awsRegion": "us-east-2",
"sourceIPAddress": "203.0.113.12",
"userAgent": "console.amazonaws.com",
"requestParameters": {
"repositoryName": "testrepo"
},
"responseElements": {
"repository": {
"repositoryArn": "arn:aws:ecr:us-east-2:123456789012:repository/testrepo",
"repositoryName": "testrepo",
"repositoryUri": "123456789012.dkr.ecr.us-east-2.amazonaws.com/testrepo",
"createdAt": "Jul 11, 2018 10:17:44 PM",
"registryId": "123456789012"
}
},
"requestID": "cb8c167e-EXAMPLE",
"eventID": "e3c6f4ce-EXAMPLE",
"resources": [
{
"ARN": "arn:aws:ecr:us-east-2:123456789012:repository/testrepo",
"accountId": "123456789012"
}
],
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012"
}
Note
When pushing an image, you will also see InitiateLayerUpload, UploadLayerPart, and
CompleteLayerUpload references in the CloudTrail logs.
{
"eventVersion": "1.04",
"userIdentity": {
"type": "IAMUser",
"principalId": "AIDACKCEVSQ6C2EXAMPLE:account_name",
"arn": "arn:aws:sts::123456789012:user/Mary_Major",
"accountId": "123456789012",
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"userName": "Mary_Major",
"sessionContext": {
"attributes": {
"mfaAuthenticated": "false",
"creationDate": "2019-04-15T16:42:14Z"
}
}
},
"eventTime": "2019-04-15T16:45:00Z",
"eventSource": "ecr.amazonaws.com",
"eventName": "PutImage",
"awsRegion": "us-east-2",
"sourceIPAddress": "203.0.113.12",
"userAgent": "console.amazonaws.com",
"requestParameters": {
"repositoryName": "testrepo",
"imageTag": "latest",
"registryId": "123456789012",
"imageManifest": "{\n \"schemaVersion\": 2,\n \"mediaType\": \"application/
vnd.docker.distribution.manifest.v2+json\",\n \"config\": {\n \"mediaType\":
\"application/vnd.docker.container.image.v1+json\",\n \"size\": 5543,\n
\"digest\": \"sha256:000b9b805af1cdb60628898c9f411996301a1c13afd3dbef1d8a16ac6dbf503a
\"\n },\n \"layers\": [\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 43252507,\n
\"digest\": \"sha256:3b37166ec61459e76e33282dda08f2a9cd698ca7e3d6bc44e6a6e7580cdeff8e
\"\n },\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 846,\n \"digest
\": \"sha256:504facff238fde83f1ca8f9f54520b4219c5b8f80be9616ddc52d31448a044bd
\"\n },\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 615,\n \"digest
\": \"sha256:ebbcacd28e101968415b0c812b2d2dc60f969e36b0b08c073bf796e12b1bb449\"\n
},\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 850,\n \"digest
\": \"sha256:c7fb3351ecad291a88b92b600037e2435c84a347683d540042086fe72c902b8a
\"\n },\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 168,\n \"digest
\": \"sha256:2e3debadcbf7e542e2aefbce1b64a358b1931fb403b3e4aeca27cb4d809d56c2\"\n
},\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 37720774,\n \"digest
\": \"sha256:f8c9f51ad524d8ae9bf4db69cd3e720ba92373ec265f5c390ffb21bb0c277941\"\n
},\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 30432107,\n
\"digest\": \"sha256:813a50b13f61cf1f8d25f19fa96ad3aa5b552896c83e86ce413b48b091d7f01b
\"\n },\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 197,\n \"digest
\": \"sha256:7ab043301a6187ea3293d80b30ba06c7bf1a0c3cd4c43d10353b31bc0cecfe7d
\"\n },\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 154,\n \"digest
\": \"sha256:67012cca8f31dc3b8ee2305e7762fee20c250513effdedb38a1c37784a5a2e71\"\n
},\n {\n \"mediaType\": \"application/
vnd.docker.image.rootfs.diff.tar.gzip\",\n \"size\": 176,\n \"digest
\": \"sha256:3bc892145603fffc9b1c97c94e2985b4cb19ca508750b15845a5d97becbd1a0e
\"\n },\n {\n \"mediaType\": \"application/
"eventID": "2bfd4ee2-2178-4a82-a27d-b12939923f0f",
"resources": [{
"ARN": "arn:aws:ecr:us-east-2:123456789012:repository/testrepo",
"accountId": "123456789012"
}],
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012"
}
{
"eventVersion": "1.04",
"userIdentity": {
"type": "IAMUser",
"principalId": "AIDACKCEVSQ6C2EXAMPLE:account_name",
"arn": "arn:aws:sts::123456789012:user/Mary_Major",
"accountId": "123456789012",
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"userName": "Mary_Major",
"sessionContext": {
"attributes": {
"mfaAuthenticated": "false",
"creationDate": "2019-04-15T16:42:14Z"
}
}
},
"eventTime": "2019-04-15T17:23:20Z",
"eventSource": "ecr.amazonaws.com",
"eventName": "BatchGetImage",
"awsRegion": "us-east-2",
"sourceIPAddress": "203.0.113.12",
"userAgent": "console.amazonaws.com",
"requestParameters": {
"imageIds": [{
"imageTag": "latest"
}],
"acceptedMediaTypes": [
"application/json",
"application/vnd.oci.image.manifest.v1+json",
"application/vnd.oci.image.index.v1+json",
"application/vnd.docker.distribution.manifest.v2+json",
"application/vnd.docker.distribution.manifest.list.v2+json",
"application/vnd.docker.distribution.manifest.v1+prettyjws"
],
"repositoryName": "testrepo",
"registryId": "123456789012"
},
"responseElements": null,
"requestID": "2a1b97ee-5fa3-11e9-a8cd-cd2391aeda93",
"eventID": "c84f5880-c2f9-4585-9757-28fa5c1065df",
"resources": [{
"ARN": "arn:aws:ecr:us-east-2:123456789012:repository/testrepo",
"accountId": "123456789012"
}],
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012"
{
"eventVersion": "1.05",
"userIdentity": {
"accountId": "123456789012",
"invokedBy": "AWS Internal"
},
"eventTime": "2020-03-12T20:22:12Z",
"eventSource": "ecr.amazonaws.com",
"eventName": "PolicyExecutionEvent",
"awsRegion": "us-west-2",
"sourceIPAddress": "AWS Internal",
"userAgent": "AWS Internal",
"requestParameters": null,
"responseElements": null,
"eventID": "9354dd7f-9aac-4e9d-956d-12561a4923aa",
"readOnly": true,
"resources": [
{
"ARN": "arn:aws:ecr:us-west-2:123456789012:repository/testrepo",
"accountId": "123456789012",
"type": "AWS::ECR::Repository"
}
],
"eventType": "AwsServiceEvent",
"recipientAccountId": "123456789012",
"serviceEventDetails": {
"repositoryName": "testrepo",
"lifecycleEventPolicy": {
"lifecycleEventRules": [
{
"rulePriority": 1,
"description": "remove all images > 2",
"lifecycleEventSelection": {
"tagStatus": "Any",
"tagPrefixList": [],
"countType": "Image count more than",
"countNumber": 2
},
"action": "expire"
}
],
"lastEvaluatedAt": 0,
"policyVersion": 1,
"policyId": "ceb86829-58e7-9498-920c-aa042e33037b"
},
"lifecycleEventImageActions": [
{
"lifecycleEventImage": {
"digest":
"sha256:ddba4d27a7ffc3f86dd6c2f92041af252a1f23a8e742c90e6e1297bfa1bc0c45",
"tagStatus": "Tagged",
"tagList": [
"alpine"
],
"pushedAt": 1584042813000
},
"rulePriority": 1
},
{
"lifecycleEventImage": {
"digest":
"sha256:6ab380c5a5acf71c1b6660d645d2cd79cc8ce91b38e0352cbf9561e050427baf",
"tagStatus": "Tagged",
"tagList": [
"centos"
],
"pushedAt": 1584042842000
},
"rulePriority": 1
}
]
}
}
The following table provides the default rate quotas for each of the Amazon ECR API actions involved
with the image push and image pull actions.
When an image is
pushed to a repository,
each image layer is
checked to verify if
it has been uploaded
before. If it has been
uploaded, then the
image layer is skipped.
When an image
is pushed, the
InitiateLayerUpload
API is called once
per image layer that
has not already been
uploaded. Whether
When an image
is pushed, the
CompleteLayerUpload
API is called once
per each new image
layer to verify that the
upload has completed.
When an image is
pushed, each new
image layer is uploaded
in parts. The maximum
size of each image layer
part can be 20,971,520
bytes (or about 20MB).
The UploadLayerPart
API is called once per
each new image layer
part.
When an image is
pushed and all new
image layers have been
uploaded, the PutImage
API is called once to
create or update the
image manifest and the
tags associated with the
image.
When an image
is pulled, the
BatchGetImage API is
called once to retrieve
the image manifest.
When an image
is pulled, the
GetDownloadUrlForLayer
API is called once per
image layer that is not
already cached.
The following table provides other quotas for Amazon ECR and Docker images that cannot be changed.
Note
The layer part information mentioned in the following table is only applicable if you are calling
the Amazon ECR API actions directly to initiate multipart uploads for image push operations.
This is a rare action. We recommend that you use the Docker CLI to pull, tag, and push images.
** The maximum layer size listed here is calculated by multiplying the maximum layer part size (10 MiB)
by the maximum number of layer parts (1,000).
Service Quotas makes it easy to look up the value of all Amazon ECR service quotas.
In the Service quotas list, you can see the service quota name, applied value (if it is available), AWS
default quota, and whether the quota value is adjustable.
4. To view additional information about a service quota, such as the description, choose the quota
name.
To request a quota increase, see Requesting a quota increase in the Service Quotas User Guide.
Use the following steps to create a CloudWatch alarm based on one of the Amazon ECR API usage
metrics.
To create an alarm based on your Amazon ECR usage quotas (AWS Management Console)
Topics
• Enabling Docker Debug Output (p. 89)
• Enabling AWS CloudTrail (p. 89)
• Optimizing Performance for Amazon ECR (p. 89)
• Troubleshooting Errors with Docker Commands When Using Amazon ECR (p. 90)
• Troubleshooting Amazon ECR Error Messages (p. 92)
• Troubleshooting Image Scanning Issues (p. 94)
Use Docker 1.10 and above to take advantage of simultaneous layer uploads
Docker images are composed of layers, which are intermediate build stages of the image. Each line
in a Dockerfile results in the creation of a new layer. When you use Docker 1.10 and above, Docker
defaults to pushing as many layers as possible as simultaneous uploads to Amazon ECR, resulting in
faster upload times.
Use a smaller base image
The default images available through Docker Hub may contain many dependencies that your
application doesn't require. Consider using a smaller image created and maintained by others in the
Docker community, or build your own base image using Docker's minimal scratch image. For more
information, see Create a base image in the Docker documentation.
Place the dependencies that change the least earlier in your Dockerfile
Docker caches layers, and that speeds up build times. If nothing on a layer has changed since the
last build, Docker uses the cached version instead of rebuilding the layer. However, each layer is
dependent on the layers that came before it. If a layer changes, Docker recompiles not only that
layer, but any layers that come after that layer as well.
To minimize the time required to rebuild a Dockerfile and to re-upload layers, consider placing the
dependencies that change the least frequently earlier in your Dockerfile. Place rapidly changing
dependencies (such as your application's source code) later in the stack.
Chain commands to avoid unnecessary file storage
Intermediate files created on a layer remain a part of that layer even if they are deleted in a
subsequent layer. Consider the following example:
WORKDIR /tmp
RUN wget http://example.com/software.tar.gz
RUN wget tar -xvf software.tar.gz
RUN mv software/binary /opt/bin/myapp
RUN rm software.tar.gz
In this example, the layers created by the first and second RUN commands contain the original .tar.gz
file and all of its unzipped contents. This is even though the .tar.gz file is deleted by the fourth RUN
command. These commands can be chained together into a single RUN statement to ensure that
these unnecessary files aren't part of the final Docker image:
WORKDIR /tmp
RUN wget http://example.com/software.tar.gz &&\
wget tar -xvf software.tar.gz &&\
mv software/binary /opt/bin/myapp &&\
rm software.tar.gz
You can reduce latency in pulling images from Amazon ECR by ensuring that you are using the
regional endpoint closest to where your application is running. If your application is running on an
Amazon EC2 instance, you can use the following shell code to obtain the region from the Availability
Zone of the instance:
REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone |\
sed -n 's/\(\d*\)[a-zA-Z]*$/\1/p')
The region can be passed to AWS CLI commands using the --region parameter, or set as the default
region for a profile using the aws configure command. You can also set the region when making
calls using the AWS SDK. For more information, see the documentation for the SDK for your specific
programming language.
In some cases, running a Docker command against Amazon ECR may result in an error message. Some
common error messages and potential solutions are explained below.
If the local disk on which you're running docker pull is full, then the SHA-1 hash calculated on the
local file may be different than the one calculated by Amazon ECR. Check that your local disk has
enough remaining free space to store the Docker image you are pulling. You can also delete old
images to make room for new ones. Use the docker images command to see a list of all locally
downloaded Docker images, along with their sizes.
Client cannot connect to the remote repository due to network error
Calls to an Amazon ECR repository require a functioning connection to the internet. Verify your
network settings, and verify that other tools and applications can access resources on the internet. If
you are running docker pull on an Amazon EC2 instance in a private subnet, verify that the subnet
has a route to the internet. Use a network address translation (NAT) server or a managed NAT
gateway.
Currently, calls to an Amazon ECR repository also require network access through your corporate
firewall to Amazon Simple Storage Service (Amazon S3). If your organization uses firewall software
or a NAT device that allows service endpoints, ensure that the Amazon S3 service endpoints for your
current Region are allowed.
If you are using Docker behind an HTTP proxy, you can configure Docker with the appropriate proxy
settings. For more information, see HTTP proxy in the Docker documentation.
This error indicates that one or more of the layers for your image has failed to download. Some possible
reasons and their explanations are given below.
This error can occur in a small percentage of cases when using a Docker version less than 1.10.
Upgrade your Docker client to 1.10 or greater.
A full disk or a network issue may prevent one or more layers from downloading, as discussed earlier
about the Filesystem verification failed message. Follow the recommendations above to
ensure that your filesystem is not full, and that you have enabled access to Amazon S3 from within
your network.
Authentication requests are tied to specific regions, and cannot be used across regions. For example,
if you obtain an authorization token from US West (Oregon), you cannot use it to authenticate
against your repositories in US East (N. Virginia). To resolve the issue, ensure that you have retrieved
an authentication token from the same Region your repository exists in.
You have authenticated to push to a repository you don't have permissions for
You do not have the necessary permissions to push to the repository. For more information, see
Amazon ECR Repository Policies (p. 17).
Your token has expired
The default authorization token expiration period for tokens obtained using the
GetAuthorizationToken operation is 12 hours. However, if you use a temporary security
credential mechanism to authenticate and receive your token, the expiration period of the token
is equal to the duration of the temporary credentials. Temporary security credential mechanisms
include multi-factor authentication (MFA) or AWS Security Token Service. For example, if you call the
aws ecr get-login-password command by assuming a role, the authorization token expires based
on the session duration. This depends on the settings you use when calling the aws sts assume-role
command.
Bug in wincred credential manager
Some versions of Docker for Windows use a credential manager called wincred, which does not
properly handle the Docker login command produced by aws ecr get-login (for more information,
see https://github.com/docker/docker/issues/22910). You can run the Docker login command that
is output, but when you try to push or pull images, those commands fail. You can work around this
bug by removing the https:// scheme from the registry argument in the Docker login command
that is output from aws ecr get-login. An example Docker login command without the HTTPS
scheme is shown below.
This error can occur on MacOS X and Windows systems that are running Docker Toolbox, Docker for
Windows, or Docker for Mac. It is often caused when other applications alter the routes through the
local gateway (192.168.0.1) through which the virtual machine must call to access the Amazon ECR
service. If this error occurs when using Docker Toolbox, then it can often be resolved by restarting the
Docker Machine environment, or rebooting the local client operating system. If this does not resolve the
issue, use the docker-machine ssh command to log in to your container instance. Perform a DNS lookup
on an external host to verify that you see the same results as you see on your local host. If the results
differ, consult the documentation for Docker Toolbox to ensure that your Docker Machine environment is
configured properly.
This indicates that you are calling a single endpoint in Amazon ECR repeatedly over a short interval, and
that your requests are getting throttled. Throttling occurs when calls to a single endpoint from a single
user exceed a certain threshold over a period of time.
For example, the throttle for the GetAuthorizationToken action is 20 transaction per second (TPS),
with up to a 200 TPS burst allowed. In each region, each account receives a bucket that can store up to
200 GetAuthorizationToken credits. These credits are replenished at a rate of 20 per second. If your
bucket has 200 credits, you could achieve 200 GetAuthorizationToken API transactions per second
for one second, and then sustain 20 transactions per second indefinitely.
To handle throttling errors, implement a retry function with incremental backoff into your code. For
more information, see Error Retries and Exponential Backoff in AWS in the Amazon Web Services General
Reference.
This indicates that your user does not have permissions granted to use Amazon ECR, or that those
permissions are not set up correctly. In particular, if you are performing actions against an Amazon
ECR repository, verify that the user has been granted permissions to access that repository. For
more information about creating and verifying permissions for Amazon ECR, see Identity and Access
Management for Amazon Elastic Container Registry (p. 51).
UnsupportedImageError
You may get an UnsupportedImageError error when attempting to scan an image that was
built using an operating system that Amazon ECR doesn't support image scanning for. Amazon
ECR supports package vulnerability scanning for major versions of Amazon Linux, Amazon Linux 2,
Debian, Ubuntu, CentOS, Oracle Linux, Alpine, and RHEL Linux distributions. Amazon ECR does not
support scanning images built from the Docker scratch image.
An UNDEFINED severity level is returned
You may receive a scan finding that has a severity level of UNDEFINED. The following are the
common causes for this:
• The vulnerability was not assigned a priority by the CVE source.
• The vulnerability was assigned a priority that Amazon ECR did not recognize.
To determine the severity and description of a vulnerability, you can view the CVE directly from the
source.
Document History
The following table describes the important changes to the documentation since the last release of
Amazon ECR. We also update the documentation frequently to address the feedback that you send us.
Multi-architecture images Amazon ECR added support for creating and pushing 28 April
Docker manifest lists which are used for multi- 2020
architecture images.
Amazon ECR Usage Metrics Amazon ECR added CloudWatch usage metrics which 28 Feb 2020
provides visiblity into your account's resource usage. You
also have the ability to create CloudWatch alarms from
both the CloudWatch and Service Quotas consoles to get
alerts when your usage approaches your applied service
quota.
Updated Amazon ECR Updated the Amazon ECR service quotas to include per- 19 Feb 2020
service quotas API quotas.
Added get-login- Added support for get-login-password, which provides a 4 Feb 2020
password command simple and secure method for retrieving an authorization
token.
Image Scanning Added support for image scanning, which helps in 24 Oct 2019
identifying software vulnerabilities in your container
images. Amazon ECR uses the Common Vulnerabilities
and Exposures (CVEs) database from the open source
CoreOS Clair project and provides you with a list of scan
findings.
VPC Endpoint Policy Added support for setting an IAM policy on the Amazon 26 Sept
ECR interface VPC endpoints. 2019
Image Tag Mutability Added support for configuring a repository to be 25 July 2019
immutable to prevent image tags from being overwritten.
Interface VPC Endpoints Added support for configuring interface VPC endpoints 25 Jan 2019
(AWS PrivateLink) powered by AWS PrivateLink. This allows you to create a
private connection between your VPC and Amazon ECR
without requiring access over the Internet, through a NAT
instance, a VPN connection, or AWS Direct Connect.
Resource tagging Amazon ECR added support for adding metadata tags to 18 Dec 2018
your repositories.
Amazon ECR Name Change Amazon Elastic Container Registry is renamed (previously 21 Nov 2017
Amazon EC2 Container Registry).
Lifecycle Policies Amazon ECR lifecycle policies enable you to specify the 11 Oct 2017
lifecycle management of images in a repository.
Amazon ECR support for Amazon ECR now supports Docker Image Manifest V2 27 Jan 2017
Docker image manifest 2, Schema 2 (used with Docker version 1.10 and newer).
schema 2
For more information, see Container image manifest
formats (p. 47).
Amazon ECR General Amazon Elastic Container Registry (Amazon ECR) is a 21 Dec 2015
Availability managed AWS Docker registry service that is secure,
scalable, and reliable.
AWS Glossary
For the latest AWS terminology, see the AWS Glossary in the AWS General Reference.