Deploy Spring Boot app to AWS Beanstalk

ぐ巨炮叔叔 提交于 2019-12-01 20:03:25

Easiest way to deploy Spring Boot to Beanstalk is to use the Spring Guide for converting your project to a WAR file. Then you just setup your Beanstalk application to use Tomcat and drag and drop the WAR file. AWS takes care of the rest.

EDIT: Based on what Maksim did

Step 1:

public class MyBootWebApp extends SpringBootServletInitializer {
    @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MyBootApp.class);
    }
}

Step 2: Change your pom.xml use <packaging>war</packaging>

You can easily deploy Spring Boot applications as jar file using Elastic Beanstalk. You don't even need boxfuse as described in the official Spring Boot guide. It is as easy as

Download the EB CLI, then in your spring boot project folder run

eb init

for the platform select option 2) java

add to the newly created .elasticbeanstalk/config.yml file this

deploy:
     artifact: target/spring-boot-aws-example-0.0.1-SNAPSHOT.jar

(change the jar name to a matching one)

then change your application to listen on port 5000 by adding this to your application.properties

server.port=5000

then do

# Prerequisite : generate deployment artifact
mvn clean install

# Create a load balancing, auto-scaling environment
eb create

The full details of the process are covered in my blog article : https://exampledriven.wordpress.com/2017/01/09/spring-boot-aws-elastic-beanstalk-example/

I don't really know enough about Beanstalk to be sure, but it looks to me like the Java container only supports WARs. You can still make the WAR executable for local (and non-Beanstalk) use (e.g. like in the gs guide).

Deploying Spring Boot project to AWS Beanstalk, preferably in a jar file:

  1. from the maven pom.xml change packaging to 'jar'
  2. from AWS Beanstalk --> create a new application
  3. inside the application --> create a new Environment
  4. from Selecting Environment Tier, choose --> Web Server Environment
  5. after in the web configuration --> From "Platform" have to be selected "Java" (Not Tomcat in this case, because will be provided a jar file which already includes embedded tomcat, the AWS Beanstalk provides us the hosting server where is established the Linux OS, JVM, and the compatible application to run with whatever is needed to support our app. If we would have deployed war file then the tomcat had to be selected)
  6. the Java platform support also 'jar' files to deploy (although is written .zip/.war)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!