Lesson 2 of 4 Compute Services

Running Applications with Containers and Serverless Compute

This lesson explains how containers package an application with everything it needs to run, and how serverless services remove server management from your responsibilities altogether.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe what containers are and the AWS services that run them.
  • Describe how AWS Lambda runs code in response to events.
  • Identify the benefits of serverless services.

Containers

Containers, such as Docker containers, package code, libraries and settings into a lightweight unit that runs the same way anywhere. They start quickly and use resources efficiently, so they are popular for microservices. Running many containers needs an orchestrator, which starts them, restarts them if they fail and scales them. Amazon ECS is AWS's own orchestrator, and Amazon EKS runs Kubernetes, the popular open-source orchestrator, as a managed service. Amazon ECR stores the container images that they run.

Containers still need servers to run on. They can run on EC2 instances that you manage, or on AWS Fargate, serverless compute for containers that works with ECS and EKS: there are no instances to manage, and you pay for the CPU and memory each container uses. The following table summarises the services.

ServiceWhat it does
Amazon ECSAWS's own container orchestration for running and scaling containers
Amazon EKSManaged Kubernetes, the popular open-source orchestrator
Amazon ECRStores and manages container images
AWS FargateServerless compute for containers, with ECS or EKS: no EC2 instances to manage; pay for each task's CPU and memory
Match the pairs

Container services

Exam skills 3.3.2 · 3.3.3

Match each container need with the AWS service that meets it.

Log in to try this activity Interactive activities are free with an account.

AWS Lambda

AWS Lambda is a serverless compute service that runs code in response to events. The following list describes its principal characteristics.

  • Runs your code in response to events: an HTTP request through API Gateway, a file uploaded to S3, a message in a queue or a schedule.
  • No servers to manage; scales automatically from zero to thousands of requests.
  • Pay per request and for compute time, billed by the millisecond.
  • Each invocation can run for up to 15 minutes.

15min

Longest a Lambda invocation can run

True or false

AWS Lambda

Exam skills 3.3.3

Check the facts about AWS Lambda.

Log in to try this activity Interactive activities are free with an account.

Benefits of serverless

No servers to provision, patch or manage; automatic scaling; built-in high availability; and no cost when idle. Other serverless services include S3, DynamoDB, API Gateway, SNS and SQS.

Worked example

Three ways to run a photo resizing feature

When users upload profile photos, an app must create a small thumbnail. The team compares three ways to run the resizing code:

OptionWhat the team managesCost when nobody uploads
An EC2 instance running all the timeThe server, operating system and patchingStill paying for the instance
A container on ECS with AWS FargateThe container image onlyPay while tasks run
An AWS Lambda function triggered by each S3 uploadOnly the codeNothing

Lambda fits best: each upload triggers the function, it runs for a second or two (well under the 15-minute limit), scales automatically if thousands of photos arrive at once, and costs nothing when idle. A long-running video processing job, by contrast, would suit containers on Fargate.

Check yourself

What does serverless mean for the customer?

Show answer

There are no servers to provision or manage, the service scales automatically, and you pay only for what you use, such as AWS Lambda per request and duration.

Exam Tips

Remember for the exam

  • To run code in response to events without servers, use Lambda.
  • To run containers without managing servers, use Fargate.
  • Managed Kubernetes is EKS; AWS-native container orchestration is ECS.
  • To store container images, use ECR.
  • A Lambda invocation can run for at most 15 minutes.