SkillSprout
Chapter 7 · Lesson 3
Intermediate
6 min read

AWS Elastic Beanstalk

Overview

AWS Elastic Beanstalk is a platform-as-a-service that deploys and runs web applications without you wiring up the infrastructure. Upload your code (Java, .NET, Node.js, Python, PHP, Ruby, Go or a Docker container) and Beanstalk provisions EC2 instances, an Auto Scaling group, a load balancer, health monitoring and CloudWatch, while you retain full access to the resources.

Think of renting a fully furnished apartment. You bring your belongings (the app), and the building handles plumbing, power and maintenance, but you can still rearrange the furniture (configuration) if you want.

Elastic Beanstalk is popular on the exam for deployment policy choices and for customising environments with .ebextensions.

Key Concepts

  • Core concepts: application (logical container), application version (labelled deployable in S3), environment (running version with AWS resources), platform (OS + runtime).
  • Web server tier (ALB + instances) and worker tier (instances polling an SQS queue via a daemon, with cron.yaml for periodic tasks).
  • Deployment policies: All at once, Rolling, Rolling with additional batch, Immutable, Traffic splitting (canary); Blue/green via environment CNAME swap.
  • .ebextensions/*.config (YAML/JSON) customise packages, files, commands, options and extra AWS resources; Procfile/Buildfile and platform hooks add control.
  • Managed platform updates and health reporting (basic or enhanced) keep environments patched and observable.
  • A RDS database created inside an environment is deleted with it; for production create it outside and pass connection info.
  • EB CLI commands: eb init, create, deploy, status, logs, swap, terminate.
  • Environment variables, scaling, instance types and the load balancer are set in configuration options, stored as saved configurations.

Detailed Notes

Deployment policies

PolicyDowntimeCapacity during deployRollbackExtra cost
All at onceYes (brief)Reduced to 0RedeployNone
RollingNoReduced by batch sizeRedeployNone
Rolling with additional batchNoFull (new batch added first)RedeploySmall
ImmutableNoFullTerminate new ASG (fast, safe)Temporarily 2x
Traffic splittingNoFullQuick, canary share of trafficTemporarily 2x
Blue/green (swap)NoFullSwap backTwo environments

Rule of thumb: dev uses all at once for speed, production uses immutable or traffic splitting, and blue/green for major changes such as platform upgrades or database migrations.

EB CLI workflow

bash
eb init my-app --platform python-3.12 --region eu-west-1
eb create my-app-prod --elb-type application --instance_type t3.small
eb setenv DB_HOST=mydb.example.internal STAGE=prod
eb deploy
eb status
eb logs
eb swap my-app-green --destination_name my-app-prod

Customising with .ebextensions

yaml
# .ebextensions/01-app.config
option_settings:
  aws:elasticbeanstalk:application:environment:
    LOG_LEVEL: info
  aws:autoscaling:asg:
    MinSize: 2
    MaxSize: 6
  aws:elasticbeanstalk:command:
    DeploymentPolicy: Immutable
packages:
  yum:
    git: []
files:
  "/etc/myapp/config.json":
    mode: "000644"
    content: |
      {"feature": true}
container_commands:
  01_migrate:
    command: "python manage.py migrate"
    leader_only: true
Resources:
  OrdersQueue:
    Type: AWS::SQS::Queue

Files must be in the .ebextensions directory at the root of the source bundle with a .config extension. container_commands run after the app is extracted, and leader_only runs on one instance only, which suits database migrations.

Beanstalk and Docker

A Dockerrun.aws.json or docker-compose.yml in the bundle defines containers. For multi-container, the modern platform uses Amazon ECS under the hood.

Worker environments

The worker daemon reads messages from SQS and POSTs them to your app at a local HTTP path. A message is deleted if the app returns 200; otherwise it returns to the queue after the visibility timeout. Use a DLQ for poison messages. cron.yaml schedules recurring POSTs.

Health and scaling

  • Enhanced health reports colour-coded states (Ok, Warning, Degraded, Severe) using the health agent and ALB metrics.
  • Scaling triggers (CPU, network, request count) are set in configuration options.
  • Managed updates apply minor/patch platform updates during a maintenance window.

When not to use Beanstalk

If you need fine-grained container orchestration, microservices or fully serverless economics, choose ECS/EKS/Fargate or Lambda. If you need full control of each resource and IaC, use CloudFormation or CDK.

Cloning and swapping

Create a blue/green by cloning the environment, deploying the new version to the clone, testing and then swapping CNAMEs. Swapping changes DNS records, so clients with cached DNS may take a little time to move.

Customising instances with .ebextensions

Place YAML or JSON *.config files in an .ebextensions/ folder inside the source bundle to install packages, create files, run commands and set options. Newer platforms also support a Buildfile, Procfile and .platform/hooks scripts.

yaml
# .ebextensions/01-settings.config
option_settings:
  aws:elasticbeanstalk:application:environment:
    LOG_LEVEL: info
  aws:autoscaling:asg:
    MinSize: 2
    MaxSize: 6
  aws:elasticbeanstalk:environment:process:default:
    HealthCheckPath: /health
packages:
  yum:
    jq: []
container_commands:
  01_migrate:
    command: "python manage.py migrate"
    leader_only: true

Deployment policies compared

PolicyCapacity during deployDowntimeRollback speed
All at onceFull, single stepYes, briefRedeploy
RollingReduced by batch sizeNoRedeploy
Rolling with additional batchFull capacity keptNoRedeploy
ImmutableNew instances alongside oldNoFast; terminate new ASG
Traffic splittingNew instances receive a percentage firstNoFast
Blue/green (CNAME swap)Separate environmentNoSwap back

EB CLI and lifecycle

bash
eb init -p python-3.12 orders --region eu-west-1
eb create orders-prod --elb-type application --instance_profile eb-instance-role
eb deploy --staged
eb setenv DB_HOST=db.example.internal
eb logs --all
eb swap orders-green --destination_name orders-prod

Beanstalk creates the Auto Scaling group, load balancer and CloudWatch alarms for you through CloudFormation, but you still own the code, instance profile and database. Use enhanced health reporting for colour-coded environment health, store credentials in Secrets Manager rather than environment properties, and apply managed platform updates in a maintenance window. Retain application versions in S3 with an application version lifecycle policy so old bundles are cleaned up.

Real World Example

A mid-sized publisher hosts its Django CMS on Elastic Beanstalk. For routine releases they use Immutable deployments: Beanstalk launches a fresh set of instances, health-checks them, then replaces the old ones; any failure simply terminates the new ones. Before upgrading the Python platform they cloned the environment, deployed to the clone and performed a CNAME swap after testing. The RDS database sits outside the environment so it survives environment replacement.

Architecture Diagram

Elastic Beanstalk web environment
Architecture
AWS Cloud
Users

Beanstalk environment

ALB
Auto ScalingEC2 instances
RDS (external)
Version in S3

Beanstalk provisions and manages the load balancer, Auto Scaling group and instances.

  1. 1You upload an application version to S3 through the EB CLI.
  2. 2Beanstalk applies the selected deployment policy to the environment.
  3. 3The ALB routes traffic to healthy instances.
  4. 4Enhanced health and CloudWatch metrics drive scaling and alerts.

Best Practices

  • ✓Create RDS outside production environments.
  • ✓Use Immutable or traffic splitting for production, blue/green for major changes.
  • ✓Keep config in .ebextensions and saved configurations in source control.
  • ✓Enable enhanced health reporting and managed platform updates.
  • ✓Use a worker tier with SQS for background jobs.

Common Interview Questions

Exam Tips

DVA-C02 focus

  • Zero-downtime with full capacity and easy rollback -> Immutable or Blue/green.
  • Lowest cost deploy for dev -> All at once.
  • Customisation -> .ebextensions (.config files).
  • Background job processing -> worker environment (SQS).

Finished this lesson?

0 of 46 lessons done · 0% of the course