Infrastructure Security · Topic 5 of 7

Container and Serverless Security

Secure containers and serverless code with ECR scanning, ECS task roles, EKS pod identity, Lambda execution roles, code signing and secrets handling.

  • 8 min
  • Includes a diagram
In a nutshell
  • ECR basic scanning finds known vulnerabilities, and enhanced scanning uses Inspector for continuous scanning.
  • ECS has a task execution role for the platform and a task role for the application. Do not confuse them.
  • Inject secrets into ECS tasks from Secrets Manager or Parameter Store through the task definition.

What it is

Containers and serverless functions move more responsibility to AWS but add their own risks: vulnerable images, over broad roles, secrets in environment variables and open network paths. The shared responsibility line shifts, yet identity, code and configuration remain yours.

For the exam, focus on three questions: how the image or code is verified, which identity the workload runs as, and what it can reach on the network.

Buildimage or codescan and signRegistryECR or Lambdaruns asTask or functionleast privilege rolereachesDataonly what it needs

How it works

Container images and ECR

Amazon Elastic Container Registry (ECR) stores images. Secure the supply chain with these controls.

  • Image scanning. Basic scanning checks images for known vulnerabilities, and enhanced scanning uses Amazon Inspector for continuous scanning of OS and programming language packages.
  • Immutable tags. Prevent a tag from being overwritten with different content.
  • Repository policies and IAM. Limit who can push and pull, including cross account pulls.
  • Encryption. Repositories are encrypted at rest, with an option to use a customer managed KMS key.
  • Signing. Sign images and verify the signature before deploy, so only trusted builds run.
  • Lifecycle rules. Remove old images that carry known vulnerabilities.

Use minimal base images, run as a non root user, and use a read only root file system where possible.

Amazon ECS

The ECS agent or Fargate uses the task execution role to pull the image from ECR, write logs to CloudWatch Logs and fetch secrets from Secrets Manager or Parameter Store for injection, while the container's application code uses the separate task role to call S3 or DynamoDB. ECS tasks use two different roles, and the exam often tests the difference.

RoleUsed byPurpose
Task execution roleThe ECS agent or FargatePull images from ECR, write logs, fetch secrets for injection
Task roleYour application code in the containerCall AWS APIs such as S3 or DynamoDB

Give each task definition its own task role. Inject secrets from Secrets Manager or Parameter Store using the secrets field of the container definition rather than plain environment variables. With the awsvpc network mode, each task gets its own network interface and security group, which allows task level network control.

Fargate runs each task in its own isolated environment with no access to the underlying host, so there is no node patching or host access to manage.

Amazon EKS

ConcernControl
Pod access to AWS APIsIAM roles for service accounts (IRSA) or EKS Pod Identity, never the node role for every pod
Cluster API accessPrivate endpoint, restricted public CIDRs, access entries or the aws-auth mapping
Pod to pod trafficKubernetes network policies, and security groups for pods
SecretsEncrypt Kubernetes secrets with a KMS key (envelope encryption)
AuditEnable control plane logs, including audit, to CloudWatch Logs
Threat detectionGuardDuty EKS audit log monitoring and Runtime Monitoring

Without pod level identity, all pods on a node share the node role and any compromised pod gets every permission of that role. IRSA and Pod Identity fix that by giving each service account its own role.

Podservice accountassumesIAM rolevia IRSA or Pod IdentityallowedS3 bucketonly this app's data

AWS Lambda

  • Execution role. One role per function with only the actions it needs. The role is the function's identity.
  • Resource based policy. Controls who can invoke the function, such as a service or another account, which is separate from the execution role.
  • Environment variables. They are encrypted at rest, and for sensitive values use a customer managed KMS key and encryption helpers, or better, fetch secrets at runtime from Secrets Manager.
  • VPC access. Attach a function to a VPC only when it must reach private resources, then control it with security groups and, for internet access, a NAT gateway.
  • Code signing. With a code signing configuration based on AWS Signer, Lambda accepts only packages signed by trusted publishers.
  • Dependencies. Inspector can scan function code and its libraries for vulnerabilities.
  • Concurrency. Reserved concurrency can limit the blast radius, and setting it to zero stops a compromised function from running.
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["dynamodb:GetItem", "dynamodb:PutItem"],
    "Resource": "arn:aws:dynamodb:us-east-1:111122223333:table/Orders"
  }]
}

