Deploying Web Applications with AWS Elastic Beanstalk
This lesson explains how Elastic Beanstalk deploys and runs web applications on managed platforms, handling capacity, load balancing, scaling and monitoring while leaving the resources under your control.
Learning outcomes
After completing this lesson, you will be able to:
- Describe what Elastic Beanstalk manages.
- Choose a deployment policy.
- Explain why production databases belong outside the environment.
What Beanstalk manages
AWS Elastic Beanstalk deploys and manages web applications written in Java, .NET, Node.js, Python, PHP, Ruby or Go, or packaged as Docker containers, from a source bundle. It creates and manages the infrastructure: EC2 instances, a load balancer, an Auto Scaling group and CloudWatch alarms, and it applies managed platform updates.
Web server environments serve HTTP requests, while worker environments process messages from an SQS queue and run periodic tasks. Beanstalk itself is free; the customer pays for the resources it creates.
Deployment policies
Elastic Beanstalk deployment policies trade speed and cost against downtime and capacity. All at once deploys to every instance together: it is the fastest, but the application is down while it deploys. Rolling deploys in batches, avoiding downtime but running with reduced capacity. Rolling with additional batch launches extra instances first, so capacity stays full.
Immutable deploys to a full set of new instances in a temporary Auto Scaling group and switches only when they are healthy, so a failure is undone quickly by terminating them. Traffic splitting sends a percentage of real traffic to new instances for an evaluation period before completing, as a canary test. The following table summarises the policies.
| Policy | Downtime | Capacity during deployment |
|---|---|---|
| All at once | Yes | None while deploying |
| Rolling | No | Reduced |
| Rolling with additional batch | No | Full |
| Immutable | No | Full; new instances in a temporary group, quickest rollback |
| Traffic splitting | No | Full; a percentage of traffic tests the new version |
Blue/green deployments use a second environment and a swap of environment URLs.
Which deployment policy?
Databases
Elastic Beanstalk can create an Amazon RDS database as part of an environment, but such a database is tied to the environment's lifecycle and is deleted with it, for example when the environment is terminated or replaced in a blue/green deployment. Production databases should therefore be created separately, outside the environment, and their connection details passed to the application through environment properties or, for credentials, AWS Secrets Manager.
A small team's web application
A three-person team must deploy a Python web application with load balancing, Auto Scaling and zero-downtime releases, without learning to build the infrastructure themselves.
| Requirement | Elastic Beanstalk feature |
|---|---|
| Infrastructure created for them | A load-balanced web server environment |
| Zero-downtime releases with quick rollback | Immutable deployment policy |
| Background jobs from a queue | A worker environment |
| Database that survives environment replacement | RDS created separately and passed in through environment properties |
The team keeps full access to the EC2 instances and load balancer if it ever needs to tune them.
Why should a production database not be created inside an Elastic Beanstalk environment?
Show answer
Its lifecycle is tied to the environment, so terminating or replacing the environment deletes the database. A separately created RDS instance survives.
Exam Tips
Remember for the exam
- To deploy a web application quickly without managing the infrastructure details, use Elastic Beanstalk.
- To keep the database when a Beanstalk environment is deleted, create the RDS database outside the environment.
- For zero downtime with the quickest rollback, use immutable deployments.
- For background jobs from an SQS queue, use a worker environment.