AWS Elastic Beanstalk
Deploying web applications without managing infrastructure: platforms, environments and tiers, worker environments, deployment policies and blue/green, configuration files, managed updates, security, cost, and monitoring.
7 min read · Last reviewed · SAA-C03
Sign in to bookmark tutorials and track what you have read.
On this page
What it is
AWS Elastic Beanstalk deploys and runs web applications for you. You upload your code, and Elastic Beanstalk creates and manages everything it needs: EC2 instances, an Auto Scaling group, a load balancer, health monitoring, and logging. You can still see and adjust every resource it creates; it is a convenience layer over normal AWS services, not a black box.
Elastic Beanstalk supports applications written in Go, Java, .NET, Node.js, PHP, Python, and Ruby, and Docker containers for anything else. It is the usual answer when a question asks to deploy a web application quickly, with the least operational overhead, while keeping the option to control the underlying resources.
Elastic Beanstalk now has two modes. Beanstalk Standard runs applications directly on EC2, as described in this tutorial. Beanstalk Cluster runs applications as containers on Amazon EKS, for faster deployments and scaling when you run many environments.
Concepts
- Application: a container for versions, environments, and configurations.
- Application version: a labeled copy of deployable code, such as a ZIP or WAR file, stored in Amazon S3.
- Environment: the AWS resources running one application version. You might have separate development, test, and production environments for the same application.
- Platform: the operating system, language runtime, and web or application server, such as a Python or Node.js platform on Amazon Linux 2023.
- Environment type: load-balanced, scalable (an Elastic Load Balancing load balancer and an Auto Scaling group across AZ (Availability Zone)An isolated location within an AWS Region, made up of one or more data centers with their own power, cooling, and networking. The AZs in a Region are linked by fast, low-latency connections, so spreading resources across them protects against the failure of one site.Glossary entry) for production, or single-instance (one instance with an Elastic IP (Internet Protocol)The protocol that addresses and routes packets between networks. Each device has an IP address: IPv4 addresses look like 192.0.2.1, and IPv6 addresses are longer, like 2001:db8::1.Glossary entry address, no load balancer) for development and low traffic.
Environment tiers
- A web server environment serves HTTP (Hypertext Transfer Protocol)The protocol that web browsers and APIs use to send requests, such as GET and POST, and receive responses. On its own it is not encrypted; HTTPS adds TLS.Glossary entry requests behind a load balancer.
- A worker environment processes background tasks from an Amazon SQS queue. A daemon on each instance reads messages and sends each one as an HTTP
POSTto your application on the instance; a200 OKresponse deletes the message, and failures are retried and eventually go to a DLQ (Dead-letter queue)A queue that receives messages that could not be processed after a set number of attempts, so they stop blocking other messages and can be inspected later. Amazon SQS, Amazon SNS, AWS Lambda, and Amazon EventBridge can send failed messages to one.Glossary entry. - A
cron.yamlfile in a worker environment schedules periodic tasks.
Putting long-running work, such as video processing or report generation, in a worker environment keeps the web tier responsive. This DecouplingDesigning components so that they do not depend directly on each other being available, for example by passing work through a queue. A slow or failed component then does not stop the others, and each can scale on its own.Glossary entry is a common exam pattern.
Deployment policies
| Policy | How it works | Downtime | Cost and speed | Rollback |
|---|---|---|---|---|
| All at once | Deploys to every instance at the same time | Yes, briefly | Fastest | Redeploy |
| Rolling | Deploys in batches | No, but capacity drops by one batch | Moderate | Redeploy |
| Rolling with additional batch | Launches an extra batch first, then rolls | No, full capacity kept | Slower; extra instances briefly | Redeploy |
| Immutable | Launches a new Auto Scaling group with the new version, then removes the old instances | No | Slowest; doubles capacity briefly | Terminate the new instances |
| Traffic splitting | Sends a percentage of traffic to new instances for an evaluation period (canary) | No | Slow | Reroute traffic to the old instances |
| Blue/green deploymentReleasing a new version (green) alongside the running one (blue), then moving traffic to green once it is ready. Rolling back is quick: move the traffic back to blue.Glossary entry | Deploy to a separate environment, then swap environment URLs (a CNAME (Canonical name record)A DNS record that makes one domain name an alias of another, such as www.example.com pointing to example.com. A CNAME cannot be used for the zone apex (example.com itself); Route 53 alias records cover that case.Glossary entry swap) | No | Two full environments | Swap back |
Use blue/green when the new version cannot run alongside the old one, or to change to an incompatible platform version. Keep the production database outside the environment, for example in Amazon RDS created separately, so it survives when an environment is replaced or terminated.
Configuration
- Configuration files (
.configfiles in an.ebextensionsfolder in your source bundle) set options, install packages, run commands, and add other AWS resources through AWS CloudFormation. - Saved configurations capture an environment's settings so you can create identical environments.
- Managed platform updates apply patch and minor platform updates automatically in a weekly maintenance window, using an immutable update so the application stays in service.
Security, resilience, performance, and cost
Security
- Elastic Beanstalk uses a service role to manage resources for you, and an instance profile that gives the instances their permissions, for example to read from S3 or send logs.
- Run environments in your VPC, with instances in SubnetA range of IP addresses in a VPC, inside one Availability Zone. A subnet is public when its route table sends internet traffic to an internet gateway, and private when it does not.Glossary entry and the load balancer in public subnets, and use Security groupA stateful virtual firewall for network interfaces, such as an EC2 instance's, whose rules can only allow traffic. Return traffic for allowed connections is allowed automatically, and a rule can refer to another security group instead of IP addresses.Glossary entry to limit access.
- Store secrets in AWS Secrets Manager or Systems Manager Parameter Store rather than in the source bundle.
- Turn on managed platform updates so the operating system and runtime get security patches.
Resilience
- A load-balanced environment spreads instances across Availability Zones and replaces unhealthy ones through its Auto Scaling group.
- Choose a deployment policy without downtime, such as rolling with additional batch, immutable, or blue/green, for production.
- Keep the database and any state outside the environment.
Performance
- Configure the Auto Scaling group's triggers, such as CPU or network, and the instance type, through the environment's capacity settings.
- Use a worker environment for long tasks so they don't slow down web requests.
Cost
- Elastic Beanstalk has no additional charge; you pay for the EC2 instances, load balancer, storage, and other resources it creates.
- Use single-instance environments for development, and scale production environments with demand.
Monitoring
- Enhanced health reporting uses an agent on each instance to report application and operating system health every 10 seconds, with color-coded status and causes in the console. You can publish detailed health metrics to Amazon CloudWatch for a fee.
- Instance logs can stream to CloudWatch Logs, with a retention period you choose.
- Environment events record deployments, configuration changes, and health transitions; AWS CloudTrail records API (Application programming interface)A defined way for one program to ask another for data or actions, such as a set of HTTPS requests and responses. Every AWS service is controlled through its API, which the console, the CLI, and the SDKs call for you.Glossary entry calls.
Elastic Beanstalk or another service?
| If the requirement is | Choose |
|---|---|
| Deploy a web application with the least effort, keeping control of resources | AWS Elastic Beanstalk |
| Full control of servers and every setting | Amazon EC2 with Auto Scaling and a load balancer |
| Run containers with an orchestrator you configure | Amazon ECS or Amazon EKS |
| Event-driven architectureA design in which services react to events that other services emit, such as an order placed or a file uploaded, instead of calling each other directly. Amazon EventBridge, Amazon SNS, Amazon SQS, and AWS Lambda are common building blocks.Glossary entry code with no servers | AWS Lambda |
| Define any IaC (Infrastructure as code)Defining infrastructure, such as networks, servers, and permissions, in text files that are versioned and deployed automatically, instead of setting it up by hand. AWS CloudFormation and the AWS CDK are AWS tools for it.Glossary entry | AWS CloudFormation (Elastic Beanstalk uses it under the hood) |
Reverse mindmap: when the question points here
- Yes, when the question says
- Deploy a web app quickly, least operational overhead leads to Elastic Beanstalk
- Developers upload code, AWS handles capacity and scaling leads to Elastic Beanstalk
- Background tasks from a queue leads to Worker environment with SQS
- Scheduled jobs for the worker tier leads to cron.yaml periodic tasks
- Choose the deployment
- Fastest deploy, downtime acceptable leads to All at once
- No downtime, full capacity kept leads to Rolling with additional batch
- Safest rollback, new instances only leads to Immutable
- Test the new version on some traffic leads to Traffic splitting
- Switch instantly and swap back if needed leads to Blue/green with URL swap
- Run it well
- Database must survive environment replacement leads to RDS outside the environment
- Install packages or set options at deploy leads to .ebextensions configuration files
- Keep the platform patched automatically leads to Managed platform updates
- No, when the question says
- Full control over every server setting leads to EC2 with Auto Scaling
- Container orchestration you manage leads to ECS or EKS
Key takeaways
- Elastic Beanstalk deploys web applications onto EC2, Auto Scaling, and a load balancer for you, at no extra charge.
- Web server environments serve HTTP; worker environments process SQS messages.
- Deployment policies trade speed for safety: all at once, rolling, rolling with additional batch, immutable, traffic splitting, and blue/green by URL swap.
- Keep databases outside the environment; customize with
.ebextensions; let managed platform updates patch it. - Enhanced health reporting and CloudWatch Logs streaming give visibility into the environment.
Sources
- AWS Elastic Beanstalk Developer Guide: What is AWS Elastic Beanstalk?
- AWS Elastic Beanstalk Developer Guide: Understanding concepts in Elastic Beanstalk
- AWS Elastic Beanstalk Developer Guide: Environment types
- AWS Elastic Beanstalk Developer Guide: Worker environments
- AWS Elastic Beanstalk Developer Guide: Deploying applications to Elastic Beanstalk environments
- AWS Elastic Beanstalk Developer Guide: Blue/Green deployments with Elastic Beanstalk
- AWS Elastic Beanstalk Developer Guide: Advanced environment customization with configuration files
- AWS Elastic Beanstalk Developer Guide: Managed platform updates
- AWS Elastic Beanstalk Developer Guide: Service roles, instance profiles, and user policies
- AWS Elastic Beanstalk Developer Guide: Enhanced health reporting and monitoring
- AWS Elastic Beanstalk Developer Guide: Using Elastic Beanstalk with Amazon CloudWatch Logs