AWS Elastic Beanstalk¶
Service Overview and Purpose¶
AWS Elastic Beanstalk is a Platform-as-a-Service (PaaS) offering that makes it easy to deploy and manage applications in the AWS Cloud. You simply upload your code, and Elastic Beanstalk automatically handles the deployment details of capacity provisioning, load balancing, auto-scaling, and application health monitoring.
Core Purpose: - Simplify application deployment and management - Provide a platform-as-a-service (PaaS) solution - Enable rapid application development and deployment - Maintain full control over underlying AWS resources - Support multiple programming languages and frameworks
Key Features and Capabilities¶
Core Features¶
- Easy Deployment: Upload code and deploy with a few clicks
- Automatic Scaling: Built-in auto scaling and load balancing
- Health Monitoring: Application health dashboard and alerts
- Version Management: Application version control and rollback
- Configuration Management: Environment configuration templates
- Integration: Deep integration with AWS services
- Multiple Platforms: Support for various programming languages
- Cost Optimization: No additional charges for the service itself
Supported Platforms¶
- Java: Tomcat, Java SE
- NET: Windows Server with IIS
- .NET Core: Linux and Windows
- PHP: Apache HTTP Server
- Node.js: Node.js runtime
- Python: Apache HTTP Server with mod_wsgi
- Ruby: Passenger or Puma
- Go: Go runtime
- Docker: Docker containers
Deployment Options¶
- All at Once: Deploy to all instances simultaneously
- Rolling: Deploy in batches with zero downtime
- Rolling with Additional Batch: Deploy with additional instances
- Immutable: Deploy to fresh instances, then swap
- Blue/Green: Deploy to separate environment, then swap URLs
Use Cases and Scenarios¶
Primary Use Cases¶
- Web Applications
- Traditional three-tier web applications
- Content management systems
- E-commerce platforms
-
Blog and portfolio websites
-
API Development
- RESTful API backends
- Microservices development
- Third-party API integrations
-
Mobile app backends
-
Development and Testing
- Development environments
- Staging environments
- Proof of concepts
-
Prototyping
-
Legacy Application Migration
- Lift and shift migrations
- Application modernization
- Cloud-first development
-
Hybrid deployments
-
Educational and Learning
- Learning cloud development
- Student projects
- Training environments
- Experimentation platforms
Detailed Scenarios¶
E-commerce Platform¶
Frontend (React/Angular) β Load Balancer β Elastic Beanstalk (Node.js/Java)
β
RDS Database
β
S3 (Static Assets)
API Backend Service¶
Mobile/Web App β API Gateway β Elastic Beanstalk (Python/Java)
β
DynamoDB/RDS
β
ElastiCache (Caching)
Multi-Environment Pipeline¶
Development β Staging β Production
β β β
EB Environment β EB Environment β EB Environment
β β β
Git Repository β CI/CD Pipeline β Automated Deployment
WordPress Website¶
Users β CloudFront β Load Balancer β Elastic Beanstalk (PHP)
β
RDS (MySQL)
β
EFS (Shared Files)
Pricing Models and Cost Optimization¶
Pricing Structure¶
Elastic Beanstalk Service¶
- No Additional Charges: Elastic Beanstalk itself is free
- Pay for Resources: Only pay for underlying AWS resources
- Resource Costs: EC2, Load Balancers, Auto Scaling, etc.
Underlying Resource Costs¶
- EC2 Instances: Based on instance types and usage
- Load Balancers: Application Load Balancer or Classic Load Balancer
- Auto Scaling: No additional charges for Auto Scaling service
- Storage: EBS volumes, S3 storage for application versions
- Data Transfer: Standard AWS data transfer rates
Cost Optimization Strategies¶
- Right-size Instances
- Monitor application performance and resource usage
- Use appropriate instance types for workload
- Implement auto scaling to match demand
-
Consider Spot instances for development environments
-
Environment Management
- Terminate unused environments
- Use saved configurations for quick recreation
- Schedule environments for development/testing
-
Implement environment lifecycle policies
-
Load Balancer Optimization
- Choose appropriate load balancer type
- Use single AZ for development environments
- Implement health checks efficiently
-
Optimize target group configurations
-
Storage Optimization
- Clean up old application versions
- Use S3 lifecycle policies
- Optimize EBS volume types and sizes
-
Implement data compression
-
Monitoring and Alerts
- Set up cost alerts and budgets
- Monitor resource utilization regularly
- Use AWS Cost Explorer for analysis
- Implement resource tagging for cost allocation
Configuration Details and Best Practices¶
Environment Configuration¶
Basic Environment Setup¶
# .ebextensions/01-environment.config
option_settings:
aws:elasticbeanstalk:environment:
EnvironmentType: LoadBalanced
ServiceRole: aws-elasticbeanstalk-service-role
aws:elasticbeanstalk:environment:process:default:
HealthCheckPath: /health
Port: 80
Protocol: HTTP
aws:autoscaling:launchconfiguration:
InstanceType: t3.micro
IamInstanceProfile: aws-elasticbeanstalk-ec2-role
SecurityGroups: sg-12345678
aws:autoscaling:asg:
MinSize: 1
MaxSize: 4
Cooldown: 360
aws:elasticbeanstalk:healthreporting:system:
SystemType: enhanced
HealthCheckSuccessThreshold: Ok
Advanced Configuration¶
# .ebextensions/02-advanced.config
option_settings:
aws:elasticbeanstalk:application:environment:
DATABASE_URL: RDS_ENDPOINT
REDIS_URL: ELASTICACHE_ENDPOINT
S3_BUCKET: my-app-bucket
aws:elbv2:loadbalancer:
SecurityGroups: sg-12345678,sg-87654321
ManagedSecurityGroup: sg-managed
aws:elbv2:listener:443:
Protocol: HTTPS
SSLCertificateArns: arn:aws:acm:region:account:certificate/cert-id
aws:autoscaling:trigger:
MeasureName: CPUUtilization
Unit: Percent
UpperThreshold: 80
LowerThreshold: 20
BreachDuration: 300
Period: 300
EvaluationPeriods: 2
Statistic: Average
UpperBreachScaleIncrement: 1
LowerBreachScaleIncrement: -1
Database Configuration¶
# .ebextensions/03-database.config
option_settings:
aws:rds:dbinstance:
DBInstanceClass: db.t3.micro
DBEngine: mysql
DBEngineVersion: 8.0
MultiAZDatabase: false
DBAllocatedStorage: 20
DBUser: admin
DBPassword: mypassword
DeletionPolicy: Delete
Application Code Structure¶
Java Application (Spring Boot)¶
myapp/
βββ src/
β βββ main/
β βββ java/
β βββ resources/
β βββ application.properties
βββ .ebextensions/
β βββ 01-environment.config
β βββ 02-https.config
βββ pom.xml
βββ Procfile
# application.properties
server.port=5000
spring.datasource.url=${DATABASE_URL}
spring.profiles.active=${SPRING_PROFILES_ACTIVE:prod}
# Procfile
web: java -jar target/myapp-1.0.jar --server.port=$PORT
Node.js Application¶
myapp/
βββ app.js
βββ package.json
βββ .ebextensions/
β βββ nodecommand.config
βββ .npmrc
// app.js
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.get('/health', (req, res) => {
res.status(200).json({ status: 'healthy' });
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
# .ebextensions/nodecommand.config
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm start"
NodeVersion: 18.x
aws:elasticbeanstalk:application:environment:
NODE_ENV: production
Python Application (Django)¶
myapp/
βββ myproject/
β βββ settings.py
β βββ urls.py
β βββ wsgi.py
βββ requirements.txt
βββ .ebextensions/
β βββ python.config
βββ application.py
# application.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
application = get_wsgi_application()
# .ebextensions/python.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: application.py
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: myproject.settings
Best Practices¶
Application Design¶
- Stateless Applications
- Design applications to be stateless
- Store session data in external stores (Redis, DynamoDB)
- Use external databases, not local file storage
-
Implement proper logging to CloudWatch
-
Health Checks
- Implement application health check endpoints
- Monitor application-specific metrics
- Use meaningful health check responses
-
Configure appropriate timeouts
-
Configuration Management
- Use environment variables for configuration
- Store secrets in Systems Manager or Secrets Manager
- Use .ebextensions for infrastructure configuration
- Implement configuration validation
Deployment Best Practices¶
- Version Management
- Use semantic versioning for applications
- Tag application versions appropriately
- Maintain deployment history
-
Implement rollback procedures
-
Deployment Strategies
- Use rolling deployments for zero downtime
- Implement blue/green for critical applications
- Test deployments in staging environments
-
Automate deployment processes
-
Security
- Use IAM roles instead of access keys
- Implement HTTPS with SSL certificates
- Configure security groups appropriately
- Regular security updates and patches
Performance Optimization¶
- Auto Scaling
- Configure appropriate scaling triggers
- Monitor application performance metrics
- Use predictive scaling when possible
-
Implement proper cooldown periods
-
Load Balancing
- Use Application Load Balancers for HTTP/HTTPS
- Configure health checks properly
- Implement sticky sessions if needed
-
Optimize target group settings
-
Caching
- Implement application-level caching
- Use CloudFront for static content
- Configure browser caching headers
- Use ElastiCache for session storage
Integration with Other AWS Services¶
Core Integrations¶
- Amazon RDS
- Managed database integration
- Automatic connection string injection
- Database security group configuration
-
Backup and maintenance automation
-
Amazon S3
- Application version storage
- Static asset hosting
- Log file storage
-
Configuration file storage
-
Amazon CloudWatch
- Application and infrastructure monitoring
- Custom metrics and alarms
- Log aggregation and analysis
-
Performance dashboards
-
AWS Certificate Manager
- SSL/TLS certificate management
- Automatic certificate renewal
- Load balancer integration
-
Domain validation
-
Amazon VPC
- Network isolation and security
- Custom network configurations
- Private subnet deployments
- VPC endpoint integration
Advanced Integrations¶
- AWS CodePipeline
- Continuous integration and deployment
- Source code integration
- Automated testing and deployment
-
Multi-environment pipelines
-
Amazon ElastiCache
- Session storage and caching
- Performance optimization
- Database query caching
-
Application state management
-
Amazon SES
- Email sending capabilities
- Transactional email integration
- Bounce and complaint handling
-
Email analytics
-
AWS Systems Manager
- Parameter store integration
- Configuration management
- Patch management
-
Session manager access
-
Amazon CloudFront
- Content delivery network
- Static asset acceleration
- Geographic distribution
- SSL termination
CI/CD Integration Patterns¶
CodePipeline Integration¶
# buildspec.yml
version: 0.2
phases:
install:
runtime-versions:
java: corretto11
pre_build:
commands:
- echo Logging in to Amazon ECR...
build:
commands:
- echo Build started on `date`
- mvn clean package
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- target/*.jar
- .ebextensions/**/*
- Procfile
GitHub Actions Integration¶
# .github/workflows/deploy.yml
name: Deploy to Elastic Beanstalk
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: myapp
environment_name: myapp-prod
version_label: ${{ github.sha }}
region: us-west-2
deployment_package: deployment.zip
Security Considerations¶
Access Control¶
- IAM Roles and Policies
- Service role for Elastic Beanstalk
- Instance profile for EC2 instances
- Application-specific permissions
-
Cross-service access controls
-
Application Security
- Secure coding practices
- Input validation and sanitization
- Authentication and authorization
- Session management
Network Security¶
- VPC Configuration
- Private subnet deployments
- Security group configurations
- Network ACLs
-
VPC endpoints for AWS services
-
Load Balancer Security
- HTTPS termination
- Security group rules
- Access logging
- DDoS protection
Data Protection¶
- Encryption
- HTTPS for data in transit
- Database encryption at rest
- S3 bucket encryption
-
Log encryption
-
Secrets Management
- Environment variables for non-sensitive config
- Systems Manager Parameter Store for secrets
- AWS Secrets Manager for database credentials
- Regular secret rotation
Compliance and Governance¶
- Monitoring and Auditing
- CloudTrail for API logging
- VPC Flow Logs for network traffic
- Application access logs
-
Security event monitoring
-
Patch Management
- Regular platform updates
- Application dependency updates
- Security patch automation
- Vulnerability scanning
Monitoring and Troubleshooting¶
CloudWatch Metrics¶
Environment Health Metrics¶
- EnvironmentHealth: Overall environment health
- ApplicationRequests2xx: Successful HTTP requests
- ApplicationRequests4xx: Client error HTTP requests
- ApplicationRequests5xx: Server error HTTP requests
- ApplicationRequestsTotal: Total HTTP requests
- ApplicationLatencyP50: 50th percentile latency
- ApplicationLatencyP95: 95th percentile latency
- ApplicationLatencyP99: 99th percentile latency
Instance Metrics¶
- CPUUtilization: CPU usage percentage
- NetworkIn: Network bytes received
- NetworkOut: Network bytes transmitted
- DiskReadOps: Disk read operations
- DiskWriteOps: Disk write operations
- StatusCheckFailed: Instance status check failures
Load Balancer Metrics¶
- RequestCount: Number of requests
- TargetResponseTime: Response time from targets
- HealthyHostCount: Number of healthy targets
- UnHealthyHostCount: Number of unhealthy targets
- HTTPCode_Target_2XX_Count: Successful responses from targets
Health Monitoring¶
Application Health Dashboard¶
# Health check configuration
option_settings:
aws:elasticbeanstalk:healthreporting:system:
SystemType: enhanced
HealthCheckSuccessThreshold: Ok
EnhancedHealthAuthEnabled: true
aws:elasticbeanstalk:environment:process:default:
HealthCheckPath: /health
HealthCheckInterval: 15
HealthyThresholdCount: 3
UnhealthyThresholdCount: 5
Custom Health Check Endpoint¶
// Node.js health check
app.get('/health', (req, res) => {
const healthcheck = {
uptime: process.uptime(),
message: 'OK',
timestamp: Date.now(),
checks: {
database: 'connected',
cache: 'connected'
}
};
try {
res.status(200).send(healthcheck);
} catch (error) {
healthcheck.message = error;
res.status(503).send(healthcheck);
}
});
Common Troubleshooting Scenarios¶
- Deployment Failures
- Application startup errors
- Configuration issues
- Dependency problems
-
Health check failures
-
Performance Issues
- High response times
- Memory leaks
- Database connection issues
-
Resource constraints
-
Scaling Issues
- Auto scaling not triggering
- Instances failing health checks
- Load balancer configuration
-
Target group registration
-
Connectivity Issues
- Database connection failures
- External service timeouts
- Network configuration problems
- Security group misconfigurations
Debugging Tools and Techniques¶
Log Analysis¶
# Download log files
eb logs
# Stream logs in real-time
eb logs --all
# Download specific log files
aws s3 cp s3://elasticbeanstalk-region-account/resources/environments/logs/ . --recursive
Environment Debugging¶
# Check environment status
eb status
# Describe environment health
eb health
# Connect to instance via SSH
eb ssh
# Deploy with verbose output
eb deploy --verbose
CloudWatch Logs Integration¶
# .ebextensions/cloudwatch-logs.config
option_settings:
aws:elasticbeanstalk:cloudwatch:logs:
StreamLogs: true
DeleteOnTerminate: false
RetentionInDays: 7
aws:elasticbeanstalk:cloudwatch:logs:health:
HealthStreamingEnabled: true
DeleteOnTerminate: false
RetentionInDays: 7
Exam-Specific Tips and Common Scenarios¶
Solutions Architect Associate (SAA-C03)¶
- PaaS vs IaaS: When to use Elastic Beanstalk vs EC2
- Deployment Strategies: Rolling, blue/green, immutable deployments
- Integration Patterns: RDS, S3, CloudFront integration
- Cost Considerations: Free tier usage and optimization
Solutions Architect Professional (SAP-C02)¶
- Enterprise Deployment: Large-scale application deployment
- Multi-Environment: Development, staging, production pipelines
- Advanced Networking: VPC, private subnets, hybrid connectivity
- Compliance: Security and governance requirements
Developer Associate (DVA-C02)¶
- Application Development: Platform-specific development practices
- CI/CD Integration: Automated deployment pipelines
- Debugging: Application troubleshooting techniques
- Version Management: Application version control
SysOps Administrator (SOA-C02)¶
- Environment Management: Day-to-day operations
- Monitoring Setup: CloudWatch and health monitoring
- Performance Tuning: Application and infrastructure optimization
- Security Operations: Security best practices and monitoring
Common Exam Scenarios¶
-
Scenario: Deploy a web application quickly without infrastructure management Solution: Use Elastic Beanstalk with appropriate platform
-
Scenario: Need zero-downtime deployments Solution: Configure rolling or blue/green deployment strategies
-
Scenario: Integrate with existing AWS services Solution: Use .ebextensions and environment variables
-
Scenario: Multi-environment development workflow Solution: Multiple Elastic Beanstalk environments with CI/CD
-
Scenario: Legacy application migration to cloud Solution: Containerize or adapt for Elastic Beanstalk platform
Hands-on Examples and CLI Commands¶
Environment Management¶
# Initialize Elastic Beanstalk application
eb init myapp --platform node.js --region us-west-2
# Create environment
eb create production --instance-type t3.small --cname myapp-prod
# Deploy application
eb deploy
# Check environment status
eb status
# View environment health
eb health
# Scale environment
eb scale 4
# Set environment variables
eb setenv DATABASE_URL=mysql://user:pass@host:port/db
# Terminate environment
eb terminate production
Configuration Management¶
# Save environment configuration
eb config save production --cfg prod-config
# Create environment from saved configuration
eb create staging --cfg prod-config
# Update configuration
eb config production
# List saved configurations
eb config list
# Delete saved configuration
eb config delete prod-config
Application Version Management¶
# List application versions
aws elasticbeanstalk describe-application-versions \
--application-name myapp
# Create application version
aws elasticbeanstalk create-application-version \
--application-name myapp \
--version-label v1.2.0 \
--source-bundle S3Bucket=my-bucket,S3Key=myapp-v1.2.0.zip
# Deploy specific version
aws elasticbeanstalk update-environment \
--environment-name production \
--version-label v1.2.0
# Delete application version
aws elasticbeanstalk delete-application-version \
--application-name myapp \
--version-label v1.1.0 \
--delete-source-bundle
Monitoring and Logs¶
# View recent events
eb events
# Download logs
eb logs --all
# Stream logs
eb logs --all --stream
# Get CloudWatch metrics
aws cloudwatch get-metric-statistics \
--namespace AWS/ElasticBeanstalk \
--metric-name ApplicationRequests2xx \
--dimensions Name=EnvironmentName,Value=production \
--statistics Sum \
--start-time 2023-01-01T00:00:00Z \
--end-time 2023-01-01T23:59:59Z \
--period 3600
Advanced Operations¶
# Create application
aws elasticbeanstalk create-application \
--application-name myapp \
--description "My web application"
# Create environment
aws elasticbeanstalk create-environment \
--application-name myapp \
--environment-name production \
--solution-stack-name "64bit Amazon Linux 2 v5.4.0 running Node.js 18" \
--option-settings file://options.json
# Update environment
aws elasticbeanstalk update-environment \
--environment-name production \
--option-settings file://update-options.json
# Swap environment URLs
aws elasticbeanstalk swap-environment-cnames \
--source-environment-name production \
--destination-environment-name staging
This comprehensive Elastic Beanstalk documentation provides detailed coverage for all AWS certification paths, including practical deployment examples and real-world application scenarios.