Want to push a Spring Boot JAR to the cloud and pretend you know what you are doing? Good news, this is boringly repeatable and only mildly magical. Follow these steps to build an executable JAR with Maven and manage deployments with the EB CLI on AWS Elastic Beanstalk. Keywords you care about include Java Spring Boot AWS Elastic Beanstalk JAR Maven and EB CLI. Yes those were intentional.
Make a reproducible artifact first. Maven will wrap up your Spring Boot app into an executable JAR if your pom includes the Spring Boot plugin. No mystical incantations required.
mvn clean package -DskipTests
# produced file will be in target, for example target/myapp.jar
Verify the JAR runs locally. If it does not run with java -jar then Elastic Beanstalk will not be thrilled either.
From the project root run the EB CLI setup. It writes config so future deploys are less annoying.
eb init
When prompted pick a region and the Java platform. The CLI will create the .elasticbeanstalk directory with the necessary mapping to your AWS account.
Make an environment and push your first version. Beanstalk will provision instances and wire the load balancer, which is honestly the part of cloud that feels like actual magic.
eb create my-env
# after packaging again for changes
mvn clean package -DskipTests
eb deploy
For iterative updates simply repackage with Maven and run eb deploy. The platform handles instance lifecycle for you unless you enjoy manual server babysitting.
Do not bake secrets into code. Use environment variables for profiles, database hosts, and JVM flags. Use the EB CLI or the AWS console to set these.
eb setenv SPRING_PROFILES_ACTIVE=prod DB_HOST=db.example.com
# add JVM settings if you need more heap
eb setenv JAVA_OPTS='-Xmx512m -XX:+UseG1GC'
Health checks must match your Spring Boot actuator endpoints. If you use the actuator health endpoint set the Beanstalk health check path to /actuator/health
in the environment settings so the load balancer does not keep restarting things that are actually fine.
When your app flails use these commands to look at the scene of the crime.
eb logs
eb health
Common fixes include:
Create a Procfile at the project root to explicitly tell Beanstalk how to launch your app. This often saves a lot of guesswork.
Procfile
web: java -Dserver.port=$PORT -Xmx512m -jar myapp.jar
Commit that file before packaging and deploying. Adjust the JVM flags to taste and to the size of your wallet.
There you go. You now have a repeatable flow to package a Spring Boot JAR with Maven and manage deployments to AWS Elastic Beanstalk with the EB CLI. It will not be glamorous but it will be reliable which is a solid replacement for glamour in production.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.