AWS Elastic Beanstalk is a fully managed service that makes it easy to deploy, operate, and scale web applications in the AWS Cloud. It’s especially well-suited for Spring Boot projects because it provides a simple, cost-effective way to run and grow Java applications—without the need to manage servers, load balancers, or infrastructure.
In this article, we’ll walk through how to create a simple Spring Boot web application and deploy it to AWS Elastic Beanstalk.
Creating the Spring Boot Application
Step 1: Generate a Basic Spring Boot Project
Start by creating a simple Spring Boot application using the spring-boot-starter-web dependency.
The easiest way to generate the project structure is by using Spring Initializr, where you can configure your project settings, add dependencies, and download a ready-to-use application template.
Step 2: Make a new package called com.example.demo.controller and create a HelloWorldController controller class. We've constructed a REST API that outputs a "Hello" message.
package com.example.demo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@GetMapping("/")
public String helloWorld() {
return "hello ";
}
}
Step 3: Add the configuration property shown below to the application.properties file of the spring boot application located in the src/main/resources folder. AWS Elastic Beanstalk anticipates that our app will listen on port 5000. This variable must be set in order for our spring boot application to listen on port 5000.
server.port=5000
Step 4: The spring boot application's final project structure is shown below.

**Step 5: **We can run the application locally by Right-clicking on the project > Run as > Spring boot app in our IDE. The application runs locally, and we can access our REST API at http://localhost:5000/.
Deploy Spring Boot App to AWS Elastic Beanstalk
Step 1: We must create the spring boot jar file, which includes the integrated Tomcat server. We can start the Maven build in STS or Eclipse by Right-clicking on the project and selecting Run as > Maven install. The maven build tool will generate our application as a jar file in the project's target/ subdirectory.

Step 2: To deploy our application, we have to navigate on the Elastic Beanstalk service, as shown below.
Step 3: Click on the Create Application button to create a new application.
Step 4: Fill up the application name field with a name. In this case, we will call our application my-spring-app.
Step 5: Then, under the platform section, select the platform details. We chose Java as the platform since we want to launch a Java application.
Select the Upload your code option beneath the Application code area as well.
Step 6: Finally, choose the spring boot application jar file created by the maven build, as shown below.

Step 7: When you click the Create application button, the application begins to be deployed into the AWS elastic beanstalk.

Step 8: When the application is successfully deployed, an entry appears under Environments, as seen below.

**Step 9: **We can also observe that the application's health is OK and that the Recent events are displayed on the screen.

Step 10: Our application is handled via AWS elastic beanstalk. The application URL produced by the AWS Beanstalk allows us to visit our application. As indicated in the above image, the URL can be discovered on the application instance screen. To access the spring boot application, open the application URL.








Top comments (0)