- November 23, 2020
- saptrxuy_learnit
- 0 Comments
- 1952 Views
- 1 Likes
- Java
Deploy Simple Spring Boot Web Application in AWS Elastic Beanstalk
1. Introduction
This document describes how to deploy simple spring boot web application in AWS Elastic Beanstalk. We need one spring boot project and account in AWS.
2. Create one spring boot web application
Create one simple spring boot web application, which will return ‘Hello World’ on RequestMapping(“/”)
3. Login to AWS account
https://signin.aws.amazon.com/signin?redirect_uri=https%3A%2F%2Fconsole.aws.amazon.com%2Fconsole%2Fhome%3Fstate%3DhashArgs%2523%26isauthcode%3Dtrue&client_id=arn%3Aaws%3Aiam%3A%3A015428540659%3Auser%2Fhomepage&forceMobileApp=0
After login, it will redirect to AWS Management Console
If you don’t have account in AWS, then create account and follow next step.
4. Create New Application in Elastic Beanstalk
4.1.What is AWS Elastic Beanstalk?
AWS Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.
we can simply upload code and Elastic Beanstalk automatically handles the deployment, from capacity provisioning, load balancing, auto-scaling to application health monitoring. At the same time, you retain full control over the AWS resources powering your application and can access the underlying resources at any time.
4.2.Click on Services
Next screen will show like below.
4.3. Create new application
Enter Application Name and description then click on Create.
Next screen will display like below:
4.4.Create Environment▲
Click on Create one now
Environment tier will have two options, we will use web server environment -> click on Select
4.5.Add Environment Information▲
Copy springboot-hello-world application name and paste in Domain section.
4.6.Configure platform in Base Configuration▲
Select Java platform in Base configuration.
4.7.Upload Jar in Application code▲
Select upload your code option and then click on upload
Next screen will show like below. Click on Browse
Select jar from your target project folder -> click on Open
Click on Upload
Click on Create environment
Next screen will come like below.
It will take few minutes.
After that next screen will display.
Copy highlighted url and paste in browser.
http://springboot-hello-world.ap-south-1.elasticbeanstalk.com/
We can see there is error 502 Bad Gateway.
5.Add port in Configuration▲
Click on Configuration -> Software -> Modify
Add SERVER_PORT 5000 in Environment properties -> click on Apply
By Default Elastic Beanstalk is running on port 5000.
6.Modify spring boot project and generate jar again▲
6.1.Downgrade the Java version in pom.xml▲
We can see on Amazon Linux Java 8 is running
In springboot project Java version is 11.
Change Java version from 11 to 1.8
6.2.Change server port in application.properties file▲
Simple spring boot project is running on port 9030.
Change server port to 5000. Because by default AWS Elastic Beanstalk is running on port 5000.
6.3.Run the spring boot project▲
We can see project is running fine.
7.Deploy spring boot application again in AWS▲
7.1.Upload jar again in AWS▲
Click on Upload and Deploy
Click on Browse
Click on Deploy
Next screen will show like below
Wait for some time, then next screen displays with no error or warning.
Click on url http://springboot-hello-world.ap-south-1.elasticbeanstalk.com/
Now there is no error, we successfully deployed spring boot web application AWS Elastic Beanstalk
Leave a Comment