
Running AWS Blocks on ECS Fargate and EKS Auto Mode: One Line of CDK for Container Compute
How I contributed load-balanced container support to an open-source AWS backend framework, the shared IAM role design, ALB + CloudFront front doors, and a CloudFormation dynamic-reference bug found on a live cluster.
Last week at AWS User Group Madurai , we opened DevTools Month of our Builders Skill Sprint with a deep dive into AWS Blocks ( session recording ). The demos landed well. Then a hand went up at the back, and the same question returned in three different forms before the session ended:
"This is great , but our workloads run on EKS. Can Blocks do that?"
It couldn't. So I spent the sprint building the answer, and it's now open for review upstream. This is the story of what AWS Blocks is, why its single compute shape became a real limit, and how I extended it, including the three bugs that only real AWS deployments could surface.
📦 The contribution, at a glance
| | Status |
|---|---|---|
| RFC #156 | Container compute targets — design + open questions | 🟢 Open for discussion |
| PR #157 | feat(core) : the compute-target seam + container HTTP server | 👀 Awaiting review |
| PR #158 | feat(compute-ecs) : ECS Fargate behind ALB + CloudFront | 👀 Awaiting review |
| PR #159 | feat(compute-eks) : EKS Auto Mode behind ALB ingress + CloudFront | 👀 Awaiting review |
+4,571 / −109 across 73 files · 22 new CDK tests + an HTTP parity suite · full CI gate suite green · both targets deployed and verified on real AWS · three production bugs found, fixed, and pinned by regression tests · clean teardowns.
First: what is AWS Blocks?
AWS Blocks attacks the slowest part of cloud development, the loop itself. Traditionally, every iteration means provisioning real resources, wiring IAM by hand, and watching a bill grow while you wait on deploys. Blocks inverts that: you declare capabilities in TypeScript, and each "Building Block" carries multiple implementations behind one class name, selected automatically by execution context:
new KVStore(scope, 'todos')
│
┌────────────────────────────────┼────────────────────────────────┐
▼ ▼ ▼
npm run dev cdk deploy in production
in-memory store DynamoDB table real SDK calls
($0, offline) + IAM, inferred (creds injected)Write the line once; it's a mock on your laptop, a CloudFormation resource at deploy, and live SDK calls at runtime. Databases, auth, queues, cron, file storage, realtime: nineteen blocks, one mental model, no infrastructure rewritten between "works on my machine" and "works in production."
The wall: one compute shape
For all that flexibility on the resource side, the compute side had exactly one answer:
every Blocks app ──▶ one Lambda ──▶ API Gateway
│
29-second request ceiling · 15-minute job ceiling · per-request pricingThat ceiling used to be a niche complaint. AI workloads made it mainstream. The apps our community is building right now, agent backends, RAG APIs, streaming chat: hold HTTP connections open for 30, 60, 90 seconds while an LLM thinks and tokens stream back. API Gateway hangs up at 29 seconds, no exceptions. And an always-on inference gateway at sustained load inverts Lambda's economics: per-request pricing that was a bargain at spiky traffic becomes the expensive option at steady RPS. Add the third force, organizations that have already standardized their platform on EKS and "Lambda-only" quietly means "not for us."
The idea, then, almost stated itself during that sprint session: Blocks already proves the same code can move between a laptop and Lambda. Could the same promise stretch to where the code runs?
the goal: laptop ──▶ Lambda ──▶ Fargate ──▶ EKS
same code · same blocks · same one-line ergonomicsThe constraint that shaped the design
Every Building Block attaches its IAM grants, environment variables, and event sources to the Lambda. Nineteen first-party blocks, plus third-party ones. Teaching each of them about containers would be API sprawl of the worst kind, so the design constraint became non-negotiable: zero changes to application code, zero changes to any block. Four decisions made it hold:
1. The companion-Lambda model. Containers don't replace the Lambda, they take over HTTP, while the Lambda keeps the event sources it is genuinely better at:
┌── HTTP (RPC + raw routes) ──▶ Fargate tasks / EKS pods
one esbuild bundle ──────┤ (ALB + CloudFront, autoscaled)
(same code, built once) │
└── events ──────────────────▶ companion Lambda (idle = $0)
SQS jobs · cron · WebSockets · DB migrationsOne bundle, two doors. No second codepath to drift, and you keep the batching, retries, and DLQ wiring Lambda event source mappings provide for free.
2. One shared execution role. Core builds a single IAM role trusted by
lambda.amazonaws.com , ecs-tasks.amazonaws.com , and pods.eks.amazonaws.com (with sts:TagSession for Pod Identity) and hands it to all three compute identities. Every grant*() a block already makes lands everywhere, automatically: KVStore.grant() ──┐
Database.grant() ─┼──▶ one shared role ──▶ Lambda ✓ Fargate task ✓ EKS pod ✓
FileBucket.grant()┘The role only exists when you opt in, without
compute , the synthesized template is byte-identical, and a template-stability test pins that promise forever.3. Reuse the dispatch, don't rewrite it. The new container entrypoint translates HTTP requests into API-Gateway-shaped events and feeds the framework's existing handler, RPC envelopes, cookies, CORS, and timeout semantics stay identical by construction. It adds only what containers genuinely need: readiness gating, SIGTERM draining, ALB-safe keep-alive timeouts.
4. CloudFront as the front door. ECS runs an internal ALB behind a CloudFront VPC origin; EKS uses Auto Mode's built-in ingress ALB, gated so only CloudFront can reach it. Either way, HTTPS, secure cookies, and OIDC redirects work with zero certificate setup.
The migration a user performs, in full:
const stack = await BlocksStack.create(app, name, {
backendHandlerPath,
backendCDKPath,
compute: new EksCompute(), // or new EcsFargateCompute()
});npm run dev is untouched, no Docker, no cluster, no bill. The compute target exists only in the CDK layer.
What only real AWS could teach
All 158 unit tests were green before the first live deploy. AWS still had three lessons waiting, each one diagnosed on a real system, fixed in code, and pinned by a test.
CloudFront VPC origins are picky about subnets and don't SNAT. Healthy ECS tasks, 504 through CloudFront, ALB request count: zero. The ALB had to move to private subnets, and VPC flow logs revealed the deeper surprise: VPC-origin traffic arrives carrying CloudFront's public origin-facing IPs, so a VPC-CIDR security group rule silently rejects every packet. The fix admits the
com.amazonaws.global.cloudfront.origin-facing managed prefix list, resolved at deploy time to keep stacks region-agnostic.Dynamic references don't resolve inside custom resource properties. The EKS ingress requires an
X-Origin-Verify header only CloudFront sends, and I referenced the secret the idiomatic way {{resolve:secretsmanager:...}} . Every deploy timed out waiting for the ingress hostname; every rollback destroyed the evidence. A --no-rollback deploy plus a live kubectl describe ingress finally produced the confession:Warning FailedDeployModel ingress ... ValidationError: Condition value for
'http-header' cannot contain more than 128 charactersKubernetes manifests in CDK are applied by a custom resource and CloudFormation doesn't substitute dynamic references there. My placeholder had gone to the cluster as a literal 150-character string, and the ALB controller rejected it on every reconcile, forever. The fix reads the secret at deploy time via
AwsCustomResource and feeds the ingress annotation and the CloudFront header from that single source, so they can never drift. A regression test now asserts no rendered manifest contains {{resolve: .The closing proof was deliberately boring: a fresh, zero-touch
sandbox:deploy of the EKS smoke app. CREATE_COMPLETE with no intervention. All five request round-trips through CloudFront, including an async job enqueued in a pod and consumed by the companion Lambda. The security gate verified directly against the live ALB: no header, 404; with the header, 200. Then a clean teardown.Try it, review it
gh pr checkout 159 --repo aws-devtools-labs/aws-blocks # full series
npm install && npm run build
npm test -w @aws-blocks/compute-eks # 8/8, offline, $0
cd test-apps/compute-eks-smoke && npm run devThe RFC carries the full design, including the rejected alternatives and each package ships a DESIGN.md. Hard questions and review comments are exactly what the PRs are open for.
Sprint with us
This build is my entry in AWS UG Madurai's Builders Skill Sprint DevTools Month: learn a tool, build something real, write it up. If that loop sounds like your kind of fun, join us . Checkpoint 1 on AWS Blocks is on YouTube , and the next checkpoint is coming.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article