Elastic Beanstalk
AWS Elastic Beanstalk is AWS's classic Platform as a Service. You upload your application (a zip of Python, Node.js, Java, .NET, PHP, Ruby or Go code, or a Docker image) and Beanstalk creates and manages everything needed to run it: EC2 instances, an Auto Scaling group, a load balancer, security groups, CloudWatch alarms and log collection. Beanstalk itself is free; you pay for the resources it creates.
Concepts
| Term | Meaning |
|---|---|
| Application | A logical container for your app: versions and environments |
| Application version | One uploaded build (a zip in S3), labelled like v42 |
| Environment | A running copy of one version on a set of AWS resources (e.g. shop-prod, shop-staging) |
| Environment tier | Web server (behind a load balancer) or worker (pulls jobs from an SQS queue) |
| Platform | The language runtime + OS, e.g. "Python 3.13 running on 64bit Amazon Linux 2023" |
Deploying with the EB CLI
pip install awsebcli
eb init shop --platform python-3.13 --region eu-west-1
eb create shop-prod --elb-type application --instance-types t3.small
eb deploy
eb statusSample output of eb status:
Environment details for: shop-prod
Application name: shop
Region: eu-west-1
Deployed Version: app-260302_101500
Environment ID: e-abcd1234ef
Platform: arn:aws:elasticbeanstalk:eu-west-1::platform/Python 3.13 running on 64bit Amazon Linux 2023/4.5.0
Tier: WebServer-Standard-1.0
CNAME: shop-prod.eba-xyz12345.eu-west-1.elasticbeanstalk.com
Status: Ready
Health: GreenConfiguration can live in the source tree, in .ebextensions/*.config files:
# .ebextensions/01-scaling.config
option_settings:
aws:autoscaling:asg:
MinSize: 2
MaxSize: 6
aws:elasticbeanstalk:application:environment:
APP_ENV: productionDeployment policies
How Beanstalk replaces the old version with the new one is a trade-off between speed, cost and risk:
| Policy | How | Downtime | Extra cost |
|---|---|---|---|
| All at once | Deploy to every instance simultaneously | Yes, briefly | None |
| Rolling | Deploy in batches; capacity drops during each batch | No | None |
| Rolling with additional batch | Launch an extra batch first, so full capacity is kept | No | Small |
| Immutable | Launch a complete new set of instances, swap when healthy | No | Double for a while |
| Traffic splitting | Send a percentage of traffic to the new version (canary) | No | Double for a while |
| Blue/green (by swapping environment URLs) | Two environments, swap CNAMEs | No | Double for a while |
Model: capacity during a deployment
This model counts how many instances are serving traffic during each step of a deployment of a 4-instance environment with a batch size of 2:
def deploy(policy, instances=4, batch=2):
steps = []
if policy == "all at once":
steps = [0, instances]
elif policy == "rolling":
serving = instances
for _ in range(instances // batch):
steps.append(serving - batch) # one batch out of service
steps.append(instances)
elif policy == "rolling + additional batch":
steps.append(instances + batch) # extra batch launched first
for _ in range(instances // batch - 1):
steps.append(instances)
steps.append(instances)
elif policy == "immutable":
steps = [instances + instances, instances] # new set beside old set, then old removed
return steps
for policy in ["all at once", "rolling", "rolling + additional batch", "immutable"]:
steps = deploy(policy)
print(f"{policy:<27} serving per step {steps} minimum {min(steps)}")all at once serving per step [0, 4] minimum 0
rolling serving per step [2, 2, 4] minimum 2
rolling + additional batch serving per step [6, 4, 4] minimum 4
immutable serving per step [8, 4] minimum 4
"All at once" briefly serves nothing, "rolling" drops to half capacity, and the last two never go below full capacity (at the price of extra instances during the deployment).
Model: environment health colours
Beanstalk's enhanced health summarises instance metrics into a colour. A simplified version based on the share of 5xx errors and the number of healthy instances:
def health(requests, errors_5xx, healthy, desired):
error_rate = errors_5xx / requests if requests else 0
if healthy == 0:
return "Red (no healthy instances)"
if error_rate >= 0.10 or healthy < desired / 2:
return f"Red ({error_rate:.1%} errors, {healthy}/{desired} healthy)"
if error_rate >= 0.01 or healthy < desired:
return f"Yellow ({error_rate:.1%} errors, {healthy}/{desired} healthy)"
return f"Green ({error_rate:.1%} errors, {healthy}/{desired} healthy)"
print(health(12000, 6, 4, 4))
print(health(12000, 300, 4, 4))
print(health(12000, 20, 3, 4))
print(health(9000, 1500, 2, 4))
print(health(0, 0, 0, 4))Green (0.1% errors, 4/4 healthy)
Yellow (2.5% errors, 4/4 healthy)
Yellow (0.2% errors, 3/4 healthy)
Red (16.7% errors, 2/4 healthy)
Red (no healthy instances)
When to use Beanstalk (and when not)
- Good fit: a conventional web app or worker, a small team, you want AWS best practices (Multi-AZ, Auto Scaling, load balancing) without writing the infrastructure yourself.
- Less good: many microservices (look at ECS/EKS or App Runner), event-driven code (Lambda), or when you need full control of every resource (CloudFormation/CDK).
Note: Beanstalk creates ordinary AWS resources. You can still see and inspect them in the EC2 console, but change them through Beanstalk's configuration, or Beanstalk may overwrite your manual changes.
Test yourself
What does Elastic Beanstalk cost?
- A fixed monthly fee
- Nothing for Beanstalk itself; you pay for the resources it creates
- Per deployment
- Per line of code
Which deployment policy launches a full new set of instances and keeps the old set until the new one is healthy?
- All at once
- Rolling
- Immutable
- Scheduled
Which environment tier processes background jobs from an SQS queue?
- Web server tier
- Worker tier
- Database tier
- Edge tier