ECR Pull Through Cache for Docker Hub, GHCR and Quay: Setup, Image URIs, Permissions, Terraform, EKS, Cost and Every Error (Fix "toomanyrequests")
ECR pull through cache lets you pull public images such as nginx from Docker Hub, GitHub Container Registry, Quay or the Kubernetes registry through your own private Amazon ECR registry. You create a pull through cache rule with a repository prefix (for example docker-hub), then pull ACCOUNT.dkr.ecr.REGION.amazonaws.com/docker-hub/library/nginx:latest; on the first pull ECR creates the repository, fetches the image from upstream and keeps a copy, and later pulls come from your account. ECR checks upstream for a newer version of that tag at most once every 24 hours. Docker Hub, GitHub, Azure, GitLab and Chainguard need credentials stored in Secrets Manager under a name starting with ecr-pullthroughcache/; ECR Public, Quay and the Kubernetes registry do not. The identity that pulls needs ecr:BatchImportUpstreamImage and, for the first pull, ecr:CreateRepository. The feature itself is free: you pay normal ECR storage and data transfer. It is the standard fix for Docker Hub's "toomanyrequests" rate limit in CI and EKS. Below: setup in the console, CLI and Terraform, the image URI for each registry, permissions, EKS and ECS, cross-account ECR, private subnets, costs and every error.
The shop's deployment pipeline failed three times one Monday with the same message from Docker Hub: "toomanyrequests: You have reached your pull rate limit." Nothing in the code had changed. The build servers, the EKS nodes and a test cluster were all pulling the same public base images from Docker Hub, all from AWS addresses, and Docker Hub had had enough. Ethan's fix took twenty minutes and one rule in ECR. The images now come from the shop's own registry, and Docker Hub only hears from them about once a day per image.
New to ECR or Secrets Manager? The cards below cover both in plain English, plus the image pull errors this feature often fixes.
How ECR pull through cache works
Amazon ECR is AWS's container registry, the shelf where your images live (our plain-English ECR guide covers the basics). A pull through cache rule turns part of that shelf into a mirror of another registry:
- You create a rule that maps a prefix in your registry, say
docker-hub, to an upstream registry, say Docker Hub. - Something pulls
ACCOUNT.dkr.ecr.REGION.amazonaws.com/docker-hub/library/nginx:1.27. - The first time, ECR creates a repository called
docker-hub/library/nginx, fetches that image from Docker Hub (using your stored credentials if the upstream needs them), stores it, and returns it. - Later pulls of the same tag come straight from your registry. If more than 24 hours have passed since ECR last checked, it asks upstream whether the tag now points at a newer image and updates the cache if so.
- If upstream is unreachable or refuses, ECR still serves the last cached copy, so an outage at Docker Hub does not stop your deployments.
Cached repositories are ordinary ECR repositories: image scanning, replication and lifecycle policies all work on them. Multi-architecture images are cached in full (the manifest list and each architecture); pull by an architecture-specific tag or digest if you only want one.
Jake: "So it's a local photocopy of the public images?"
Ethan: "A photocopy that checks the original once a day. And when the library is closed, we still have our copy."
Why Docker Hub says "toomanyrequests"
Docker Hub limits how many image pulls it serves in a time window. Anonymous pulls get the lowest limit and are counted per IP address; pulls logged in with a free personal account get a higher limit counted per account; paid Docker subscriptions are effectively unlimited under a fair-use policy. Docker has changed the exact numbers more than once, so check its rate limit page for today's figures rather than trusting an old blog post, including this one.
Three things make AWS workloads hit the limit far sooner than a laptop would:
- Shared addresses. All the nodes in a private subnet leave through one NAT gateway, so to Docker Hub they look like a single, very busy user. Ten nodes each pulling five images at once is fifty pulls from one IP.
- Every new node pulls everything. Autoscaling, node replacements and Kubernetes upgrades start fresh nodes with empty image caches, which all pull the same images in the same few minutes.
- CI pulls on every build. Build servers that start clean each time pull base images for every single job.
Logging in to Docker Hub on each machine raises the limit but spreads a credential everywhere, and paying for Docker licenses only to lift a pull limit is expensive for a small team. The cache solves it structurally: one copy per Region in ECR, refreshed at most daily per tag, with one stored credential that only ECR uses.
Set up pull through cache for Docker Hub, step by step
1. Create a Docker Hub access token. In Docker Hub, go to your account settings and create a personal access token with read-only access. Even a free Docker Hub account gives authenticated pulls a higher limit than anonymous ones.
2. Store it in Secrets Manager, in the same account and Region as the rule, with a name that starts with ecr-pullthroughcache/:
aws secretsmanager create-secret \
--name ecr-pullthroughcache/docker-hub \
--secret-string '{"username":"shopbuilds","accessToken":"dckr_pat_EXAMPLE"}' \
--region us-east-1
The console's pull through cache page can create this secret for you with the right name and format. Our Secrets Manager explainer covers what the service does with it.
3. Create the rule. In the ECR console: Private registry, Settings (or Feature & Settings), Pull through cache, Add rule, choose Docker Hub, pick the secret, and set the repository prefix. With the CLI:
aws ecr create-pull-through-cache-rule \ --ecr-repository-prefix docker-hub \ --upstream-registry-url registry-1.docker.io \ --credential-arn arn:aws:secretsmanager:us-east-1:111122223333:secret:ecr-pullthroughcache/docker-hub-AbCdEf \ --region us-east-1 # Check the rule can reach upstream with those credentials aws ecr validate-pull-through-cache-rule --ecr-repository-prefix docker-hub --region us-east-1
4. Pull through it. Log in to your ECR registry and pull using the new path. Official Docker Hub images live under library/:
aws ecr get-login-password --region us-east-1 | \ docker login --username AWS --password-stdin 111122223333.dkr.ecr.us-east-1.amazonaws.com docker pull 111122223333.dkr.ecr.us-east-1.amazonaws.com/docker-hub/library/nginx:1.27 docker pull 111122223333.dkr.ecr.us-east-1.amazonaws.com/docker-hub/grafana/grafana:latest
5. Change your image references in Dockerfiles (FROM lines), Kubernetes manifests, ECS task definitions and CI files to the ECR paths. That is the step that actually stops the Docker Hub rate limit, because nothing talks to Docker Hub directly any more.
There is no way around step 5 with ECR alone. A Docker registry mirror setting such as registry-mirrors expects the mirror to answer for Docker Hub's names at its root, while ECR's cached images live under your prefix, so the image names themselves have to change. For a large estate, do it with search and replace in your repositories plus a review, rather than hoping a node setting will redirect pulls quietly.
How to pull an image from ECR, cached or not
Pulling from ECR always starts with a login, because ECR is private. The login command exchanges your AWS credentials for a registry password that Docker or another client uses:
# Log in (the password is valid for 12 hours) aws ecr get-login-password --region us-east-1 | \ docker login --username AWS --password-stdin 111122223333.dkr.ecr.us-east-1.amazonaws.com # Pull a cached public image and one of your own docker pull 111122223333.dkr.ecr.us-east-1.amazonaws.com/docker-hub/library/python:3.13-slim docker pull 111122223333.dkr.ecr.us-east-1.amazonaws.com/shop/ticketing:2.4.1
Where the login happens matters more than the command:
- EKS nodes and ECS hosts log in to ECR automatically using the node role or task execution role; you never run the command there. What they need is the IAM permission, including the pull through cache actions for cached prefixes.
- CI jobs run the login at the start of each job, since the 12-hour password outlives no pipeline but also should not be stored. GitHub Actions has an official "Amazon ECR Login" action that does the same.
- Developer laptops can install the Amazon ECR credential helper, which logs in on demand from your AWS profile, so
docker pulljust works without the login step.
A pull that fails with "no basic auth credentials" or a 401 is a login problem; a pull that fails with "not authorized to perform" is an IAM problem; and a pull of a cached image that fails only the first time is a cache rule problem. Telling those three apart first saves most of the debugging.
Pushing your own images next to the cache
Most registries hold two kinds of repository side by side: cached copies of public images, and your own application images. Keep them clearly apart:
# Create a repository for your own app once aws ecr create-repository --repository-name shop/ticketing --image-scanning-configuration scanOnPush=true # Build on a cached base image, then push your image docker build -t 111122223333.dkr.ecr.us-east-1.amazonaws.com/shop/ticketing:2.4.1 . docker push 111122223333.dkr.ecr.us-east-1.amazonaws.com/shop/ticketing:2.4.1
A naming convention keeps everyone straight: cache prefixes named after the upstream (docker-hub/, k8s/, quay/), and your own images under a team or company prefix (shop/). Never push into a cache repository: it is not a supported pattern, and the next refresh can replace what you pushed with the upstream version. If you need a modified version of a public image, build it as your own image, with the cached one as its FROM, and push it under your own prefix.
Upstream registries and their image URIs
| Upstream | Upstream URL | Credentials | Example pull (prefix in bold) |
|---|---|---|---|
| Docker Hub | registry-1.docker.io | Secrets Manager | .../docker-hub/library/nginx:1.27 |
| Amazon ECR Public | public.ecr.aws | None | .../ecr-public/amazonlinux/amazonlinux:2023 |
| Kubernetes registry | registry.k8s.io | None | .../k8s/pause:3.9 |
| Quay | quay.io | None | .../quay/prometheus/prometheus:latest |
| GitHub Container Registry | ghcr.io | Secrets Manager (GitHub token) | .../ghcr/ORG/IMAGE:TAG |
| Azure Container Registry | NAME.azurecr.io | Secrets Manager | .../azure/IMAGE:TAG |
| GitLab Container Registry (GitLab.com only) | registry.gitlab.com | Secrets Manager | .../gitlab/GROUP/PROJECT/IMAGE:TAG |
| Chainguard Registry | cgr.dev | Secrets Manager | .../chainguard/IMAGE:TAG |
| Another Amazon ECR registry | ACCOUNT.dkr.ecr.REGION.amazonaws.com | IAM role (cross-account) | .../central/REPO:TAG |
"..." stands for ACCOUNT.dkr.ecr.REGION.amazonaws.com. The prefix is your choice; the names above are just a readable convention. Everything after the prefix is the path the image has upstream, which is why Docker Hub's official images need library/ in the middle.
Credentials for the upstreams that need them. Every authenticated upstream uses the same secret format, a JSON object with username and accessToken, under a name starting with ecr-pullthroughcache/. What goes into accessToken differs:
- Docker Hub: a personal access token with read-only scope, created in Docker Hub's account settings.
- GitHub Container Registry: a GitHub token that can read packages; with it, the cache can also pull private images your account or organization can see.
- GitLab: a token with registry read access; only GitLab.com is supported, not self-managed GitLab servers.
- Azure Container Registry: a token or service principal with pull rights on that registry.
Use a dedicated account or token for the cache rather than a person's own, so it survives staff changes, and give it read-only scope. When it expires or is rotated, update the secret's value and run validate-pull-through-cache-rule; nothing else needs to change.
Permissions: what the pulling identity needs
A normal pull needs the usual ECR read permissions. A pull through a cache rule needs two more, because the first pull creates a repository and imports the image:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PullThroughCache",
"Effect": "Allow",
"Action": [
"ecr:BatchImportUpstreamImage",
"ecr:CreateRepository",
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchCheckLayerAvailability"
],
"Resource": "arn:aws:ecr:us-east-1:111122223333:repository/docker-hub/*"
},
{
"Sid": "Login",
"Effect": "Allow",
"Action": "ecr:GetAuthorizationToken",
"Resource": "*"
}
]
}
ecr:BatchImportUpstreamImagelets the pull fetch from upstream into the cache; without it, a pull of an image not cached yet fails.ecr:CreateRepositoryis needed only when the repository does not exist yet. If you pre-create the repositories, you can leave it out.- ECR uses its own service-linked role, created automatically with the first rule, to read the Secrets Manager secret and push the cached image, so you do not grant secret access to your build or node roles.
- To give many identities these rights at once, a registry permissions policy on your private registry can allow them for the whole account or organization.
For CI systems, EKS nodes and ECS task execution roles, add these to whichever role does the pulling. AWS's read-only ECR managed policies were written for ordinary pulls, so check that the role you use includes the import action rather than assuming it.
Terraform
resource "aws_secretsmanager_secret" "dockerhub" {
name = "ecr-pullthroughcache/docker-hub"
}
resource "aws_secretsmanager_secret_version" "dockerhub" {
secret_id = aws_secretsmanager_secret.dockerhub.id
secret_string = jsonencode({ username = var.dockerhub_user, accessToken = var.dockerhub_token })
}
resource "aws_ecr_pull_through_cache_rule" "dockerhub" {
ecr_repository_prefix = "docker-hub"
upstream_registry_url = "registry-1.docker.io"
credential_arn = aws_secretsmanager_secret.dockerhub.arn
}
resource "aws_ecr_pull_through_cache_rule" "k8s" {
ecr_repository_prefix = "k8s"
upstream_registry_url = "registry.k8s.io"
}
The rule needs no explicit dependency on the secret version, but the secret must have a value before the first pull, so apply both together. Pass the Docker Hub token as a sensitive variable from your CI secrets rather than writing it into the code, and mark the variable sensitive = true so it stays out of plan output. To control the settings of repositories the cache creates (scanning, encryption with your KMS key, a lifecycle policy, tag mutability), add an aws_ecr_repository_creation_template whose prefix matches the rule's prefix.
resource "aws_ecr_repository_creation_template" "dockerhub" {
prefix = "docker-hub"
applied_for = ["PULL_THROUGH_CACHE"]
image_tag_mutability = "MUTABLE"
lifecycle_policy = jsonencode({
rules = [{
rulePriority = 1
description = "Expire cached images not pushed or refreshed in 90 days"
selection = { tagStatus = "any", countType = "sinceImagePushed", countUnit = "days", countNumber = 90 }
action = { type = "expire" }
}]
})
}
The applied_for list says which kind of repository creation the template covers; PULL_THROUGH_CACHE limits it to repositories the cache creates. Because templates apply only at creation, put the template in the same apply as the rule, before anything pulls through it, or the first cached repositories will be created without its settings.
Repository creation templates: lifecycle, scanning, encryption
Repositories created by the cache start with plain defaults: mutable tags, AES256 encryption, no repository policy, no lifecycle policy and no tags. A repository creation template with the same prefix lets you set these up front:
- A lifecycle policy, so cached images that nobody pulls any more expire instead of piling up; our guide to ECR lifecycle policies covers the rules.
- Encryption with your own KMS key, if your policies require it.
- A repository policy letting other accounts in your organization pull the cached images.
- Tags for cost allocation.
Templates apply only when a repository is created; existing cached repositories keep their settings. And leave tag immutability off for cache repositories: with immutable tags, ECR cannot update a cached tag such as latest when upstream changes it.
Scanning cached images for vulnerabilities
Public images carry public vulnerabilities, and caching them in your registry is a good moment to start scanning them. ECR offers two levels:
- Basic scanning checks operating system packages in an image for known vulnerabilities, on push or on demand, at no extra charge.
- Enhanced scanning, provided by Amazon Inspector, also checks programming language packages (such as Python, Node.js and Java libraries) and rescans images continuously as new vulnerabilities are published, billed per image scanned.
Scanning is configured for the whole registry with filters on repository names, so a filter such as docker-hub/* brings every cached repository under the same rules as your own images. With enhanced scanning, findings appear in Amazon Inspector and can raise alerts through EventBridge, which turns "is that old nginx image vulnerable?" into a dashboard instead of a guess.
A practical policy for a small team: enhanced scanning for the handful of base images every service builds on, basic scanning for everything else, and a monthly look at critical findings. When a cached base image has a critical vulnerability, the fix is usually a newer tag upstream: change your FROM line, rebuild, and the cache fetches the new tag on the next pull.
Tags, digests and reproducible builds
A tag such as nginx:1.27 is a label that upstream can move to a newer image at any time, and the cache follows it within a day. That is usually what you want for security fixes, but it means two builds a week apart may not use the same base image. Pinning by digest fixes the image exactly:
# Find the digest of what the cache holds for a tag aws ecr describe-images --repository-name docker-hub/library/nginx \ --image-ids imageTag=1.27 --query "imageDetails[].imageDigest" --output text # Reference the image by digest in a Dockerfile or manifest FROM 111122223333.dkr.ecr.us-east-1.amazonaws.com/docker-hub/library/nginx@sha256:DIGEST
A digest never changes meaning, so builds become reproducible, and the cache serves digest pulls like tag pulls. The trade-off is that security updates arrive only when you change the digest, so teams that pin by digest usually let a bot propose digest updates in pull requests. Avoid latest for anything you deploy: it combines the drawbacks of both, changing without notice while telling you nothing about which version you run.
Using it with EKS, ECS and CI
- EKS: change image references in your manifests or Helm values to the ECR paths, and give the node role (or the pod's role) the permissions above. Many Helm charts have an
image.registryorglobal.imageRegistryvalue that switches every image at once. If pods then fail with ImagePullBackOff, our EKS ImagePullBackOff guide walks through the checks. - ECS: use the ECR path in the task definition's
imageand add the permissions to the task execution role. Errors at task start show as CannotPullContainerError; our CannotPullContainerError guide covers them. - CI (CodeBuild, GitHub Actions on AWS, Jenkins on EC2): change
FROMlines in Dockerfiles to the ECR path and log in to ECR before the build. - Lambda: not supported. Lambda container images cannot be pulled through a cache rule; push them to an ordinary ECR repository.
Moving an existing EKS cluster onto the cache, in order:
- Create the rules for every upstream your cluster uses (Docker Hub,
registry.k8s.io, Quay, ECR Public), plus a creation template with a lifecycle policy. - List the images in use:
kubectl get pods -A -o jsonpath="{..image}"shows every image reference across namespaces. - Grant the node role (or the IRSA or Pod Identity role) the import and create permissions for the cache prefixes.
- Pull one image by hand through each rule from a machine in the VPC, to prove permissions and routing before anything depends on it.
- Change image references one workload at a time (manifests, Helm values, add-on settings) and watch the rollout; keep the old reference ready to switch back.
Private subnets. If your nodes reach ECR only through interface VPC endpoints (PrivateLink) with no internet route, the first pull of each image can fail, because ECR may need a route to the internet to fetch from upstream on your behalf. Give the VPC an internet path (a NAT gateway or public subnet route) for those first pulls; later pulls from the cache do not need it. Our VPC endpoint guide explains the endpoint setup itself.
Jake: "So after the first pull, the nodes never talk to Docker Hub again?"
Ethan: "Only ECR does, once a day per tag, with our login. That's what got us under the limit."
The images people forget: add-ons and Helm charts
After changing their own manifests, most teams still see Docker Hub pulls, because the images in third-party charts were never changed. A quick tour of where cluster images usually come from:
- EKS's own add-ons (VPC CNI, CoreDNS, kube-proxy, the EBS CSI driver) come from AWS-owned ECR registries, not Docker Hub, so they need no cache rule and should be left alone.
- Community charts often pull from
registry.k8s.io(ingress controllers, metrics-server),quay.io(Prometheus, cert-manager and many operators) andghcr.io, which is why a rule per upstream is worth creating on day one. - Sidecars and init containers hidden inside charts, such as a
busyboxinit step, are easy to miss because they never appear in your own YAML.
To find every image still pulled from outside, list them and filter out your ECR hostname:
kubectl get pods -A -o jsonpath="{..image}" | tr -s ' ' '\n' | sort -u | grep -v '.dkr.ecr.'
Whatever that prints is still coming from a public registry. For charts, look for an image.registry, image.repository or global.imageRegistry value; well-built charts let one value redirect every image they use to your cache prefix.
Checking the cache is really being used
Three checks confirm the switch worked:
- Cached repositories exist:
aws ecr describe-repositories --query "repositories[?starts_with(repositoryName, 'docker-hub/')].repositoryName"lists every image the cache has fetched so far. An empty list after a deployment means nothing is pulling through it yet. - Pulls come from ECR: on a node,
crictl images(or the pod'simagefield) shows ECR hostnames rather thandocker.io. - Docker Hub goes quiet: Docker Hub's usage page for the account whose token the cache uses shows a handful of pulls a day, one per refreshed tag, instead of hundreds.
Repeat the image listing from the previous section after every new chart or service goes in. Rate limit problems come back quietly when a new workload references Docker Hub directly, usually months later, usually on a busy day.
ECR to ECR: a central registry for many accounts
Pull through cache can also use another Amazon ECR private registry as the upstream, which suits organizations with a central "golden images" account. Each workload account creates a rule pointing at the central registry and pulls through its own prefix. When the two registries are in different accounts, you create an IAM role that ECR uses to read from the upstream registry, and the upstream repositories' policies must allow it. The cached copies then live in each workload account, so a workload keeps running even if the central account's repository is changed or unavailable for a while.
The alternative for the same goal is ECR replication, which pushes every new image from the central registry to the others automatically. Replication copies everything up front; pull through cache copies only what each account actually uses, on first pull.
Rolling the cache out across many accounts and Regions
Pull through cache rules and their secrets live in one account and one Region. For a company with a dozen accounts across two Regions, that is two dozen rules and, for Docker Hub, two dozen copies of a credential. Two patterns keep this manageable:
- Infrastructure as code everywhere. The same Terraform module or CloudFormation StackSet creates the rules, secrets and creation templates in every account and Region, with the Docker Hub token fed in from one secure source. Simple, but the credential exists in many places.
- A central cache, with ECR as the upstream. One shared-services account holds the Docker Hub rule and the only copy of the credential. Every other account creates a rule whose upstream is that central ECR registry. Docker Hub sees one account, and the credential never leaves the central account.
Either way, a registry permissions policy in each account can grant ecr:BatchImportUpstreamImage and ecr:CreateRepository on the cache prefixes to every role in the account at once, which saves editing dozens of node and CI roles. And keep the prefixes identical in every account, so the same manifest works anywhere once the account ID and Region in the hostname are filled in.
Multi-architecture images and Graviton nodes
Most popular public images are multi-architecture: one tag points to an index listing separate images for x86 (amd64) and Arm (arm64), among others. When a node pulls through the cache, it gets the variant for its own processor, so a cluster mixing Intel and Graviton nodes needs nothing special; the same image reference works on both.
Storage follows what has been pulled. If only x86 nodes ever pull an image, mostly x86 layers end up stored; once Graviton nodes pull it too, their layers are cached as well. That is worth knowing when estimating storage, and it is also a reason to move to Graviton deliberately: the first pulls of every image on the new nodes go upstream once, then come from the cache like any other.
ECR pull through cache vs Azure's artifact cache, Artifactory and Harbor
Every major registry has a version of this idea, and if you run more than one, it helps to know how they line up:
| Product | Feature name | Fits best when |
|---|---|---|
| Amazon ECR | Pull through cache rules | Workloads run on AWS and already use ECR and IAM |
| Azure Container Registry | Artifact cache (cache rules with credential sets) | Workloads run on Azure, with AKS |
| JFrog Artifactory | Remote Docker repositories | Many clouds and package types in one tool, already licensed |
| Harbor (open source) | Proxy cache projects | Self-hosted registries, including on-premises |
The concepts carry over directly: a rule or project that maps a local path to an upstream, stored upstream credentials, and image names that change to point at the cache. On AWS, ECR's advantages are that IAM roles already authenticate every node and task, nothing extra has to run, and the feature itself is free. Artifactory or Harbor make more sense when the same cache must serve several clouds and on-premises machines. Artifactory is not one of ECR's supported upstreams, so if your company publishes internal images there, pull those from Artifactory directly or replicate them into ECR.
Deleting rules, cached images and forcing a refresh
A few housekeeping tasks come up sooner or later:
- Deleting a rule (
aws ecr delete-pull-through-cache-rule --ecr-repository-prefix docker-hub) stops new caching for that prefix but leaves the cached repositories and images in place. Images already cached keep working until you delete those repositories too. - Forcing a refresh before the 24-hour check: delete the cached image (
aws ecr batch-delete-imagewith the tag) and pull again; the next pull fetches the current upstream version. - Deleting a cached repository entirely:
aws ecr delete-repository --repository-name docker-hub/library/nginx --force. The next pull through the rule recreates it from upstream. - Changing the credentials after a token rotation: update the Secrets Manager secret's value; the rule keeps pointing at the same secret, so nothing else changes. Run the validate command afterwards.
Deleted cached images are gone from your registry, so anything still running with them keeps its local copy, but a new node or task that needs the image pulls it fresh from upstream, through the rule, on its first start.
What pull through cache costs
- The feature: no charge.
- Storage: cached images are billed at normal ECR storage rates per GB-month. A lifecycle policy (through a creation template) keeps this small.
- Data transfer: the normal ECR rates; pulls within the same Region to AWS compute are typically free of transfer charges, and pulls through a NAT gateway add NAT processing charges.
- Secrets Manager: a small monthly charge per secret, one per authenticated upstream.
Against that, you save failed builds, Docker Hub paid plans bought only for rate limits, and NAT gateway data for repeated large pulls from the internet. For a cluster that pulls the same few base images hundreds of times a day, the cached copy is also faster: the image comes from ECR in your own Region instead of across the internet.
Jake: "So the cache costs us a few cents of storage a month?"
Ethan: "A few cents, against a broken pipeline every Monday. Easiest trade we've made."
What the cache changes for security
The cache stores the same image bits upstream published, byte for byte, so a cached image is exactly as trustworthy as the public one: no more, no less. What changes is where you can apply controls:
- One place to scan and expire. Every public image your company uses now sits in your registry, where scanning filters, lifecycle policies and audits apply to all of it.
- One place to say no. A Kubernetes admission policy (with Kyverno or OPA Gatekeeper, for example) can reject any pod whose image is not from your ECR hostname, which turns "please use the cache" into a rule the cluster enforces.
- Signatures still work. Image signatures are tied to the digest, which the cache preserves, so signature checks at deploy time keep working when you verify by digest.
- Control who adds upstreams. Creating a rule (
ecr:CreatePullThroughCacheRule) decides which public registries your company trusts, so keep that permission with the platform team rather than every developer.
What the cache does not do is make an image safe. A vulnerable or malicious public image is cached just as faithfully as a good one, which is why scanning cached prefixes matters as much as scanning your own builds.
Rollout checklist
- Create rules for every upstream you use: Docker Hub,
registry.k8s.io, Quay, ECR Public, GitHub. - Store Docker Hub and GitHub tokens as
ecr-pullthroughcache/secrets from a dedicated account, read-only. - Add creation templates with a lifecycle policy and mutable tags, before the first pull.
- Grant the import and create permissions to node, task and CI roles, or through a registry policy.
- Pull one image through each rule by hand, from inside the VPC.
- Change image references, starting with CI base images, then workloads, then charts.
- List remaining public images, turn on scanning for cache prefixes, and consider an admission policy.
Done in that order, nothing breaks along the way: the rules and permissions exist before any image reference changes, and every change can be rolled back by switching a reference back to its public name. Most small teams finish in an afternoon; the longest part is usually finding the image settings inside third-party charts.
Jake: "And if Docker Hub changes its limits again next year?"
Ethan: "Then it changes them for someone else. We pull from our own registry now."
ECR pull through cache not working: every error
| Symptom | Cause | Fix |
|---|---|---|
| "repository ... does not exist" on first pull | Prefix typed wrong, or the identity lacks ecr:CreateRepository / ecr:BatchImportUpstreamImage | Check the prefix against the rule; add both permissions |
| "not authorized to perform: ecr:BatchImportUpstreamImage" | The pulling role has only ordinary read permissions | Add the action for the prefix's repositories |
| Rule creation fails on the secret | Secret name lacks the ecr-pullthroughcache/ prefix, or is in another Region or account | Recreate the secret with the prefix, beside the rule |
| Validation fails, or pulls fail with an authentication error | Wrong username or token, or an expired token | Update the secret's value; run validate-pull-through-cache-rule |
| Docker Hub image "not found" via the cache | Missing library/ for official images | Use .../docker-hub/library/nginx |
| First pull times out in a private subnet | No internet route for the upstream fetch | Add a NAT route for first pulls |
| Cached tag never updates | Tag immutability on, or less than 24 hours since the last check | Turn immutability off; wait, or pull by digest |
| Pushed image not served | Pushing into a cache repository is not supported | Push to a normal repository; delete and re-pull to refresh |
| Lambda cannot use the image | Lambda does not support pull through cache | Push the image to an ordinary repository |
| Still hitting "toomanyrequests" | Some images still reference docker.io directly | Search manifests, charts and Dockerfiles for docker.io paths |
| "no basic auth credentials" or 401 from ECR | Not logged in to ECR, or an expired login | Run aws ecr get-login-password again (valid 12 hours) |
Two more things worth knowing: the first pull through a FIPS endpoint is not supported (later pulls are), and for upstreams without authentication, the first pull comes from AWS addresses, not yours. If an ECR login error persists, our guide to "authorization token has expired" covers ECR logins in CI.
Frequently asked questions
What is ECR pull through cache?
A feature that caches images from an upstream registry, such as Docker Hub or Quay, in your private Amazon ECR registry, fetched on first pull and refreshed at most once a day.
How do I use ECR pull through cache with Docker Hub?
Store a Docker Hub token in Secrets Manager under ecr-pullthroughcache/, create a rule with a prefix such as docker-hub, then pull ACCOUNT.dkr.ecr.REGION.amazonaws.com/docker-hub/library/IMAGE:TAG.
Does ECR pull through cache fix the Docker Hub rate limit?
Yes, once your images reference the ECR paths: only ECR contacts Docker Hub, authenticated, and only when refreshing a cached tag.
How often does ECR update cached images?
When an image is pulled, ECR checks upstream for a newer version of that tag if more than 24 hours have passed since the last check.
What permissions does pull through cache need?
The pulling identity needs ecr:BatchImportUpstreamImage and, for the first pull, ecr:CreateRepository, plus normal ECR pull permissions.
How much does ECR pull through cache cost?
The feature is free; you pay ECR storage for cached images, data transfer, and Secrets Manager for any stored credentials.
Which registries does ECR pull through cache support?
ECR Public, the Kubernetes registry, Quay, Docker Hub, GitHub Container Registry, Azure Container Registry, GitLab.com, Chainguard and other ECR registries.
What must the Secrets Manager secret be named?
Its name must start with ecr-pullthroughcache/ and it must be in the same account and Region as the rule.
Can I use ECR pull through cache with Lambda?
No. Lambda does not support pulling images through a cache rule; use an ordinary ECR repository.
Can I use pull through cache across AWS accounts?
Yes. A rule can use another ECR registry as upstream, with an IAM role when the registries are in different accounts.
How do I set up ECR pull through cache in Terraform?
Use aws_ecr_pull_through_cache_rule with ecr_repository_prefix, upstream_registry_url and, for authenticated upstreams, credential_arn.
Why does the first pull fail in a private subnet?
The first fetch from upstream may need an internet route; add a NAT path for first pulls even if you use ECR VPC endpoints.
Can I push images into a pull through cache repository?
It is not a supported pattern and can serve stale images; push to a normal repository instead.
What happens if Docker Hub is down?
ECR serves the last cached copy of the image, so pulls of cached tags keep working.
How do I control lifecycle and encryption of cached repositories?
Create a repository creation template with the same prefix, setting lifecycle policy, encryption, scanning and tags.
What is the image path for official Docker Hub images?
Add library/, for example ACCOUNT.dkr.ecr.REGION.amazonaws.com/docker-hub/library/nginx:1.27.
How do I pull an image from ECR?
Log in with aws ecr get-login-password piped to docker login, then docker pull ACCOUNT.dkr.ecr.REGION.amazonaws.com/REPO:TAG. EKS and ECS log in automatically.
How do I push an image to ECR?
Create the repository, tag the image with the ECR path, log in, and docker push. Use your own prefix, never a cache prefix.
Can ECR act as a Docker Hub registry mirror?
Not transparently. Cached images live under your prefix, so image names must change to the ECR paths.
Are cached images scanned for vulnerabilities?
If your registry scanning filters include the cache prefixes, yes: basic scanning for OS packages, or enhanced scanning with Amazon Inspector.
How do I force ECR to refresh a cached image?
Delete the cached image with batch-delete-image and pull again; the next pull fetches the current upstream version.
Does deleting a pull through cache rule delete the cached images?
No. The cached repositories and images stay until you delete them separately.
What is the Azure equivalent of ECR pull through cache?
Azure Container Registry's artifact cache, which uses cache rules and credential sets in the same way.
Does the ECR cache make public images safe?
No. It stores the same bytes upstream published. Scan cached prefixes and verify signatures by digest as you would for any image.
How do I force everyone to use the ECR cache?
Use a Kubernetes admission policy that rejects images not from your ECR hostname, and keep rule creation with the platform team.
Do EKS add-ons like CoreDNS need a pull through cache rule?
No. EKS add-ons pull from AWS-owned ECR registries. Community charts using registry.k8s.io, quay.io or Docker Hub do.
How do I find images still pulled from Docker Hub in my cluster?
List every pod image with kubectl get pods -A -o jsonpath="{..image}" and filter out your .dkr.ecr. hostname.
Why do AWS workloads hit Docker Hub rate limits so fast?
Nodes behind one NAT gateway share an IP address, and new nodes and CI jobs pull everything fresh, so many pulls land in a short window.
How do I cache private GitHub Container Registry images in ECR?
Store a GitHub token that can read packages in Secrets Manager as ecr-pullthroughcache/NAME, then create a ghcr.io rule with it.
Do I need a pull through cache rule in every Region?
Yes. Rules, secrets and cached images are per account and per Region; use infrastructure as code or a central ECR upstream.
Does pull through cache work with Graviton nodes?
Yes. Multi-architecture images are served per node, so arm64 and amd64 nodes pull their own variant through the same path.
Should I pin cached images by digest?
For reproducible builds, yes: reference image@sha256:DIGEST. Tags follow upstream changes within a day.
Is ECR pull through cache the same as ECR replication?
No. Replication copies every new image to other registries; pull through cache copies only the images each registry actually pulls.
For readers preparing for an AWS certification
We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.
Exams that test this topic: Developer – Associate (DVA-C03 from December 1, 2026) • CloudOps Engineer – Associate (SOA-C03) • Solutions Architect – Associate (SAA-C03).
Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:
1. Builds and EKS nodes hit Docker Hub pull rate limits. Which ECR feature caches public images in your own registry?
ECR pull through cache rules.
2. Where must Docker Hub credentials for an ECR pull through cache rule be stored?
In AWS Secrets Manager, in a secret whose name starts with ecr-pullthroughcache/.
3. Which IAM action lets a pull import an image from the upstream registry into the cache?
ecr:BatchImportUpstreamImage (plus ecr:CreateRepository for the first pull).
4. Which compute service cannot pull container images through an ECR pull through cache rule?
AWS Lambda.
5. How can you set lifecycle policies and encryption on repositories that pull through cache creates automatically?
With a repository creation template matching the rule's prefix.
6. What is the difference between ECR replication and pull through cache?
Replication copies every new image to other registries; pull through cache copies only images that are pulled.
7. Which AWS service stores secrets such as registry credentials and rotates them?
AWS Secrets Manager.
Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.
A month later, the shop's builds have not seen a single Docker Hub rate limit. The cluster's images all come from docker-hub/, k8s/ and ecr-public/ prefixes in the shop's own registry, a creation template expires cached images nobody has pulled in 90 days, and the Docker Hub token sits in Secrets Manager where only ECR reads it. Jake's verdict: "We stopped borrowing from the library every five minutes and started keeping our own copies."
📌 If you keep one line from this page
Store upstream credentials as ecr-pullthroughcache/NAME in Secrets Manager, create a pull through cache rule with a prefix, point every image at ACCOUNT.dkr.ecr.REGION.amazonaws.com/PREFIX/..., and give the pulling role ecr:BatchImportUpstreamImage and ecr:CreateRepository.
Free feature · refresh at most daily · library/ for official images · not for Lambda · first pull needs internet.
Revision note. Written October 19, 2026. A rate limit from a public registry is usually a sign you need your own copy; pull through cache makes that copy for you.