AWS Elastic Beanstalk With Use Cases
AWS Elastic Beanstalk is a fully managed service that makes it easy to deploy, run, and scale web applications and services. You provide your code, and Beanstalk handles provisioning and managing the infrastructure: EC2 instances, load balancers, auto scaling, health monitoring, and application deployment.
Elastic Beanstalk Key points
- Supported platforms: Java, .NET, Node.js, Python, Ruby, PHP, Go, Docker, and more.
- Deployment models: Single instance, Load balanced + Auto Scaling, Worker environments (for background jobs via SQS).
- Configuration: Use configuration files (.ebextensions, platform hooks) and environment variables.
- Monitoring: Built-in health checks, logs, and metrics via CloudWatch.
- Rolling updates and blue/green deployments supported.
Example scenario: Deploy a Node.js web app
Goal: Deploy a simple Node.js Express app behind an Application Load Balancer with automatic scaling.
- Prepare your app
- App structure:
- package.json (specifies start script)
- app.js (Express server listening on process.env.PORT)
Example app.js:
const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
app.get('/', (req, res) => res.send('Hello from Elastic Beanstalk!'));
app.listen(port, () => console.log(`Server listening on ${port}`));
Example package.json:
{
"name": "eb-node-demo",
"version": "1.0.0",
"main": "app.js",
"scripts": { "start": "node app.js" },
"dependencies": { "express": "^4.18.2" }
}
Initialize Beanstalk (CLI)
- Install AWS EB CLI: pip install awsebcli
- Initialize the app:
eb init
# Choose region, platform (Node.js), and set up SSH key if desired
Create an environment and deploy
eb create eb-node-env \
--single # or omit --single to create a load-balanced, auto-scaling environment
# Wait until environment is ready
eb deploy
Access your app
eb open
This opens the environment URL like http://eb-node-env.us-east-1.elasticbeanstalk.com
Configure scaling and variables
- To run with a load balancer and auto scaling, create without --single:
#bash
eb create eb-node-prod
Set environment variables:
#bash
eb setenv NODE_ENV=production API_BASE_URL=https://api.example.com
Basic .ebextensions (optional)
Add .ebextensions/options.config to set instance type and health check path:
#yaml
option_settings:
aws:autoscaling:launchconfiguration:
InstanceType: t3.small
aws:elasticbeanstalk:application:
Application Healthcheck URL: /health
Blue/Green deployment (high level)
- Create a second environment (green), deploy and test there.
- Swap CNAMEs between green and blue environments from the console or:
#bash
eb swap --source eb-node-blue --destination eb-node-green
Typical use cases
- Quickly deploying web apps without managing infrastructure.
- Teams that want opinionated defaults for ALB, Auto Scaling, logs, and health checks.
- Worker environments for background processing with SQS.
When to choose Beanstalk
- You want managed infrastructure with minimal ops, but more control than pure serverless.
- You prefer pushing code over writing IaC for all components.
- You need rolling updates, health checks, and auto scaling out-of-the-box.
