Elastic Beanstalk
Deploy a web app by uploading code; Beanstalk builds the EC2, load balancer, scaling and monitoring automatically. Components, tiers and environment types.
What it is
Most web apps on AWS end up with the same building blocks: EC2 instances in an Auto Scaling group behind a load balancer, often with an RDS database, spread across AZs. Building, configuring and updating that by hand takes time, and developers mostly just want their code to run, the same way in every environment.
AWS Elastic Beanstalk is a developer-centric way to deploy an app on AWS. The developer uploads the code; Beanstalk creates and manages the EC2 instances, Auto Scaling group, load balancer, health monitoring and configuration.
- It's a managed service: capacity provisioning, load balancing, scaling, application health monitoring and instance configuration are handled by Beanstalk.
- Only the application code is the developer's job. But the developer keeps full control: the resources are normal AWS resources in the account, and their settings can be changed.
- Beanstalk is free. Billing covers only the resources it creates, such as the EC2 instances and load balancer.
It sits between EC2 (the customer does everything) and fully serverless services (no servers at all): a Platform as a Service built on familiar pieces.
Components
- Application: the container for everything about one app: its environments, versions and saved configurations.
- Application version: one iteration of the code, a source bundle (a zip, a Java WAR file) stored in S3, with a label such as
v1.4. - Environment: the AWS resources running one application version at a time. An application can have several environments, such as
dev,testandprod, running different versions. - Environment tier: what kind of environment it is: a web server tier or a worker tier (below).
- Configuration: the settings that define how the environment's resources behave.
The workflow: create an application → upload a version → launch an environment → manage it, then upload new versions and deploy them to the environment.
Supported platforms
Beanstalk runs code written in Go, Java (SE and Tomcat), .NET (on Linux or Windows Server), Node.js, PHP, Python and Ruby, and any language packaged as a Docker container, including a platform that runs containers on ECS.
Web server tier vs worker tier
- Web server tier: a load balancer sends HTTP requests to EC2 instances in an Auto Scaling group across AZs. The environment gets a URL such as
myapp.us-east-1.elasticbeanstalk.com. - Worker tier: EC2 instances in an Auto Scaling group process jobs from an SQS queue. Beanstalk creates the queue if none exists, and a daemon on each instance pulls messages and passes them to the app. The tier scales on the number of messages in the queue.
- A web tier can push jobs to the worker tier's queue, so slow work (sending emails, making reports, resizing videos) doesn't hold up web requests. That's decoupling, covered in the Application Integration group.
Environment types
- Single instance, great for development: one EC2 instance with an Elastic IP, and optionally an RDS database, in one AZ. No load balancer, so it's cheap, but there's no failover or scaling.
- High availability with a load balancer, great for production: a load balancer in front of an Auto Scaling group spanning several AZs, and an RDS database with a standby in a second AZ (Multi-AZ).
An environment can start with a single instance and switch the environment to load-balanced later.
Updated since the slides
Beanstalk now has two modes. Beanstalk Standard is what the slides describe: apps run on EC2. Beanstalk Cluster runs apps as containers on Amazon EKS. The platform list has also changed: the old Multi-container Docker and Packer builder platforms are gone, and Docker apps use the Docker or ECS platforms on Amazon Linux 2023.
Real-world examples
- A start-up deploys its Python API with
eb deployfrom a laptop, and gets scaling and health monitoring without anyone on the team knowing CloudFormation. - An agency runs a
devsingle-instance environment and aprodload-balanced environment for each client site, from the same code.
Exam tips
- "Developers want to deploy code without managing infrastructure", "quickly deploy a web app", on a supported language → Elastic Beanstalk.
- "Background jobs", "long-running tasks decoupled from the web app" → a Beanstalk worker environment with SQS.
- "Cheap dev environment" → single-instance environment. "Production, highly available" → load-balanced environment.
- Beanstalk itself is free; the underlying resources are billed.
Common traps
- "Beanstalk hides the resources so you can't change them." They're normal resources in the account, under the customer's full control.
- "Beanstalk is serverless." It runs EC2 instances (or EKS in Cluster mode) that are billed.
Beyond the exam: deployment policies
When a new version is deployed to a load-balanced environment, Beanstalk can roll it out in several ways:
- All at once: fastest, but a short outage.
- Rolling: one batch of instances at a time; capacity drops during the deploy.
- Rolling with additional batch: launches an extra batch first, so capacity never drops.
- Immutable: launches a full new set of instances, then swaps; safest and easiest to roll back.
- Traffic splitting: sends a percentage of traffic to the new version first (canary testing).
A blue/green deployment uses two environments and swaps their URLs. These are tested in the Developer Associate exam more than in SAA.
Hands-on lab: deploy the sample app
Goal: get a working web app on AWS without writing code, and see what Beanstalk created.
Costs money
A single-instance environment runs one t3.micro with an Elastic IP: about $0.02 an hour. Beanstalk also creates a small S3 bucket for app versions. Terminate the environment when you finish.
Create the application
Open Elastic Beanstalk in us-east-1 and choose Create application. Environment tier Web server environment, application name saa-beanstalk, platform Node.js (latest), application code Sample application, preset Single instance.
Roles
On Configure service access, choose Create and use new service role. For the EC2 instance profile, use aws-elasticbeanstalk-ec2-role if it exists. If not, the console shows a link to create it (an EC2 role with the AWSElasticBeanstalkWebTier policy). Pick your key pair saa-lab-key.
Launch
Keep the defaults on the next pages (instance type t3.micro, no database), add the tag Project=saa-lab, and Submit. Watch the Events list as Beanstalk creates the resources, which takes a few minutes.
Open it and look around
When health is OK, click the environment's domain: the sample Congratulations page appears. Then look in the EC2 console (a new instance and an Elastic IP) and CloudFormation (a stack named after the environment, which Beanstalk uses behind the scenes).
Expected result: a running web app on its own elasticbeanstalk.com URL, built from normal EC2 resources in your account.
Clean up: in Elastic Beanstalk, Actions → Terminate environment, then delete the application. Beanstalk removes the instance, Elastic IP and stack. The S3 bucket elasticbeanstalk-us-east-1-<account> stays; empty and delete it if you won't use Beanstalk again (it has a bucket policy you may need to delete first).