AWS Certified Cloud Practitioner
EC2 vs Lambda vs containers (ECS, Fargate) for Cloud Practitioner
Amazon EC2 gives you virtual servers, and you manage the operating system and software on them. AWS Lambda runs your code without servers to provision or manage, and you pay for requests and run time. Amazon ECS runs containers for you, either on EC2 instances or on AWS Fargate, a serverless engine where you don't manage servers.
Amazon EC2: virtual servers
An EC2 instance is a virtual server in the AWS Cloud. You launch as many or as few as you need, and scale up or down as demand changes.
The instance type you pick sets the hardware: each type offers a different balance of compute, memory, network and storage. An Amazon Machine Image (AMI) is the template that packages the operating system and other software for the instance.
On-Demand Instances are billed by the second, with a minimum of 60 seconds, and no long-term commitment. EC2 suits workloads where you want full control of the server.
AWS Lambda: serverless functions
AWS Lambda is a serverless compute service. You run code without provisioning or managing servers. Lambda manages the infrastructure, including server maintenance, capacity provisioning, scaling and patching.
A Lambda function runs in response to events or API calls. You connect it to a trigger, such as Amazon S3, Amazon SQS, Amazon EventBridge or Amazon API Gateway. A standard invocation can run for up to 15 minutes.
Lambda is priced on the number of requests and the duration your code runs, measured in GB-seconds. The free tier includes one million requests and 400,000 GB-seconds per month.
Containers: Amazon ECS and AWS Fargate
Amazon ECS is a fully managed container orchestration service. It deploys, manages and scales containerized applications, without you managing a control plane.
ECS needs somewhere to run the containers. With Amazon EC2 instances, you choose the instance type and number and manage the capacity. With AWS Fargate, a serverless, pay-as-you-go compute engine, you don't manage servers or plan capacity. With Amazon ECS Anywhere, you register your own on-premises servers or VMs.
Amazon Elastic Container Registry (Amazon ECR) stores and manages container images. Amazon EKS runs Kubernetes applications on AWS.
Where the exam catches people
- Believing Lambda bills for idle server time: it charges for requests and for the duration your code runs.
- Believing Fargate is the orchestration service: Amazon ECS orchestrates the containers, and Fargate is a serverless engine they can run on.
- Believing EC2 is serverless because AWS owns the hardware: with EC2 you still choose instances and manage the software on them.
- Believing Amazon ECR runs containers: ECR stores and manages container images.
- Believing a Lambda function runs for hours: a standard invocation runs for up to 15 minutes.