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.
| Service | What it does |
|---|---|
| Amazon ECS | AWS's own container orchestration for running and scaling containers |
| Amazon EKS | Managed Kubernetes, the popular open-source orchestrator |
| Amazon ECR | Stores and manages container images |
| AWS Fargate | Serverless compute for containers, with ECS or EKS: no EC2 instances to manage; pay for each task's CPU and memory |
Container services
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
AWS Lambda
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.
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:
| Option | What the team manages | Cost when nobody uploads |
|---|---|---|
| An EC2 instance running all the time | The server, operating system and patching | Still paying for the instance |
| A container on ECS with AWS Fargate | The container image only | Pay while tasks run |
| An AWS Lambda function triggered by each S3 upload | Only the code | Nothing |
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.
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.