What is Elastic Beanstalk?
Elastic Beanstalk (EB) is a Platform as a Service (PaaS) by AWS that helps developers deploy and manage applications in the cloud—without managing the underlying infrastructure.
You just upload your code, and Beanstalk:
- Handles provisioning (EC2, ELB, Auto Scaling, etc.)
- Monitors the health of your app
- Manages deployments
- Supports multiple languages: Python, Node.js, Java, PHP, Ruby, .NET, Go, and Docker
Why Use Elastic Beanstalk?
Feature | Description |
---|---|
Fully Managed | No need to manage servers or scaling manually |
Fast Deployment | Upload code + config and it’s live |
Customizable | Full control of underlying EC2, VPC, Security |
Built-in Monitoring | Comes with CloudWatch integration |
Supports CI/CD | Works with CodePipeline & GitHub Actions |
Supported Architectures
- Single-instance: Good for dev/test environments
- Load-balanced + Auto-scaled: Great for production
- Worker Environment: For background jobs (e.g., SQS consumers)
Step-by-Step: Deploy a Python Web App to Elastic Beanstalk
Let’s deploy a simple Flask app:
Step 1: Set Up the Project Locally
mkdir flask-eb-demo && cd flask-eb-demo
python3 -m venv venv
source venv/bin/activate
pip install flask
Create application.py
:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "Hello from Elastic Beanstalk!"
if __name__ == "__main__":
app.run()
Create requirements.txt
:
Flask==2.2.2
Create Procfile
:
web: gunicorn application:app
Step 2: Install EB CLI
pip install awsebcli
Configure it:
aws configure
Step 3: Initialize and Deploy
eb init -p python-3.8 flask-eb-demo
- Choose region
- Create or use an existing Elastic Beanstalk app
- Link to your Git repo if available
Then create an environment:
eb create flask-env
To deploy:
eb deploy
To open the app in your browser:
eb open
Securing Your Environment
- Use HTTPS with SSL certs via ACM
- Set env variables using:
eb setenv KEY=value ANOTHER=value
- Restrict EC2 access via security groups
Monitoring & Logs
Elastic Beanstalk provides:
- Health Monitoring Dashboard
- CloudWatch Logs
- Auto Recovery options
- Alarms for CPU, memory, latency, etc.
To pull logs:
eb logs
Advanced: CI/CD with GitHub Actions
Example .github/workflows/deploy.yml
:
name: Deploy to Elastic Beanstalk
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: "flask-eb-demo"
environment_name: "flask-env"
version_label: ${{ github.sha }}
region: "us-east-1"
When Not to Use Elastic Beanstalk
- If you need fine-grained container orchestration → use ECS or EKS
- If you want ultra-low latency and edge computing → use Lambda + API Gateway
💬 Final Thoughts
Elastic Beanstalk is perfect for:
- Quick deployments
- Projects where you don’t want to manage infra
- Teaching DevOps concepts (CI/CD, monitoring, scaling)
You get control without complexity.