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

TierPurposeUses
Web Server TierHandles HTTP/HTTPS requests from usersALB + EC2 instances + Auto Scaling
Worker TierProcesses background tasks from an SQS queueSQS 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:

StrategyHow It WorksDowntimeBest For
All at OnceDeploy to all instances simultaneouslyYes (brief outage)Development environments
RollingDeploy to a batch of instances at a timeReduced capacity during deployStaging environments
Rolling with Additional BatchLaunch new instances first, then deploy in batchesNo capacity lossProduction — zero capacity drop
ImmutableLaunch all new instances with new version, swap when healthyZero downtimeProduction — safest option
Blue/GreenDeploy to a new environment, swap URLs when readyZero downtimeProduction — 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

  1. Create a Django application locally with a requirements.txt and a Procfile defining the web server command.
  2. Run eb init to select the Python platform and Region.
  3. Run eb create django-api-prod — Beanstalk provisions ALB, EC2 (Auto Scaling group), security groups, and S3 for logs.
  4. Add environment variables (database URL, secret key) through the Elastic Beanstalk console.
  5. On code updates, run eb deploy — Beanstalk deploys with a Rolling strategy and zero downtime.

Elastic Beanstalk vs Other Options

FeatureElastic BeanstalkEC2 ManualLambda
Server managementManaged by AWSManaged by userNo servers
ControlFull (can customize EC2)FullLimited
DeploymentAutomated with strategiesManualAutomatic
Long-running processesYesYesMax 15 minutes
Best forTraditional web apps, APIsMaximum control neededEvent-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.

Leave a Comment