Back to Terraform

Containers on AWS: ECR, ECS and EKS Ownership Boundaries

November 6, 2026 Wasil Zafar 17 min read

Provision managed container infrastructure without mixing cluster creation and workload reconciliation

Table of Contents

  1. Choose ECS or EKS by the Operating Model
  2. Publish Immutable Images to an Explicit Registry Owner
  3. Model ECS Task Roles or EKS Node and Workload Roles
  4. Split EKS Infrastructure from Kubernetes Provider Operations
  5. Verify a Minimal Container Service and Cleanup Order

Choose ECS or EKS by the Operating Model

The orchestrator is the API your team agrees to operate. ECS exposes an AWS service API; EKS exposes the Kubernetes API, and with it every controller, add-on and version skew that API implies. The image can be identical, so choose the control plane you are willing to own.

ECS stops at the service. A task definition is a versioned contract, a service holds a desired count and replaces failed tasks, and Fargate removes the host entirely. Nobody on the application team needs to know about kubelets, admission controllers or CNI upgrades.

EKS hands you a cluster and asks what you will run on it. The control plane is managed, but nodes, add-ons, ingress, policy and tenant isolation are yours or your platform team's. Every capability past "run this image" becomes a component to install and later upgrade.

Ownership decides more than features. If a platform team already runs clusters, EKS lets application teams ship into a governed namespace. If no such team exists, ECS keeps the operating surface small enough for one team to own end to end.

Networking is shared, not orchestrator-specific. Both place workloads in your VPC: ECS with awsvpc gives each task its own ENI, and the EKS VPC CNI gives each pod a subnet address. Subnet size, endpoint access and security groups are prerequisites either way.

Choose by the failure you can staff. A failed ECS rollout is usually a task that cannot pull an image or reach a dependency; a failed EKS upgrade is usually version skew across control plane, nodes and add-ons. Pick the failure your on-call rotation can diagnose at 3 a.m.

