
Running a Bedrock vision app on Amazon EKS with Karpenter
A proof of concept where the app is trivial and the platform is the point: EKS across two AZs, IRSA-scoped Bedrock access, Karpenter autoscaling, and cost caps.
The app is not the point
I built an image recognition web application. You upload a photo, it returns ranked labels with confidence scores. That is the entire product surface, and it is deliberately unremarkable.
The reason is that most AI demonstrations spend all their design effort on the model call and almost none on what surrounds it. The result looks impressive for ten minutes and then raises every question it avoided: what happens when traffic arrives, which identity is allowed to invoke the model, where does the cost come from, and how would anyone know if something went wrong.
I wanted to answer those questions on a project where the answers did not matter yet. So the application stayed trivial and the platform underneath it got the attention. This article walks through that platform, the decisions inside it, and the parts that turned out differently from what I expected.
What runs where
The workload is two services. A React frontend built with Vite and served by nginx, and a FastAPI inference service in Python. Both run as pods on Amazon EKS, spread across two Availability Zones.
Traffic arrives through Route 53 and an Application Load Balancer. The ALB is provisioned by the AWS Load Balancer Controller from a standard Kubernetes Ingress resource, which means the load balancer is described in the same manifests as the rest of the application rather than configured separately.
Both sets of pods sit in private subnets. Nothing that runs my code is directly reachable from the internet. The load balancer is the only public entry point, and outbound calls leave through NAT Gateways, one per Availability Zone.
The frontend's nginx configuration does two useful things. It serves the single page application with a fallback so client-side routes resolve correctly, and it proxies
/api to the backend's ClusterIP service. That keeps the browser talking to one origin and means the backend never needs to be publicly exposed.Calling Bedrock without credentials
The inference service sends the uploaded image to an Amazon Bedrock vision model and asks for labels as a JSON array.
The part worth dwelling on is authentication. There are no AWS access keys in the container, in an environment variable, or in a Kubernetes secret. The backend pods use IAM Roles for Service Accounts. The pod's service account is annotated with an IAM role ARN, the cluster's OIDC provider vouches for that pod's identity, and AWS issues short-lived credentials automatically.
The role itself permits one action,
bedrock:InvokeModel , scoped to the model in use. That constraint is the interesting bit. If someone obtained a shell inside that container, the full extent of what they could do with AWS is describe pictures. They cannot read a bucket, launch an instance, or enumerate the account.This is least privilege, which everyone agrees with in principle and frequently skips in practice because it is more work than a wildcard policy. Doing it on a low-stakes project was the cheapest possible way to build the habit.
A practical note on parsing. Asking a language model for JSON and getting JSON are different things, so the backend extracts the array between the first
[ and last ] , parses defensively, clamps confidence values into the zero to one range, and returns a clean error if the output is unusable. Treat model output as untrusted input, because that is what it is.Autoscaling with a ceiling
I replaced the default Cluster Autoscaler with Karpenter.
The difference in model matters. Cluster Autoscaler adds nodes to a node group you have already defined, so you have pre-decided the instance type. Karpenter looks at the pods that cannot be scheduled, works out what would actually fit, and provisions that. When demand drops, it consolidates workloads and removes nodes it no longer needs.
The configuration detail I would not skip is the CPU limit on the NodePool. Karpenter will happily keep provisioning to satisfy pending pods, which is exactly what you asked it for. A misconfigured deployment requesting more replicas than you intended becomes an open tab against your account. A limit turns "scale as needed" into "scale as needed, up to here," and the ceiling is the difference between elasticity and an incident.
One dashboard for three concerns
Three things report into a single Grafana view.
Performance comes from Prometheus: request latency, error rate, pod restarts, node pressure, and inference latency tracked separately so a slow model does not get diagnosed as a slow application.
Security comes from Amazon GuardDuty with EKS Protection enabled, which monitors control plane audit logs and runtime behaviour on the nodes.
Cost comes from Cost Explorer and the Cost and Usage Report, broken down per namespace.
Combining them was intentional. In most organisations these are three products owned by three teams, and the relationships between them are invisible as a result. A latency spike that coincides exactly with a cost spike is a much easier conversation than either signal alone. Putting them on one timeline makes those correlations obvious rather than archaeological.
Where the money actually goes
The cost distribution surprised me, and it is the finding I would most want another builder to take away.
Inference was not the expensive part. The recurring charges that dominate are the EKS control plane at a flat hourly rate, the worker nodes, the NAT Gateways, and the load balancer. Those bill whether or not a single request arrives. Leaving a modest two-node cluster running around the clock costs substantially more per month than a meaningful volume of vision inference.
That reframed the problem. Controlling token spend is largely a configuration exercise:
- A hard
max_tokenscap on every request, so no single call can produce a long expensive response. Classification needs a short JSON array, so the ceiling can be low.
- A maximum upload size, rejected before the image ever reaches the model. Input tokens are frequently the larger half of a bill, and an image is a lot of input.
- Token counts logged per request from the Bedrock response, so spend can be attributed to a feature instead of estimated.
Controlling infrastructure spend is an architecture exercise: how many NAT Gateways you actually need, whether nodes should exist overnight, and whether the cluster should be running at all when nobody is using it. For a learning project, tearing the environment down between sessions is the single largest lever, and it dwarfs anything you can do at the model layer.
The general lesson: cap the model because it is easy, then go look at the infrastructure, because that is where the bill is.
Closing the loop with CodePipeline
Delivery runs through AWS CodePipeline and AWS CodeBuild. A push to the repository triggers the pipeline, CodeBuild executes a buildspec that builds both container images and pushes them to Amazon ECR, and a deploy step updates the Kubernetes deployments so the cluster performs a rolling update.
CodeBuild needs an IAM role with permission to push to ECR, and for the deploy stage it also needs to be registered as an access entry on the cluster so
kubectl is authorised. That second requirement is easy to overlook and produces a confusing permissions error when missed.What I would tell someone starting this
The proportions are the thing I did not anticipate. The Bedrock invocation is roughly twenty lines of Python. Everything around it, the manifests, the IAM policies and trust relationships, the ingress annotations, the NodePool definition, the scrape configuration, is several hundred lines. Almost all of the learning was in the several hundred.
If your goal is to understand cloud infrastructure rather than to ship a product, choose an application nobody needs. A trivial app removes every reason to compromise on the platform, and the platform is what you were trying to learn.
Two more suggestions. Set an AWS Budget with an alert before you create the cluster, not after you receive a bill. And build it in phases, getting the application working locally before any infrastructure exists, so that when something breaks in the cluster you already know the application is not the cause.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article