Jomari AbejoJomari Abejo alternate
Jomari Abejo

Full Stack Developer

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

  1. Create a Dockerized Spring Boot app and push the image to ECR
  2. Provision an EB environment (load-balanced, rolling updates)
  3. Attach an RDS instance in the same VPC subnets
  4. Configure health checks to hit /actuator/health/readiness
  5. 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

  1. Create Environment
  • Use the EB CLI for convenience
pip install awsebcli --upgrade
eb init --platform docker --region ap-southeast-1 orders-eb
  1. Configure Health Checks
  • In the EB console, set the health check URL to /actuator/health/readiness
  1. 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_PASSWORD in EB env vars
  1. Blue/Green Deployments
  • Create a second EB environment (green)
  • Swap CNAMEs after validating smoke tests
  1. Logs and Metrics
  • Enable instance log streaming to CloudWatch
  • Add /actuator/prometheus and scrape with your monitoring stack if applicable
  1. 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