Skip to main content

Spring Boot to AWS Elastic Beanstalk

Beanstalk is an AWS-managed service that allows applications to run containerized in AWS. I am using Elastic Beanstalk (EB) to deploy quickly developed applications when the emphasis is on time-to-market rather than all the features of an enterprise application.

For the purpose of this post, I will use the application called Genova as an example. It is a web application that exposes HTML and JSON content.

Step 1 - Create a Spring Profile for AWS Beanstalk

The configuration of Spring Boot application is applications-<profile>.yml files that are in the src/main/resources folder.

By default, an EB deployment listens to the port 5000. For this reason I am creating the file application-eb.yaml with the following content:

server:
 port: 5000

Step2 - Build the Spring Boot Application

Using maven to create the Spring Boot jar file:

mvn clean package -DskipTests

This command creates a file with the name genova-1.0.0-SNAPSHOT.jar  in the target folder.

Step 3 - Create the Elastic Beanstalk Application and Environment in AWS

Log in to the AWS console, select AWS Elastic Beanstalk, and start the wizard to create a new application.

Then, create a new Environment for this application. I am choosing the Java platform:




Other parameters:

  • Single instance
  • Loading from a local file
  • Root volume type - General Purpose 3 (SSD)
  • IMDSv1 - Deactivated

Environment variables:

  • Important: add the aws-eb profile, this will set the server port

Step 4 - Create the DNS Entry for the EB Deployment

Go to AWS Route 53, select the zone, add an A record pointing to the EB-generated endpoint:

Step 5 - Run the Application

The application is now deployed, running in AWS EB:

Step 6 - Pause the Environment

To save money, this environment configuration can be saved and quickly re-created later.

Select the environment, then select Actions -> Save Configuration.

Select the environment, then select Actions -> Terminate Environment.

Appendix

Notes:

  • The application is now running on port 80, unsecured
  • The deployment is running on a single instance
  • These can be addressed by creating a load-balanced EB environment with multiple instances running in separate availability zones.


Popular posts from this blog

View - A Functor for Web App Design

This blog is about practical applications of Category Theory to the development of Java + Spring applications. I am looking at a design approach to simplify the development of web applications. Traditionally, this kind of back-office application is based on the Web 1.0 technology stack, using Spring Boot and Thymeleaf. My approach is to keep using Spring Boot but replace the generation of HTML with J2HTML and higher-order views. From a Category Theory point of view, we can look at web applications as mappings from the Category of Business Entities and the Category of UI Widgets. If we go one step further, both business entities and UI widgets are mapped to Java classes. Thus, we can view a web application (or a part of it) as an endofunctor in the Category of Java Classes. We define the View-functor as follows: domain(V) - Java classes representing business entities - e.g., Invoice, User - and, codomain(V) - Java functions that render the business entity as a DomContent object (DomCont

Web Application Development following Functional Programming Principles

After studying category theory and functional programming, I decided to put these concepts into practice by developing a simple web application. This project was inspired by the example in Chapter 11 of 'Programming in Haskell' by Graham Hutton. My goal was to take these theoretical programming ideas and see how they work in creating a real-world web application. The key concepts of functional programming are: Prioritize creating pure functions as much as possible. These are functions without side effects, making them simpler to test Use composition of pure functions to construct more intricate functions Use Functors, Applicatives, and Monads in scenarios that require pure functions, such as error handling or managing missing values, and when working with collections like trees and lists. I wrote this application in Java, utilizing the Spring Boot framework. This decision was influenced by my previous work in developing enterprise applications with this technology stack. My obj

Reading J2HTML

J2HTML (j2html) is a Java library used to generate HTML I have been using it to create Web 1.0 applications in Java. Web 1.0 is server-side rendering pages with minimal Javascript. As I got deeper into using the library I started to read the actual source code of this library with an eye on following Java best practices and to my pleasant surprise, this code follows many of them. I am going to show here some examples of using interesting Java features, beyond the basics. 1. Functional Interface People are aware that Java supports some form of Functional Programming, and here is an example of using it: @FunctionalInterface public interface Indenter {     String indent( int level , String text ); } public static Indenter indenter = ( level , text ) -> String. join ( "" , Collections. nCopies ( level , FOUR_SPACES )) + text ; Things that I noticed: String has a method called join. I used before StringUtils.join, but now that is in the standard library I don’t need to us