This policy gives a function access to two actions on one table, which is the shape of a least privilege execution role.

Secrets for workloads

Do not bake secrets into images or code. Use Secrets Manager or Parameter Store, grant the task or function role read access to only its secrets, and use VPC endpoints when workloads have no internet path.

Network isolation

Place workloads in private subnets, give them security groups that allow only required flows, and use VPC endpoints for AWS APIs. For EKS and ECS, separate sensitive workloads into different clusters or accounts when the trust boundary calls for it.

Generative AI workloads on Amazon Bedrock

A generative AI application adds new risks on top of the usual compute controls: untrusted text steers the model, and the model may leak data or trigger actions. The Open Worldwide Application Security Project (OWASP) publishes a Top 10 list of risks for large language model (LLM) applications. Skill 3.2.7 asks you to put guardrails against those risks in place.

Amazon Bedrock Guardrails check both the user input and the model response against rules you define.

  • Content filters block harmful categories and also include a prompt attack filter for jailbreak and prompt injection attempts.
  • Denied topics keep the application off subjects you describe.
  • Sensitive information filters detect personally identifiable information (PII) and either block or mask it.
  • Word filters block specific words or phrases.

A guardrail is created once, versioned, and then attached to model calls. The ApplyGuardrail API lets you apply the same guardrail to text from any model, even one outside Bedrock.

OWASP LLM riskTypical AWS control
Prompt injectionPrompt attack filter, and treat all user and retrieved text as untrusted
Sensitive information disclosurePII filters in the guardrail, plus least privilege on the data the model or its knowledge base can read
Excessive agencyA narrow role for any tool or agent action, with human approval for risky steps
Improper output handlingValidate and encode model output before passing it to a browser, shell or database
Unbounded consumptionThrottling, quotas and budgets on model calls

Protect the surrounding plumbing the same way as any other workload.

  • Access. Allow bedrock:InvokeModel only for the model ARNs a role needs.
  • Network. Reach the Bedrock runtime through a VPC interface endpoint so traffic stays off the internet.
  • Logging. Turn on model invocation logging to S3 or CloudWatch Logs, since it is not on by default, and use CloudTrail for the API calls.
Exam tip

A question about blocking prompt injection or masking PII in model answers points to Bedrock Guardrails, while a question about who may call which model points to IAM.

What to remember for the exam

  • ECR basic scanning finds known vulnerabilities, and enhanced scanning uses Inspector for continuous scanning.
  • ECS has a task execution role for the platform and a task role for the application. Do not confuse them.
  • Inject secrets into ECS tasks from Secrets Manager or Parameter Store through the task definition.
  • On EKS, use IRSA or Pod Identity so pods do not share the node role.
  • Encrypt Kubernetes secrets with a KMS key, use private endpoints and enable audit logging.
  • Lambda has an execution role (what the function can do) and a resource policy (who can invoke it).
  • Code signing with AWS Signer restricts Lambda to trusted packages.
  • Reserved concurrency of zero stops a function immediately during an incident.
Exam tip

A question that says "each pod needs different AWS permissions" points to IRSA or EKS Pod Identity, and a question that says "the container needs to pull its image" points to the task execution role.

Common mistakes

Mixing the two ECS roles. Giving S3 access to the execution role does not let the application call S3.

Using the node role for everything on EKS. One compromised pod then reaches every permission on the node.

Storing secrets in environment variables in plain form. They show in the console and in the task definition.

Putting Lambda in a VPC by habit. It adds network complexity without any benefit if the function only calls public AWS APIs.

Watch out

A Lambda resource policy that allows Principal: "*" without conditions makes the function invocable by anyone, so scope it to a service or account with a source condition.

Check yourself

  • What is the difference between the ECS task role and the task execution role?

    The task role is used by application code to call AWS APIs, while the execution role is used by ECS to pull images, write logs and fetch injected secrets.

  • How do you give different EKS pods different IAM permissions?

    Use IAM roles for service accounts or EKS Pod Identity, so each service account has its own role.

  • How do you ensure Lambda runs only trusted code?

    Configure code signing with AWS Signer so Lambda rejects unsigned or untrusted packages.

Topic 5 of 7 in Infrastructure Security

Test yourself on Infrastructure Security

The full AWS SCS-C03 question bank has 858 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.