# IAM policy example: push images to one ECR repository, with a least privilege rewrite

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

Allows a build role to push images to one repository, web-app, with the upload and layer actions a push uses. The AWS documentation lists these actions. The original puts them on every repository in the account. The names and the account ID 111122223333 are AWS documentation placeholders.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Login",
      "Effect": "Allow",
      "Action": "ecr:GetAuthorizationToken",
      "Resource": "*"
    },
    {
      "Sid": "Push",
      "Effect": "Allow",
      "Action": [
        "ecr:BatchCheckLayerAvailability",
        "ecr:InitiateLayerUpload",
        "ecr:UploadLayerPart",
        "ecr:CompleteLayerUpload",
        "ecr:PutImage"
      ],
      "Resource": "arn:aws:ecr:us-east-1:111122223333:repository/*"
    }
  ]
}
```

## What it allows

- Allows login, then pushing images to any repository in one Region.

- Allows 1 action (ecr:GetAuthorizationToken) on every resource.
- Allows 5 actions (ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, ecr:PutImage) on arn:aws:ecr:us-east-1:111122223333:repository/*.

Checks:
- No flags.

A build job could overwrite an image in a repository that production services pull from.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Login",
      "Effect": "Allow",
      "Action": "ecr:GetAuthorizationToken",
      "Resource": "*"
    },
    {
      "Sid": "PushOne",
      "Effect": "Allow",
      "Action": [
        "ecr:BatchCheckLayerAvailability",
        "ecr:InitiateLayerUpload",
        "ecr:UploadLayerPart",
        "ecr:CompleteLayerUpload",
        "ecr:PutImage"
      ],
      "Resource": "arn:aws:ecr:us-east-1:111122223333:repository/web-app"
    }
  ]
}
```

The rewrite replaces the repository wildcard with one repository ARN. The build job can push only to web-app.

- Allows 1 action (ecr:GetAuthorizationToken) on every resource.
- Allows 5 actions (ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, ecr:PutImage) on arn:aws:ecr:us-east-1:111122223333:repository/web-app.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every Elastic Container Registry action and its access level](/actions/ecr/)

## Related pages

- [IAM policy example: run ECS tasks in one cluster](/examples/ecs-run-tasks-in-one-cluster/)
- [IAM policy example: read EKS cluster details for kubeconfig](/examples/eks-describe-cluster-for-kubeconfig/)
- [IAM policy example: invoke one Bedrock foundation model](/examples/bedrock-invoke-one-model/)
- [All of them](/examples/)

## Sources

- Amazon ECR User Guide: identity-based policy examples: https://docs.aws.amazon.com/AmazonECR/latest/userguide/security_iam_id-based-policy-examples.html (read 16 Nov 2026)
- Amazon ECR User Guide: repository policy examples: https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policy-examples.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/ecr-push-images-to-one-repository/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
