AWS Elastic Beanstalk
AWS Elastic Beanstalk is a Platform as a Service (PaaS) that deploys and manages web applications and services automatically. The developer uploads application code, and Elastic Beanstalk handles the deployment details — provisioning EC2 instances, setting up the load balancer, configuring Auto Scaling, and monitoring the application.
Elastic Beanstalk sits between raw EC2 (where everything is configured manually) and serverless Lambda (where servers are completely hidden). It offers the control of EC2 with the convenience of managed deployment.
The Problem Elastic Beanstalk Solves
Deploying a web application on EC2 involves many steps: launching instances, installing a web server, configuring security groups, setting up a load balancer, enabling Auto Scaling, configuring monitoring, and handling deployments on each update. For many developers, this is time-consuming and error-prone.
Elastic Beanstalk handles all of this automatically. The developer focuses on the application code. Beanstalk handles the rest — and still provides full access to the underlying resources (EC2, RDS, etc.) if customization is needed.
Supported Platforms
Elastic Beanstalk supports many popular application platforms:
- Python
- Node.js
- Java (Tomcat)
- PHP
- Ruby
- Go
- .NET on Windows Server
- Docker (single container and multi-container)
- Docker Compose
Elastic Beanstalk Core Concepts
Application
An Elastic Beanstalk application is a logical grouping of environments and versions. Think of it as the project name — for example, "my-online-store".
Application Version
Each time new code is uploaded, a new application version is created. Versions are stored in S3. Previous versions are retained, allowing rollback to an earlier version at any time.
Environment
An environment is a running deployment of a specific application version. Multiple environments can exist for the same application — for example, separate environments for development, staging, and production, each with different configurations.
Application: my-online-store | +-- Environment: production (v1.5 — 4 EC2 instances, RDS, ALB) +-- Environment: staging (v1.6 — 2 EC2 instances, test RDS) +-- Environment: development (v1.7 — 1 EC2 instance, no RDS)
Environment Tiers
| Tier | Purpose | Uses |
|---|---|---|
| Web Server Tier | Handles HTTP/HTTPS requests from users | ALB + EC2 instances + Auto Scaling |
| Worker Tier | Processes background tasks from an SQS queue | SQS Queue + EC2 instances |
How Elastic Beanstalk Deploys an Application
Developer uploads application code (ZIP or WAR file)
|
Elastic Beanstalk provisions:
+------------------------------------------+
| [EC2 Instances] [Security Groups] |
| [Application Load Balancer] |
| [Auto Scaling Group] |
| [CloudWatch Monitoring] |
| [S3 for logs and application versions] |
+------------------------------------------+
|
Application is live at:
my-online-store.ap-south-1.elasticbeanstalk.com
Deployment Strategies
Elastic Beanstalk supports multiple deployment strategies to balance speed, availability, and risk:
| Strategy | How It Works | Downtime | Best For |
|---|---|---|---|
| All at Once | Deploy to all instances simultaneously | Yes (brief outage) | Development environments |
| Rolling | Deploy to a batch of instances at a time | Reduced capacity during deploy | Staging environments |
| Rolling with Additional Batch | Launch new instances first, then deploy in batches | No capacity loss | Production — zero capacity drop |
| Immutable | Launch all new instances with new version, swap when healthy | Zero downtime | Production — safest option |
| Blue/Green | Deploy to a new environment, swap URLs when ready | Zero downtime | Production — full rollback capability |
Blue/Green Deployment — Detailed
BEFORE SWAP: Blue Environment (current - v1.0): users.myapp.com → [4 EC2 instances] Green Environment (new - v2.0): green.myapp.com → [4 EC2 instances] TEST green environment → all looks good AFTER SWAP (Route 53 or CNAME swap): Blue Environment (old - v1.0): available for rollback Green Environment (new - v2.0): users.myapp.com → [now serving all users] If v2.0 has issues → swap back to Blue instantly
Elastic Beanstalk Configuration with .ebextensions
Custom configuration is added through .ebextensions — a folder inside the application package containing YAML or JSON configuration files. These files run commands, install software, configure environment variables, and set up resources when an environment starts.
Example .ebextensions/install-packages.config — install additional packages on EC2 instances:
packages:
yum:
git: []
nginx: []
commands:
01_install_node:
command: "curl -sL https://rpm.nodesource.com/setup_18.x | bash -"
Elastic Beanstalk and RDS
A database can be created directly inside an Elastic Beanstalk environment or connected externally as a separate RDS instance.
- Inside the environment: Easy setup, but the database is tied to the environment — deleting the environment deletes the database. Not recommended for production.
- External RDS (recommended for production): The RDS instance is created separately. The environment is given the RDS connection string via environment variables. This way, the database persists even if the environment is terminated.
Elastic Beanstalk CLI
The EB CLI (Elastic Beanstalk Command Line Interface) is a dedicated tool for managing Beanstalk environments from the terminal:
eb init # Initialize application and configure Region eb create prod # Create a new environment named "prod" eb deploy # Deploy latest code to the current environment eb open # Open the application URL in the browser eb logs # Retrieve application logs eb terminate # Terminate the environment and all resources
Real-World Example — Deploying a Django REST API
- Create a Django application locally with a
requirements.txtand aProcfiledefining the web server command. - Run
eb initto select the Python platform and Region. - Run
eb create django-api-prod— Beanstalk provisions ALB, EC2 (Auto Scaling group), security groups, and S3 for logs. - Add environment variables (database URL, secret key) through the Elastic Beanstalk console.
- On code updates, run
eb deploy— Beanstalk deploys with a Rolling strategy and zero downtime.
Elastic Beanstalk vs Other Options
| Feature | Elastic Beanstalk | EC2 Manual | Lambda |
|---|---|---|---|
| Server management | Managed by AWS | Managed by user | No servers |
| Control | Full (can customize EC2) | Full | Limited |
| Deployment | Automated with strategies | Manual | Automatic |
| Long-running processes | Yes | Yes | Max 15 minutes |
| Best for | Traditional web apps, APIs | Maximum control needed | Event-driven, short tasks |
Summary
- Elastic Beanstalk deploys web applications automatically by provisioning EC2, ALB, Auto Scaling, and monitoring.
- Supported platforms include Python, Node.js, Java, PHP, Ruby, .NET, Go, and Docker.
- Multiple environments (dev, staging, production) are managed within one application.
- Deployment strategies — All-at-Once, Rolling, Immutable, and Blue/Green — offer flexibility based on downtime tolerance.
- All underlying resources remain accessible — Elastic Beanstalk provides managed convenience without removing control.
