Deploy Spring Boot application into the AWS infrastructure

Hasitha Kaushan
FAUN — Developer Community 🐾
5 min readMar 15, 2020

--

I am highly motivated with the responses I had for my first article on creating a spring boot web application 😍 , thus I decided to have a go-to present how to deploy it into a physical server. You can find the steps to create a simple web application using spring boot referring to my previous article.

From my early childhood days, I was eagerly looking to access something I created(most probably a website) through the internet 🤓 (Of course that could not be the case I am going to write, but still it relates). I tried a lot and there were times I got failed.

In this article, I will illustrate how to deploy a Spring Boot application to an Amazon EC2 instance using Elastic BeanStalk. AWS is one superb cloud service provider with a range of services, but if you access AWS as a newbie, you will surely get lost (Actually I did) without knowing what service to choose. Let’s get started.

When we use AWS Elastic BeanStalk, we do not need to create an EC2 instance manually, instead BeanStalk will automatically create an EC2 container with Linux and Tomcat within it. The web application will be deployed into this EC2 instance. If you still did not refer to my previous article, please go and have a look as I use it in this case.

Go to the AWS console https://console.aws.amazon.com. It is obvious that you will have to put your card details in order to create an AWS account. In console, search for Elastic BeanStalk and open it

And create a new application.

If you successfully created a new application, you will get a view similar to the one below.

Now you need to create a new environment. Select a web server environment.

Then you will have to include Environment Information and Base Configuration.

You can give any name as Environment name. What you will have to consider most is the Base config part. As we are deploying our spring boot application to tomcat, select Tomcat as the Platform. I am uploading my WAR file, thus I chose Upload your code option.

In order to generate the WAR file of the project, you can either use

mvn package command inside the project directory or you can simply go to Build > Build Artifacts in IDE.

It will generate a WAR file inside the target folder. Then you need to upload the generated WAR file into the Elastic BeanStalk environment.

If you have uploaded your WAR file into an S3 bucket, you can simply enter the Public S3 URL but in this case, I am uploading from my Local machine. This will take some time, hold on

After the WAR file been uploaded successfully, you just have to click on the Create environment button which will automatically create an EC2 instance with tomcat and the WAR file will be deployed into it. Cool! ❤ Isn’t it?

Now go to Services and search EC2 and go to the EC2 dashboard.

There you will find your EC2 instance being initialized, after been successfully initialized, you will see your running EC2 instance.

Now return back to your Elastic BeanStalk dashboard, there you will find your environment being successfully up and running.

Click on it and you will see this dream display, where you can see the status of your spring boot application.

I got an URL http://elasticbeanstalkdemoapp.eba-bcncfdru.ap-southeast-1.elasticbeanstalk.com/ where you can locate your endpoint mentioned in your spring boot app, in my case /version (http://elasticbeanstalkdemoapp.eba-bcncfdru.ap-southeast-1.elasticbeanstalk.com/version).

Whoaaaaaa ❤ You’ve done it. It took me one hell of a time to do this thus I suppose that this would be helpful to anyone who is looking for this kinda article. Do let your comments coming in and if you are really pleased about this put a clap. Happy Coding ❤️

👋 Join FAUN today and receive similar stories each week in your inbox! Get your weekly dose of the must-read tech stories, news, and tutorials.

Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our Facebook and Linkedin Groups 💬

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

--

--

I am an Electrical Engineering undergraduate at University of Moratuwa. My passion is towards the Cloud Computing and IoT.