DEV Community

Cover image for Run Springboot application with Elastic Beanstalk, SSH and EC2
EI Akoji
EI Akoji

Posted on • Updated on

Run Springboot application with Elastic Beanstalk, SSH and EC2

Image description

Recently, I worked on a PoC to create an automated build pipeline for a springboot rest api in elastic beanstalk. Based on prior knowledge related to the use of Amazon EBS, this was expected to be a trivial tasks. Turns out that without a solid knowledge on setting up and managing configurations for AWS resources, doing this can be challenging.

There are a host of pages and videos explaining how to deploy spring/springboot applications to elastic beanstalk. however, I was not lucky enough to find one explaining details of the underlying computing resource for this configuration.

For this post, I am focusing on the configuration required to deploy a java application on elastic bean stalk, using Amazon EBS CLI. This can also be done with AWSCLI, though, EBS CLI is tailored to meet our needs.

Infrastructure Diagram

To run java applications with EBS, we can use several configurations. Deploying an application that runs on scalable EC2 instances is common, hence is used in this guide.

illustration of AWS EBS with EC2 environments

Requirements

  1. You'll obviously need to have an AWS account with the required access level to AWS console.

  2. If you have not done so, install AWSCLI and configure your credentials.

You can create named profiles with your aws credentials and configuration using this guide.

  1. Install EBS CLI

  2. Follow this tutorial to create and deploy a simple springboot application with AWS Elastic Beanstalk. Remember to select "create a new SSH public, private key pair" when prompted to.

Implementation Notes

I noticed that the eb create command fails when the following line is added:

deploy:
  artifact: target/spring-boot-bootstrap-eb.jar
Enter fullscreen mode Exit fullscreen mode

If you get the following error message: ERROR: NotFoundError - Application Version does not exist locally (target/spring-boot-bootstrap-eb.jar). Try uploading the Application Version again.

Remove the deploy artifact configuration and use the following command to create your environment:

$ eb create --source target/spring-boot-bootstrap-eb.jar --$ version spring-boot-bootstrap-eb
Enter fullscreen mode Exit fullscreen mode

Similarly run the following command to deploy

$ eb deploy --version spring-boot-bootstrap-eb
Enter fullscreen mode Exit fullscreen mode

You can review the CLI documentation or use eb command_name --help to view usage of different commands.

SSH to your EC2 Instance

Now you're all set to go!

$ eb ssh
$ cd /var/app/current
$ java -jar application.jar
Enter fullscreen mode Exit fullscreen mode

You can run regular commands as you'd do in a local environment. This can be useful for troubleshooting application instances.

Top comments (0)