EB is a PaaS (Platform as a Service) to quickly deploy and manage applications in AWS without worrying about the underlying infrastructure.
Features
AWS Elastic Beanstalk is used to deploy and scale applications and services.
You can simply upload your code, and AWS Elastic Beanstalk automatically handles the deployment, from capacity provisioning, load balancing, and auto scaling to application health monitoring.
- Supports many programming languages.
- Java, .NET, PHP, Node.js, Python, Ruby, and Go
- Supports many platforms
- Apache, Tomcat, Nginx, Passenger, and Internet Information Services (IIS)
- Supports Docker images
- Fits best to provision an environment with little admin overhead but not good for low-level infrastructure control.
- Can host multiple different versions in separate URLs.
- Basic Monitoring with CloudWatch and CloudTrail
- Monitors application health via a health dashboard.
- Can only be used to deploy application to the AWS cloud. It is not used to deploy application on-premise environment.
- Architecture Model
- Single Instance (1 AZ)
- for developing and testing
- single AZ RDS
- LB + ASG
- Web applications – Production or Staging
- ASG only
- Non-web applications (Workers) – Production or Staging
- Works with SQS
- Single Instance (1 AZ)
Workflow
- Create an Application
- Setup the environment
- Set the service role & EC2 instance profile with EC2 Key pair
- Select the VPC
- Set up Database if required
- Set up the EC2 instance information
- Set up Auto Scaling Group & Load Balancing
- Set up Health reporting
- Set up deployment options
- Upload a bundle – Version
- Launch Environment
- Update and Deploy a new Version
Key Architecture Components
Application
- An application is a logical collection of Elastic Beanstalk Components such as environments, versions, and environment configurations.
- You can think of the application as a container or a package.
Application version
- An application version refers to a distinct iteration of an application that’s packaged into a bundle. It points to an S3 object that contains the deployable code.
Environment
- An environment is a collection of AWS resources running a specific application version.
- Each environment runs only one application version at a time.
- Tiers
- Web Server environment
- EC2 Instances + ASG + ELB
- Worker environment
- Long-running processes
- EC2 Instances + ASG + SQS
- You can define periodic tasks in cron.yaml
- Web Server environment
- Modes
- Single Instance
- Single Instance using spot instance
- High Availability
- High Availability using spot and on-demand instances
- Custom
Deployment Types
Deploying applications to Elastic Beanstalk environments – AWS Elastic Beanstalk (amazon.com)
All at once
- Deploys the new version to all instances simultaneously.
- Quick, simple and no additional cost
- Not recommended for production
- Good for the first deployment or in the development/test environment
- Rollback:
- Redeploy the old version to all instances
Rolling
- Splits instances into batches (buckets) and deploys one batch at a time to the existing instances
- No service outage but your service capacity will be reduced by the batch size.
- Both versions are running at the same time.
- Not good for performance-sensitive applications
- Rollback
- Do another rolling update to the old version
Rolling with additional batch
- Steps
- Deploys the new version in batches, but the first batch is deployed to the newly created instances.
- Once the first batch is successfully deployed in a new environment, all existing instances will be deployed in batch.
- Features
- It ensures full capacity during the deployment process.
- Both versions are running at the same time.
- Rollback
- Do another rolling update
Immutable
- Immutable environment updates are an alternative to rolling updates.
- Steps
- A temporary ASG is created
- A new instance is created.
- New version is installed
- Attached to the temporary ASG
- If the first instance works, all other required instances are created on a temporary ASG.
- Move all instances in the temporary ASG are moved to the old ASG
- Both new and old instances are located in the same ASG.
- Old instances are terminated.
- Features
- You do not modify or update the existing environment.
- You need to create a new environment for a new version.
- Unlike Blue/Green, both versions are running at the same time.
- Rollback
- Just delete the new environments.
Traffic splitting
- Deploys the new version to new instances just like immutable deployment
- Main ASG (old version) and Temp ASG (new version)
- And then temporarily split traffic between the new version and the old version. (Canary testing)
Blue/Green
- Not a “direct feature” of Elastic Beanstalk
- Steps
- Create a new “stage” environment and deploy a new version – green environment
- The new green environment is validated independently and roll back if needed
- Route 53 can be setup using weighted policies (canary)
- Using Beanstalk, swap URLs
<Note> Some policies – Deployments with immutable updates or traffic splitting – replace all instances during the deployment or update. This causes all accumulated Amazon EC2 burst balances to be lost.
| Deployment Type | Deploy time | Zero downtime | DNS Change | Failed Deployment | Rollback | Deploy to |
|---|---|---|---|---|---|---|
| All at once | Quick | No | No | Downtime | Manual | Existing instances |
| Rolling | Medium | Yes | No | Single batch out of service, Mix of old/new version | Manual | Existing instances |
| Rolling with an additional batch | Medium+ | Yes | No | Minimal if the first batch fails, otherwise similar to Rolling | Manual | New and Existing instances |
| Immutable | Long | Yes | No | Minimal | Terminate new instances | New instances |
| Traffic Splitting | Long | Yes | No | Percentage of traffic to new version | Reroute traffic and terminate new instances | New instances |
| Blue/Green | Long | Yes | Yes | Minimal | Swap URL | New instances |
Using Elastic Beanstalk with Amazon RDS
Option 1: Launch RDS within the Elastic Beanstalk environment
- Launch RDS inside the Elastic Beanstalk
- When you terminate the environment, the RDS is also terminated
- It is OK for dev and test environment, but not good for the production environment.
Option 2: To allow your EC2 instances in the EB environment to connect to an outside database:
- Configure an additional security group allowing access to the database
- Add the security group to the Auto Scaling group that’s associated with your environment
- Pass the connection information, such as the endpoint and password, to your application by using environment properties
Configuration Options
During environment creation, configuration options are applied from multiple sources with the following precedence, from highest to lowest:
- Settings applied directly to the environment
- Saved Configurations
- Configuration Files (.config files in the .ebextensions folder in the top-level directory of your application source code bundle)
- Amazon Linux 1 platforms only
- Default Values
ebextensions
- Any resources created as part of your
.ebextensionsis part of your Elastic Beanstalk template and will get deleted if the environment is terminated.- Folder: “
.ebextensions” - Files: YAML or JSON with the “.config” extension
- Folder: “
option_settings:
aws:elasticbeanstalk:environment:
LoadBalancerType: network
For Amazon Linux 2 platforms:
- Run custom code during instance provisioning
- Use Buildfile (in a root directory) to run a script for a short time
- Use a Procfile (in a root directory) for a long running processes
- Use Platform Hooks at the provisioning stages
- .platform/hooks/prebuild
- .platform/hooks/predeploy
- .platform/hooks/postbuild
Events
You can create rules in EventBridge to handle Beanstalk events:
- Environment Status (Create, Update, Terminate): start, success, fail
- Resource (ASG, ELB, EC2) Status: created, deleted
- Updates Status: start, fail


