Elastic Beanstalk - Deploy a Simple Spring Boot Application (using web console)
- Details
- Written by Nam Ha Minh
- Last Updated on 28 October 2023   |   Print Email
In this tutorial, I’d like to share how to deploy a simple Spring Boot application (no database) on AWS Cloud using Elastic Beanstalk web management console, step by step with screenshots.
I suppose that you have a Spring Boot project without database, which is ready for deployment. If not, you can download a sample one in this article. Then run Maven to package the application as an executable JAR file.
Before following this guide, I recommend you check this page to grasp some fundamental information about Elastic Beanstalk. Also note that you must have an AWS account and IAM user.
1. Create New Application
Sign in AWS management console using an IAM user with administrative access. Then choose an AWS region of your choice, e.g. US East (Ohio):
AWS will provision necessary resources and host your application in that physical region. Then go to Elastic Beanstalk management console from the menu Services > Compute > Elastic Beanstalk. Then click the Create application button:
Then you will go through the deployment process that consists of 6 steps, as shown below:
The first step is Configure environment. Keep the default environment tier is Web server environment because we’re doing to deploy a Java web application. Then enter the application name as My Spring Boot App.
It will suggest the environment name based on the application name, and you can change if you wish. Then specify subdomain of your application, and click the Check availability button:
You may need to enter the domain until it shows the green check mark, which means your application will be accessible on the Internet via that domain.
Then in the Platform section, the default Platform type is Managed platform. Then choose Platform is Java. And keep the suggested the Platform branch and Platform version:
Then in the Application code section, choose Upload your code and enter Version label is Version 1. Then choose Local file. Click the Choose file button to upload the executable JAR file of your Spring Boot application, as shown below:
Then in the Presets section, choose the default instance type of virtual server is Single instance (free tier eligible), which is suitable for demo/testing purpose of simple application.
Then click the Next button to proceed to the next step.
2. Configure Service Access
This is the important step that decides whether the deployment is successful or not. On the Configure service access page, choose Service role is Create and use new service role. And under EC2 instance profile, click the View permission details button:
Then in the popup dialog, you can see it requires the permissions of a new EC2 role are: AWSElasticBeanstalkWebTier, AWSElasticBeanstalkWorkerTier and AWSElasticBeanstalkMulticontainerDocker:
Click the IAM console link to open the IAM Dashboard in a new tab in order to create a new role with the required permissions.
In the IAM management console, click Roles on the left menu. Then click Create role button.
Then on the next page (Selected trusted entity), choose AWS service as Trusted entity type and choose EC2 under the dropdown list Service or use case:
Click Next. Then on the Add permissions page, type awselasticbeanstalk into the search box. Then select 3 policies:
- AWSElasticBeanstalkWebTier
- AWSElasticBeanstalkWorkerTier
- AWSElasticBeanstalkMulticontainerDocker
As shown below:
Click Next, then enter the role name as aws-elasticbeanstalk-ec2-role on the next page. Click Create role button. It will create the new role as shown below:
Now, switch to the browser tab that displays the Configure service access page, click the refresh button in the EC2 instance profile section. You will see it selects the newly created role as follows:
Then click Next to proceed to Step 3 and Step 4, which are optional. You can keep all the default settings of these steps, or adjust if you wish. Then in Step 5, follow the instruction described below.
3. Add Environment Variable
By default, a Spring Boot web application running on embedded Tomcat server listening on port 8080. But Elastic Beanstalk assumes that the application will listen on port 5000, so we need to add a system environment variable under the Environment properties section.
Click the Add environment property button and add a new variable named PORT with value 5000, as shown below:
Click Next button to proceed to the next step.
4. Deploy the Application
The last step (Step 6) allows you to review all the information before start the deployment process. Click Submit button to proceed. It will take you to the environment page where you can see the deployment progress and status.
It will take a few minutes for the deployment to complete, and you can see all the details in the Events tab. The events are continuously updated, until you see the message “Environment successfully launched” and the health status is “Ok”, as shown below:
You can see the Health status is Ok, which means the application has been deployed and running, ready to receive requests from clients. Also note that the running version is Version 1.
Congratulations! You have deployed your first Spring Boot application on AWS using Elastic Beanstalk successfully.
5. Access Newly Deployed Spring Boot Application
On the environment page, under Environment overview section, click the link appears under Domain to open the newly deployed application in a new browser tab:
You will see the home page of your Spring Boot application appears. For example, this is my simple Spring Boot application:
You can notice the domain of the application starts with the subdomain you specified in the first step, then your chosen region name, and elasticbeanstalk.com is the top level domain.
That’s my tutorial about deploying a simple Spring Boot application without database on AWS Cloud using Elastic Beanstalk web management console. I recommend you check this tutorial for other operations such as Deploy a new version, Check AWS related services, Terminate an environment and Undeploy the application.
To see the deployment process in action, watch the following video:
References: