AWS Builder Center

Securing Your Containers in AWS (the stuff that actually matters)

Practical AWS container security guide covers base image hygiene, IAM lockdown (the #1 real breach cause), image scanning in CI, network isolation, runtime hardening, secrets management, monitoring, and pipeline security. Written casual/conversational, not corporate ordered by what actually prevents breaches, not textbook order.

Ai researcher
Everyone loves containers until something gets popped and nobody knows why. I've seen enough writeups and postmortems to notice the same handful of mistakes showing up over and over. So here's a rundown, roughly in order of "how much this actually saves you," not some textbook checklist order. Your base image is probably the weakest link Start here because honestly most people don't. If you're pulling some random ubuntu:latest and layering your app on top, you're inheriting whatever CVEs are sitting in that image, and you probably don't even know what they are. Go minimal. Alpine, distroless, whatever smaller surface area, fewer things that can go wrong. And please, pin your versions. latest in production is asking for a surprise later. Rebuild every so often too, images rot. IAM is where things actually go wrong in real life Not gonna lie, this is the one people skip because it's boring, and it's also the one that bites the hardest. Most container "breaches" you read about aren't some 0-day exploit, they're just a role with way too many permissions attached to it. Use task roles in ECS or IRSA if you're on EKS. Don't bake AWS keys into your image or env vars I know it's tempting when you're rushing to ship something, but don't. If your container reads from one bucket, give it access to that one bucket. Not s3:*. Run IAM Access Analyzer once in a while too, you'll be surprised what's sitting there unused. Scan your images, obviously, but actually wire it into CI ECR has scanning built in turn it on. Enhanced scanning uses Inspector and catches more. The part people mess up is not failing the build on critical CVEs they scan, see red, and ship anyway because there's a deadline. Don't do that, set it to actually block. Also check for secrets accidentally baked into image layers. Happens more than you'd think someone commits an API key, deletes it in the next commit, but it's still sitting in an earlier layer forever. Network stuff Private subnets for anything that doesn't need to be public. Security groups should default-deny and you open only what's needed, not the other way around. If you're on EKS and this trips people up a lot Kubernetes by default lets any pod talk to any pod. That's rarely what you actually want. Network policies fix this but a lot of clusters just never set them up because it's not the default and nobody remembers. Runtime hardening (small things, add up) run as non-root, set USER in your Dockerfile, it's one line read-only root filesystem where you can get away with it drop capabilities you don't need --cap-drop=ALL and add back only what's required None of these are hard. They're just easy to forget when you're focused on getting the thing working. Secrets don't do the obvious wrong thing You know the wrong thing. Plaintext env vars, secrets baked into the image. Use Secrets Manager or Parameter Store with SecureString, inject at runtime. Rotation matters too Secrets Manager can do this automatically for a lot of AWS services, so there's no excuse really. Actually watching what's happening Deploying securely and then never looking again isn't really security. GuardDuty has runtime protection for EKS and ECR now, catches weird stuff like a container suddenly making outbound calls to some crypto-mining pool. Ship logs somewhere central (CloudWatch or your SIEM of choice) and actually set alerts, not just collect logs nobody reads. AWS Config is also worth setting up for drift detection catches things like "wait, why is this container running as root now" before it becomes a problem. Don't forget the pipeline itself Your CI/CD is part of the attack surface, people forget this constantly. Restrict who can push to ECR. Sign your images (cosign or AWS Signer) and verify before deploy. And for the love of god use OIDC federation for your pipeline credentials instead of some long-lived access key sitting in a GitHub secret for two years. If I had to pick two things to fix first if you're starting from nothing: base image hygiene and IAM. That's where most of the real damage happens in practice, everything else is incremental hardening on top of that foundation. Anyway feedback welcome, I'm sure I missed something.
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