Deploying Java Apps on AWS Elastic Beanstalk and RDS
Elastic Beanstalk (EB) simplifies provisioning and deployment while keeping control over the underlying AWS resources.
Steps
- Create a Dockerized Spring Boot app and push the image to ECR
- Provision an EB environment (load-balanced, rolling updates)
- Attach an RDS instance in the same VPC subnets
- Configure health checks to hit
/actuator/health/readiness - Enable blue/green for safe cutovers
Example Dockerrun.aws.json (v2)
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "api",
"image": "public.ecr.aws/your-repo/your-image:latest",
"essential": true,
"portMappings": [{ "containerPort": 8080, "hostPort": 8080 }],
"environment": [
{ "name": "SPRING_PROFILES_ACTIVE", "value": "prod" }
],
"memory": 512,
"cpu": 256
}
]
}
EB is a great on-ramp for teams standardizing on Docker without managing full Kubernetes.
Step-by-Step: Elastic Beanstalk Deployment
- Create Environment
- Use the EB CLI for convenience
pip install awsebcli --upgrade
eb init --platform docker --region ap-southeast-1 orders-eb
- Configure Health Checks
- In the EB console, set the health check URL to
/actuator/health/readiness
- Database with RDS
- Create an RDS instance in the same VPC/subnets as EB
- Add a security group rule to allow EB instances to connect to RDS
- Configure
SPRING_DATASOURCE_URL,SPRING_DATASOURCE_USERNAME,SPRING_DATASOURCE_PASSWORDin EB env vars
- Blue/Green Deployments
- Create a second EB environment (green)
- Swap CNAMEs after validating smoke tests
- Logs and Metrics
- Enable instance log streaming to CloudWatch
- Add
/actuator/prometheusand scrape with your monitoring stack if applicable
- Rolling Updates and Rollbacks
- Configure rolling with additional batch
- Keep last successful version to rollback quickly
Example GitHub Actions Workflow
name: Deploy to EB
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- run: ./gradlew clean build -x test
- run: zip -j build.zip Dockerrun.aws.json
- uses: einaregilsson/beanstalk-deploy@v22
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: orders-eb
environment_name: orders-eb-prod
region: ap-southeast-1
version_label: ${{ github.sha }}
deployment_package: build.zip