Elastic Beanstalk

Difficulty: Beginner

Question

What is AWS Elastic Beanstalk, what does it manage for you, and what are its deployment options?

Answer

AWS Elastic Beanstalk is a platform as a service that deploys and runs web applications on AWS for you: you upload your code, and it provisions EC2 instances, an Auto Scaling group, a load balancer, health monitoring and logging. It supports Java, .NET, PHP, Node.js, Python, Ruby, Go and Docker, there is no extra charge for Beanstalk itself, and you still have full access to the underlying resources.

What Beanstalk creates

When you create an environment, Beanstalk uses CloudFormation behind the scenes to build:

  • EC2 instances running a platform (for example "Node.js 20 on Amazon Linux 2023").
  • An Auto Scaling group with scaling triggers.
  • An Elastic Load Balancer (usually an ALB) for load-balanced environments, or a single instance for cheap dev setups.
  • Security groups, CloudWatch alarms, log rotation to S3 and enhanced health reporting.

Key terms:

  • Application: the logical container.
  • Application version: a specific uploaded bundle (zip or Docker image reference) stored in S3.
  • Environment: a running copy of one version, such as shop-prod or shop-staging.

Environment tiers

  • Web server tier: serves HTTP traffic behind a load balancer.
  • Worker tier: a daemon on each instance pulls messages from an SQS queue and POSTs them to your app on localhost, useful for background jobs like sending invoices or resizing images. It also supports periodic tasks via cron.yaml.

Deployment policies

PolicyHow it worksDowntimeRollback
All at onceDeploy to every instance togetherYesRedeploy old version
RollingUpdate instances in batchesNo, but reduced capacityRedeploy
Rolling with additional batchLaunch an extra batch first, keep full capacityNoRedeploy
ImmutableNew instances in a temporary ASG, swap when healthyNoFast, terminate new ASG
Traffic splittingCanary: send a percentage of traffic to new instancesNoFast

Blue/green is done outside these policies: create a second environment, deploy there, then swap environment URLs (CNAME swap).

Customizing the platform

  • .ebextensions/*.config files set option settings, install packages and create resources.
  • .platform/hooks/ and .platform/nginx/ customize Amazon Linux 2 and 2023 platforms, such as running a script before deploy or changing nginx settings.
  • Saved configurations and environment properties hold config and environment variables.

Trade-offs and gotchas

  • Do not create production RDS inside the environment. If you terminate the environment, the database goes with it. Create RDS separately and pass the endpoint in as an environment variable.
  • Platforms get retired as runtimes and OS versions age, so plan platform upgrades.
  • Beanstalk is great for a college project, an MVP or a small team's monolith. As teams grow they usually move to ECS, EKS or a CDK/Terraform-defined stack for finer control.
  • Compared with App Runner, Beanstalk gives you real EC2 instances you can SSH into and tune; App Runner hides the servers entirely.
Deploying with Elastic Beanstalk. From code bundle to a running, load-balanced environment.
  1. Package the app: Zip your code or reference a Docker image.
  2. Create application version: Bundle is stored in S3.
  3. Provision environment: CloudFormation builds EC2, ASG, ALB and alarms.
  4. Apply deployment policy: Rolling, immutable or traffic splitting.
  5. Monitor health: Enhanced health and logs show instance status.

Code examples

EB CLI workflow

pip install awsebcli

# Inside your project folder
eb init my-shop --platform node.js --region ap-south-1
eb create my-shop-prod --elb-type application --instance-types t3.small

# Set environment variables without baking them into the code
eb setenv NODE_ENV=production DB_HOST=mydb.xxxx.ap-south-1.rds.amazonaws.com

eb deploy           # upload a new version and deploy it
eb logs             # pull recent logs from instances
eb health --refresh # live instance health view

The EB CLI wraps the whole lifecycle; eb deploy creates a new application version and rolls it out using the environment's deployment policy.

Switching to immutable deployments

# .ebextensions/deploy.config
option_settings:
  aws:elasticbeanstalk:command:
    DeploymentPolicy: Immutable
  aws:autoscaling:asg:
    MinSize: 2
    MaxSize: 6

Immutable deployments launch fresh instances for each release, so a bad build never touches the instances serving live traffic.

Key points

  • Beanstalk is PaaS on top of EC2, Auto Scaling, ELB and CloudFormation, with no extra service charge.
  • Application, application version and environment are the core concepts.
  • Worker tier processes SQS messages; web tier serves HTTP.
  • Deployment policies: all at once, rolling, rolling with additional batch, immutable, traffic splitting; blue/green via CNAME swap.
  • Keep production databases outside the environment.

Common follow-up questions

  • How would you do a zero-downtime deployment on Elastic Beanstalk?
  • What is the difference between immutable and rolling deployments?
  • Why should RDS not be created inside a Beanstalk environment?
  • How does Elastic Beanstalk compare with App Runner and ECS?

Interview tips

  • Emphasise that you keep control of the underlying resources; it is not a black box.
  • Know the deployment policies and when you would pick immutable or blue/green.
  • Mention the RDS coupling mistake; it shows you have thought about production lifecycles.

Concepts covered

PaaS, Environments, Deployment Policies, ebextensions, Worker Tier, EB CLI

More AWS & Cloud Fundamentals questions