Choose ECS or EKS by the Operating Model
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    T["Container image
already built"] --> Q1{"Who debugs
the scheduler?"} Q1 -->|"the application team"| ECS["ECS cluster
AWS API only"] Q1 -->|"a platform team"| EKS["EKS cluster
Kubernetes API"] ECS --> Q2{"Patch container
hosts yourself?"} Q2 -->|"no"| FAR["Fargate
one task ENI each"] Q2 -->|"yes"| EC2["EC2 capacity
ASG and drain"] EKS --> Q3{"Many teams in
one cluster?"} Q3 -->|"yes"| NG["Managed node group
RBAC and policy"] Q3 -->|"not yet"| FARG["Fargate profile
namespace selector"] EKS -.->|"no owner for
add-on upgrades"| DRIFT["Version skew
plane, nodes, CNI"] ECS -.->|"no owner for
subnet capacity"| ENI["Tasks pending
addresses exhausted"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class T,Q1 primary; class ECS,EKS secondary; class FAR,EC2,NG,FARG ok; class Q2,Q3 warn; class DRIFT,ENI danger;
ECS and EKS share a registry and a network but expose different control surfaces Two panels compare the operating model. ECS exposes a service and a task definition over an AWS API, with Fargate or EC2 capacity. EKS exposes a control plane, node groups and pods over the Kubernetes API. Both pull the same immutable image digest from one registry owner and both depend on the same VPC subnets, endpoints and security groups. One artifact, one network, two control surfaces The choice changes who operates the scheduler, not what the image contains. ECS: the service owns rollout AWS API, no cluster API to operate service desired count, health checks, replacement task definition image digest, cpu, task and execution roles capacity: Fargate, or EC2 instances you patch EKS: a platform owns the API Kubernetes objects, add-ons, upgrades control plane managed API server and etcd nodes or Fargate profiles AMI, drain, CNI and add-ons namespaces, deployments, admission policy ECR: one registry owner, immutable tags, deploy by digest both orchestrators pull the same artifact, and neither builds it in the deploy root Shared foundation: VPC subnets, route tables, endpoints, security groups Address space and endpoint reachability constrain both choices, and no cluster root owns them.
DimensionECS on FargateECS on EC2EKS managed node group
Unit of ownershipservice and task definitionservice plus container instancescluster, node group and workload objects
Host patchingAWSyou, through the AMIyou, through the node group release
Network attachmentone ENI per taskone ENI per taskone address per pod through the CNI
Control APIECS APIECS APIKubernetes API
Failure you owntask cannot pull or reach a dependencyinstance drain and capacity headroomcontrol plane, node and add-on version skew
Team neededapplication teamapplication team with capacity skillsplatform team for the cluster

The table is a responsibility map, not a feature list. Whichever row names your team is the row you must be able to debug at 3 a.m. That is the honest basis for the choice.

Publish Immutable Images to an Explicit Registry Owner

A tag is a pointer; a digest is the artifact. Tags are convenient for humans and mutable by default, so two builds can share one name. The digest identifies exact bytes, and a deployment that names the digest cannot be changed by a later push.

Immutability makes the tag honest. A repository configured with IMMUTABLE tags rejects a second push under an existing tag, so a release identifier cannot silently change content. A rollback then names a digest that still means what it meant when it was tested.

One registry owner, many consumers. Publish from a central account and let workload accounts pull through a repository policy, plus a KMS grant when the repository uses a customer-managed key. Replication is for latency and regional isolation, not for transferring ownership.

Scanning is a gate, not a dashboard. scan_on_push attaches findings to an image, but nothing blocks on them by itself. Put the check in the promotion job so a critical finding quarantines the digest before a service references it.

Retention must not delete what runs. A rule that expires untagged images is safe; a rule that keeps only the last few tagged images can remove a digest a rollback still needs. Size the count against the rollback window, not against storage cost.

Registry settings belong to the registry root. Repository, policy, lifecycle and replication change on a different schedule from the service, so keep them in their own state. Terraform 1.17.1 and hashicorp/aws 6.72.0 are the versions this article was checked against; pin both rather than floating a range.

Publish Immutable Images to an Explicit Registry Owner
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    SRC["Commit and lockfile"] --> BUILD["CI build
one platform target"] BUILD --> PUSH["Push release tag"] PUSH --> IMM{"Tag already
exists?"} IMM -->|"yes"| REJ["Push rejected
immutable tag"] IMM -->|"no"| DIG["Digest recorded
sha256 of the image"] DIG --> SCAN["Scan on push
findings attached"] SCAN --> GATE{"Critical finding
at promotion?"} GATE -->|"yes"| BLOCK["Digest quarantined
release not promoted"] GATE -->|"no"| PROMOTE["Deploy by digest
ECS image or pod spec"] PROMOTE --> RUN["Running task or pod"] RUN -.->|"lifecycle expired
the digest"| PULL["Next replacement
cannot pull"] PROMOTE -.->|"consumer account
absent from policy"| DENY["Pull denied
at start"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class SRC,DIG primary; class BUILD,PUSH,SCAN secondary; class IMM,GATE,PROMOTE,RUN ok; class REJ,BLOCK,PULL,DENY danger;

Deploy the digest, keep the tag as a label. The service or pod spec references the digest; the tag survives in release notes, image metadata and dashboards. When the two disagree, the digest is the truth.

The registry policy is a security boundary. A wildcard principal in a repository policy lets any account that guesses the repository name pull the image. Name the consuming accounts and roles, and review that statement like any other cross-account grant.

Model ECS Task Roles or EKS Node and Workload Roles

Three identities do three different jobs. One deploys, one runs the platform agent, and one is the application. Collapsing them is how a container ends up with permission to change the cluster that runs it.

The ECS execution role belongs to the agent. ECS assumes it to pull from ECR, write logs and resolve secrets before the container starts. It is trusted by the ECS tasks service and should hold nothing that the application itself needs at runtime.

The ECS task role belongs to your code. SDK calls inside the container use it, so scope it to the bucket, table or queue the process actually touches. An empty task role is a valid and honest starting point.

The EKS cluster role is only for the control plane. EKS assumes it to manage the API server's AWS dependencies; it is neither a node identity nor a workload identity. Granting application permissions there spreads them across every pod in the cluster.

The node role is shared by every pod on the host. It supplies the instance profile, the CNI policy and registry read access, and anything reachable through instance metadata is reachable from an unblocked pod. Never park application permissions on the node role.

Workload identity is per service account. IRSA trusts a scoped OIDC subject, while EKS Pod Identity maps a service account through an association. Pick one mechanism per cluster, because debugging two credential paths at once is its own incident.

Deployment rights are Kubernetes rights. The CI role needs an access entry and RBAC that can change the objects it owns, not cluster-admin. That grant is separate from the workload role and deserves its own review.

Split EKS Infrastructure from Kubernetes Provider Operations

The Kubernetes provider is a client, not a resource. It opens a connection while Terraform builds the plan, before dependency ordering applies. A cluster that does not exist yet is not pending; it is unreachable.

Split infrastructure from workload. One root owns the VPC attachments, cluster, OIDC provider, node groups or Fargate profiles, and add-ons. A second root owns the provider block and the Kubernetes objects, and reads the cluster name, endpoint and certificate from published outputs.

Reachability is a design input. A private-only endpoint means the runner must sit in the VPC or behind a connection to it; a public endpoint with an allowlist means the runner's egress address must be listed. A laptop plan against a private endpoint fails at provider configuration, before a single diff.

Authenticate with a short-lived exec credential. The exec block calls aws eks get-token, so no token is stored in state. The older cluster auth data source returns a token that expires mid-apply and is stored in state; avoid it for anything long-running.

Wait for readiness the API can observe. Cluster status, node group status and Ready nodes, CoreDNS running, and CRDs installed by an add-on before a manifest uses them. Terraform orders only what it creates, and a plan-time data source reads yesterday's state.

Same-root plans fail in a specific way. Provider configuration is evaluated before the graph, so a namespace that depends on the cluster does not make the provider wait. That sentence is the whole reason for the split.

Infrastructure and workload roots separated by the Kubernetes API connection The infrastructure root creates the network, the EKS cluster, its node group and add-ons, and the identity plumbing, then publishes the endpoint and certificate. The workload root configures the Kubernetes provider with those outputs and a short-lived exec token, then creates the namespace, service account, deployment and service. A red gate marks where an unreachable endpoint stops the plan, and the bottom strip explains that provider configuration runs before the resource graph. Two roots, one API connection between them The cluster must exist and be reachable before the workload root is worth planning. 1 Infrastructure root Applied with the AWS provider only network and subnets consumed from the VPC root EKS cluster endpoint, certificate, OIDC issuer node group and add-ons ready before a pod can schedule access entry for the deploy role authentication, then authorization 2 Workload root Applied with the Kubernetes provider kubernetes provider endpoint, certificate, exec token namespace and service account the scope a workload identity binds to deployment and service reconciled by the API server plan gate unreachable endpoint stops here outputs The provider connects before the graph runs A same-root depends_on cannot make the client wait. Apply the infrastructure root, publish its outputs, then plan the workload root.

Publish only what the workload root needs. Cluster name, endpoint, certificate authority and the identity mechanism are enough; a node group ARN in the workload root invites it to manage infrastructure by accident.

The split is also an access boundary. The infrastructure pipeline can hold cluster-administration rights, while the workload pipeline holds only the namespace rights it needs. A single root forces both pipelines to share one role.

Verify a Minimal Container Service and Cleanup Order

Verify one service, not the platform. One image, one task or pod, one log group and no load balancer tests registry pull, identity, subnet routing and log delivery without creating objects that outlive the test.

Pick a path and finish it. The ECS path is a cluster, a task definition and a service with a desired count of one. The EKS path is a namespace, a deployment and a ClusterIP service. Building both in one lab doubles the cleanup and halves the evidence.

Lab

Verify a Minimal Container Service and Cleanup Order

Execution status: design-only. These steps are a lab plan; no live account output is recorded here, and identifiers are written as tokens rather than real values.

Prerequisites. Terraform 1.17.1, AWS provider 6.72.0, one sandbox account, private subnets with ECR, S3, logs and STS endpoints, permission to push one image and read task or pod logs. Choose the ECS path or the EKS path; do not build both.

ObjectOwnerProof it exists
image digestregistry rootthe digest in the release note matches the service or pod spec
execution identityplatform rootthe task starts, or the pod pulls, without a credential error
application identityworkload rootone allowed API call succeeds and a second, unrelated call is denied
log groupplatform or workload rootexactly one group exists, with the retention you set
  1. Create the repository with immutable tags and scan on push, push one image, and record the digest. Confirm the plan changes no repository setting when the service is planned.
  2. Apply the infrastructure root. Read back the cluster status, the endpoint and the certificate, and confirm the deploy role's access entry exists before any Kubernetes object is planned.
  3. Apply the workload root, or the ECS service, with a desired count of one and no load balancer. Expect the task or pod to reach a running state and one log line to appear.
  4. Call one permitted API from inside the container and one unrelated API. Expect the first to succeed and the second to fail with an authorization error, proving the runtime identity is the one you granted.
  5. Break the pull path by removing the registry read permission in a branch. Expect the task or pod to fail before the application starts, with an image pull error and no application log line.
  6. Restore the permission and confirm recovery. Then change the image reference to a digest that no longer exists and confirm the failure is the same shape, not a crash loop inside the application.
  7. Destroy the workload root first. Confirm the namespace, deployment and service are gone and that no load balancer remains in the account.
  8. Destroy the infrastructure root, then audit for load balancers, EBS volumes, ENIs and log groups tagged to the lab. Delete the repository and its images explicitly.

Expected observation. Each step changes one boundary: the identity test changes the application's permissions without touching the image, the pull test changes registry access without touching the runtime identity, and the workload destroy removes Kubernetes objects before the cluster that hosts them.

Failure checks. The lab fails if the application can call an API the task role or workload role does not grant, if a load balancer survives the workload destroy, if the cluster destroy leaves ENIs or volumes behind, or if a second log group appears with no retention.

Cleanup order. Workload objects first, then confirm that no Service of type LoadBalancer remains, then add-ons and node groups, then the cluster, then registry images and repository, then log groups. Check the load balancer, volume and network-interface consoles after each stage rather than only at the end.

Evidence to keep. The image digest, the identity ARN or service account, one permitted and one denied API result, the pull failure message, and the cleanup audit with the time each residual object disappeared.

Cleanup follows the dependencies you created. A cluster destroyed while a Service still exists can strand the load balancer that Service created, and a retained claim can strand its volume. Audit load balancers, volumes, network interfaces and log groups by tag and by account, not by memory.

Next in the Series

In AWS Edge Delivery: Route 53, CloudFront, ACM and Cloudflare Boundaries, we'll explore Coordinate DNS, certificates, CDN and origin protection without assigning two tools the same surface.