AWS Elastic Beanstalk
Environment tiers, platforms, deployment policies, configuration with ebextensions, health reporting and the database and blue/green pitfalls.
Exam tasks: 2.1 (deployment strategies), 2.5, 4.3 (replatform a web application)
The decision: do you want a managed platform for a standard web application, where you upload code and AWS builds the load balancer, Auto Scaling group and monitoring, while you keep access to the instances?
Beanstalk is a platform as a service built from ordinary AWS resources. It creates an environment: an Auto Scaling group of EC2 instances, a load balancer, security groups, CloudWatch alarms and an S3 bucket for versions. You pay only for those resources.
Tiers and platforms
| Web server tier | Worker tier | |
|---|---|---|
| Receives | HTTP requests through a load balancer | Messages from an SQS queue |
| How | Standard web application | A daemon reads the queue and posts each message to your app over local HTTP |
| Use it for | Websites and APIs | Background jobs and periodic tasks (a cron.yaml file) |
- Platforms include Java (Tomcat and SE), .NET, Node.js, PHP, Python, Ruby, Go and Docker.
- Instances run in your VPC and you keep SSH access. Managed platform updates apply patches in a maintenance window.
Deployment policies
| Policy | Capacity during deploy | Rollback |
|---|---|---|
| All at once | Drops, brief outage | Redeploy |
| Rolling | Reduced by a batch | Redeploy |
| Rolling with additional batch | Full, an extra batch first | Redeploy |
| Immutable | Full, new instances in a temporary group | Terminate the new group |
| Traffic splitting | Full, a percentage of traffic to new instances | Reroute |
Beanstalk offers all at once, rolling, rolling with additional batch, immutable and traffic splitting (a canary: a percentage of requests goes to a new set of instances for an evaluation period).
Blue/green in Beanstalk is not a deployment policy. You clone the environment, deploy to the clone, then swap environment URLs (a CNAME swap). Because it's DNS-based, clients with cached records keep reaching blue for a while.
Blue/green and the database
Beanstalk blue/green swaps environments. If the RDS instance was created inside the environment, it belongs to blue and gets deleted with it. Production databases should be created outside Beanstalk and passed in through configuration.
Configuration and operations
.ebextensions*.configfiles customize packages, files, commands and environment resources. Saved configurations capture environment settings to reuse. Environment properties set environment variables.- Enhanced health reporting reads an agent on each instance and reports application health with colors and causes. Basic health only reflects the load balancer and instance status.
- Environment cloning copies an environment's configuration, which is the first step of a blue/green release.
- Beanstalk uses an instance profile for instances and a service role for Beanstalk itself.
- For anything beyond standard web applications, such as complex container networking, ECS or EKS fits better.
Scenarios
A database created inside an environment lives and dies with it. A clone gets a new, empty database. Production databases should be created outside and referenced through configuration. Rolling policies are a different mechanism, and neither a different Region nor a Classic Load Balancer is required.
The worker tier is built for queued background jobs, with a daemon that delivers messages and scales with the queue. A second web environment still handles HTTP. Lambda is capped at 15 minutes. A cron job on web instances competes with web traffic and scales badly.
Related
- Deployment strategies: CodeDeploy and traffic shifting compared with Beanstalk.
- Compute and containers: when to pick Beanstalk over ECS or Lambda.
- Modernization: replatforming to Beanstalk.
Further reading
AWS CloudFormation
Template anatomy, intrinsic functions, stacks, nested stacks and StackSets, change sets, rollback behavior, helper scripts and safety controls.
Configuration and patching
Using Systems Manager to patch, configure, access and inventory EC2 and on-premises servers at scale, and building golden AMIs with EC2 Image Builder.