Skip to content

Configure Spring Boot on Elastic Beanstalk

This tutorial covers the main configuration layers for Spring Boot on Elastic Beanstalk: application properties, environment properties, Procfile, and .ebextensions. The objective is to make runtime settings explicit, source-controlled, and repeatable across environments.

Prerequisites

  • Running Java Elastic Beanstalk environment.
  • Spring Boot app deployed once successfully.
  • Familiarity with Maven packaging and the PORT contract.

What You'll Build

You will build:

  • Environment-property driven application configuration.
  • A source-controlled health check and JVM tuning baseline.
  • A Procfile startup contract for the JAR.
flowchart TD
    A[application.properties] --> D[Spring Environment]
    B[EB Environment Properties] --> D
    C[.ebextensions option_settings] --> E[Elastic Beanstalk Platform]
    E --> F[nginx plus Java Process]
    D --> F
    G[Procfile] --> F

Steps

  1. Keep port binding inside application.properties.
server.port=${PORT:5000}
spring.application.name=aws-eb-java-reference
logging.level.root=${LOG_LEVEL:INFO}
app.environment=${ENV_NAME:local}
  1. Set runtime environment properties through Elastic Beanstalk.
eb setenv ENV_NAME=production APP_VERSION=2026-04-07 LOG_LEVEL=INFO FEATURE_DEMO=true
  1. Read those values in Spring Boot.
package com.example.guide.controller;

import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConfigController {
    @Value("${app.environment:local}")
    private String environment;

    @GetMapping("/demo/config")
    public Map<String, String> config() {
        return Map.of("environment", environment);
    }
}
  1. Keep the startup command in Procfile.
web: java -jar target/guide-0.0.1-SNAPSHOT.jar
  1. Add a health check path and JVM options with .ebextensions.
option_settings:
    aws:elasticbeanstalk:environment:process:default:
        HealthCheckPath: /health
    aws:elasticbeanstalk:container:java:jvmoptions:
        Xms: 256m
        Xmx: 512m
        XX: +UseG1GC
  1. Add an environment file for a larger example.
option_settings:
    aws:elasticbeanstalk:application:environment:
        SPRING_PROFILES_ACTIVE: prod
        SERVER_FORWARD_HEADERS_STRATEGY: framework
  1. Redeploy configuration changes.
eb deploy --staged

Verification

Use these checks after applying configuration:

eb printenv
eb config
eb logs --all
curl --verbose "http://$CNAME/demo/env"

Expected outcomes:

  • Environment properties are visible in Elastic Beanstalk.
  • The app reads expected values without hardcoding secrets.
  • /health remains the configured health check path.
  • JVM settings are captured in source-controlled config files.

See Also

Sources