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: |
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.