Amazon Web Services

In this section, you will learn how to build a Jmix application as executable JAR and deploy it to the AWS Elastic Beanstalk service.

Before starting the guide, create an account and ensure that you have access to the AWS Console.

We will use PostgreSQL as a database for this guide.
If you need to deploy your application just for test or demo purposes, consider using Quick Cloud Deployment. It will deploy and run your application together with the database on a newly created EC2 instance.

Deploying Executable JAR

Preparing The Application

Since we have more than one database connection now (local development and AWS), we need to configure additional properties file that will contain connection properties for AWS environment.

To switch between different configurations, we will use Runtime Profiles. For our case, we will use aws profile name.

Let’s create file according to naming rules described in Spring Boot Documentation.

In this file, we will specify database connection properties using AWS Elastic Beanstalk environment variables:

  • RDS_HOSTNAME - internal Beanstalk-specific database host name

  • RDS_PORT - database port allocated by Beanstalk

  • RDS_DB_NAME - database name

  • RDS_USERNAME - database username

  • RDS_PASSWORD - database password

Note that these variables should be specified if you create a database using Beanstalk. If you created the database separately using RDS or another AWS service, you may not need these variables

In addition to the datasource coordinates, we may want to specify the following properties before the deployment:

  • server.port - should be set to 5000 by default. You can specify Beanstalk environment property SERVER_PORT instead if you like. We will show how to set Beanstalk environment later.

  • main.liquibase.enabled - if set to true (default value) - enables automatic execution of Liquibase database migration scripts on application start.

So, the file content may look like this:

main.datasource.url = jdbc:postgresql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
main.datasource.username = ${RDS_USERNAME}
main.datasource.password = ${RDS_PASSWORD}

The application is ready, you can create an executable JAR and move to the next step.

Creating The AWS environment

Log in to the AWS Console and select Elastic Beanstalk service from the list of services.

After that, create the application by clicking on a corresponding link on the Beanstalk main page. Enter application information:

  • Application name - any name you prefer.

  • Platform - Java. Select platform branch according to your preferences.

In the Application code section select Upload your code option. In the Source code origin section for the Local file option click on Choose file button and upload your application’s JAR. It is usually located in /build/libs folder.

Add a database to the environment by clicking on Configure more options button. In the configuration page, edit the database parameters:

aws ebs add database

Set database parameters similar to those on the picture:

aws rds parameters
Setting Retention to Delete is recommended for test environments. For production environments set it to Create snapshot to avoid data loss in case of the application is deleted accidentally.

After creating the database, we have one more step specifying runtime profile to enable proper application configuration - aws. In order to do this, edit Software settings in the environment configuration page:

aws ebs environment settings

In the Environment properties section add the SPRING_PROFILES_ACTIVE property and set its value to aws:

aws ebs environment values

Save all settings and create the application. The creation and startup usually takes 5-10 minutes.

Testing The Deploy

When the application is created and deployed, open the environments list and click on the corresponding environment:

aws ebs app env list

In the environment page, click on the Go to environment link to open the deployed application page.

aws ebs app env page

The application page should open.

More Information

The guide is based on the AWS guide, so you can refer to it for further details.

Also, you may find the guide on deploying Java applications useful.