Blog

  • Home
  • AWS
  • How to deploy a Java enterprise application to AWS cloud

How to deploy a Java enterprise application to AWS cloud

  • (4.0)
  • | 105 Ratings |
  • Last Updated January 12, 2019

As we all know, Amazon Web Services (AWS) is a very popular name and a wonderful platform for Java application development to run Java workloads which offer for deploying and managing both off the shelf as well as custom applications. The new customers are unclear as to which method will allow them to quickly get their application running up when planning to deploy a java web application to AWS for the first time. AWS is an evolving and comprehensive cloud computing platform provided by Amazon for a mix of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS).

Amazon.com launched AWS in 2006 from its internal infrastructure to handle all online retail operations. It was one of the first company to introduce a pay as you go cloud computing model that scales to provide users with storage as needed. AWS offers services from dozens of data centers spread across availability zones in regions across the world.  

Deep dive into the world of Amazon Web Services through Mindmajix AWS Certified Training.

An availability zone is a location that typically contains multiple physical data centers, whereas a region is a collection of AZs in geographic proximity connected by low-latency network links. Virtual machines are spun up by AWS customer to replicate data in different AZs to achieve as highly reliable infrastructure that is resistant to failures of individual servers or an entire data center. In this article, we will provide you with a quick overview so that you get an idea about deploying your Java enterprise application on AWS cloud.

Step 1: Signup a permanent account

In order to begin, you are required to sign up for an AWS account which can be done via aws.amazon.com. Click on the button like "Create an AWS account" or "Sign in to the Console" which will take you to the account creation or sign in the screen that looks like depicted below.

Amazon AWS cloud

If you are a regular customer who does shopping from Amazon, then you don't need to sign up again; you can continue with AWS from the same shopping account. But, if you are creating a brand new account then you definitely have to fill out some account information as given below.

[Related Article: Brief Introduction To Amazon Web Services (AWS)]

Amazons AWS cloudAmazons AWS cloudAfter filling out all of your personal and business information you also need to give payment information. Amazon does not charge a single penny for the first 12 months for using AWS. All of the payment procedure begins once the free trial months get completed. The payment information contains to enter your credit or debit card data and after entering it, you will have to verify your identity by receiving a call or typing a PIN on the assigned phone number/email.

Amazon AWS CloudAmazons AWS cloudAfter everything is filled up, you need to select the support plan that gives you an opportunity to have access to set everything up. Unless you are a large corporation you don't need to choose anything other than their basic support plan which is totally free and gives you access to their online documentation.

Amazons AWS cloud

And there you go! After successfully creating the account, you can log in to the console and type your account information that you created previously to log in to your AWS dashboard. Then comes the next step to create a Tomcat server using Amazon Web Services called Elastic Beanstalk product for Java development services.

[Related Article: Types Of AWS Certifications And Aws Certification Path]

Step 2: Create a Tomcat Server with the help of Elastic Beanstalk

Next, we are going to create a virtual server in the cloud for an instance that will be running a Tomcat server which is known as a t2.micro instance, its part of Amazon's free tier offering. To create this server, you need to login to your AWS dashboard and navigate to Elastic Beanstalk by clicking on services option.

Amazons AWS Cloud

After clicking, you are going to Get Started by entering a few simple details to get your environment up and running. 

  • Mention the name of your application or product you are building.
  • Choose a platform - Tomcat platform for launching Java web app.
  • Lastly, you can select to launch a simple application or WAR file.

Once you hit the 'Create Application' button, AWS will proceed to create your environment for you.

Amazons AWS cloudThis usually takes about a few minutes and then presents with a familiar screen.

Amazons AWS cloud

Before working in Elastic Beanstalk, you need to take care of few points.

  • Your existing instance region which you select. If you change regions, you will not find the elastic beanstalk instance that you just created. 
  • Your application's tab if you have plenty of applications in the same region to switch between them via this tab.
  • Your application's URL to see your app in all its glory.
  • Your application's version to specify unique version numbers for each build.

Checkout AWS Tutorials

After your app is launched, take a note of your screen to go ahead and click on your app's URL to see in action.

Amazons AWS cloud

We also need to launch our own code onto this Linux server with Tomcat installed on it. To create your new Java development company cloud environment, you need to look at some other important configuration.

Change your t2.micro instance by clicking on 'Instance type' label.

Amazons AWS cloudOnce the environment is accustomed to seeing, you will see its updates on the screen.

All of that INFO status will be changed to OK health status once your new t2.micro instance is ready to go.

Step 3: Prep your code for deployment

You got a running instance in elastic beanstalk but it does not contain your application's code yet. To insert your code you have two options to unfold:

  • Created an application using SpringBoot
  • Does not create an application using SpringBoot

If you have created your application code using SpringBoot then you can skip this step. But for those, you haven't, here's all that you can do. Firstly, you have to create a deployable WAR file from your project by invoking a Maven install on your code-base. Just be sure to get your maven pom.xml as a WAR and not JAR. You can simply take your WAR file and upload it to Elastic Beanstalk.

The basic logic is to replace your existing class which contains your main method with the SpringBoot version which looks like this:

@SpringBootApplication  
public class Application extends SpringBootServletInitializer {  
  
    @Override  
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {  
        return application.sources(Application.class);  
    }  
  
    public static void main(String[] args) throws Exception {  
        SpringApplication.run(Application.class, args);  
    }  
  
}

Step 4: Deploy your code 

Your code is prepared for getting ready to deploy to AWS. Make sure you have set up Maven to deploy your project as a WAR file which can be seen inside of your pom.xml file under that looks something like this:

< ?xml version="1.0" encoding="UTF-8"? >  
< project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >  
    < modelVersion >4.0.0< /modelVersion >  
    < groupId >com.proffesso< /groupId >  
    < artifactId >proffesso-core< /artifactId >  
    < version >1.5.1.12< /version >  
  
    < !-- Here's where you set it up as a WAR file-- >  
    < packaging>war< /packaging >  
  
    < name >CourseCreation< /name >  
    < description >CourseCreation project for Spring Boot< /description >  
< /project >

The next step is to maven package your code together into a deployable WAR file by selecting your application's root project folder and running it as Maven install.

Amazons AWS Cloud

Then, you need to upload and deploy your source code file.

Amazons AWS Cloud

By hitting that deploy button your WAR file gets uploaded to Elastic Beanstalk and deployed in front of you. Once it is reported to OK health status, you should be able to visit your unique URL for your website.

Step 5: Create a Database using Amazon RDS in AWS

By following the steps sincerely, you have successfully launched your application into the cloud but what if you still need to hook it up to a database. The newly launched cloud application does not work properly using a reference to localhost:8080 fro your database connection string. To overcome this, you need to launch a database in the cloud using Amazon RDS.

Amazons AWS Cloud

If you have already created an RDS instance before, you just need to click the 'Launch a DB instance' button. We will be creating a MySQL instance which tends to be cheap as MySQL is free. You can also choose whichever option suits your needs.

Amazons AWS CloudAmazons AWS Cloud

Next, we will need to choose what kind of instance to run for the database and specify your DB details for free tier support.

Amazons AWS Cloud

Amazons AWS Cloud

Amazons AWS Cloud

After all these steps, you are all set to launch your first Amazon RDS instance. But still, there requires other configuration we need to do. Go ahead and click on 'View Your DB Instance' to watch your database get created before your eyes as it usually takes 10 minutes to get through the entire process.

Amazons AWS Cloud

Step 6: Amazon RDS Instance configuration

Once the status of your DB instance is set to available, you will ready to start configuring things. You can connect your DB from outside of your Virtual Private Cloud. Identify which security group was created for your DB instance to expand the details section.

Amazons AWS Cloud

You can also head over to EC2 page by clicking on Services.

Amazons AWS Cloud

You can click the Edit button to edit the inbound rules and edit the existing rule or add a new one like so. Also, you can choose a new rule and open it up to allows all inbound traffic as given in the below screenshots.

Amazons AWS CloudAmazons AWS Cloud

Thus, your new DB instance is ready to rock.

Step 7: Connect code to the RDS Instance

You can log into DB instance using MySQL Workbench or Toad for MySQL by following the given procedure.

  • Host -> Endpoint 
  • Username -> myUsername
  • Password -> [your password]
  • Database -> myDatabaseName
  • Port -> 3306

Amazons AWS cloud

Next, you need to connect your application code to this database via your properties file which you used to connect to your database previously. This can be found in your application.properties file if you are using a Spring Boot application.

Frequently Asked AWS Interview Questions

Step 8: Add a Domain Name to your new Hosted Application

To get rid of the non-friendly UEL that Elastic Beanstalk assigns to your application, you can use another AWS product called 'Route 53'. Once you begin with it, you can create 'Hosted Zones' which allow forwarding our incoming HTTP traffic to our Elastic Beanstalk application from any domain we owe. 

The only pre-requisite is that you will need to own a domain name that will get forwarded to Elastic Beanstalk application. To point towards the AWS app when someone navigates to your domain name, create a new 'Record Set' and also point to a subdomain to the same place as well. And Voila! you are all set to go.

Amazons AWS Cloud

Before you go…

In a few simple clicks and steps, you can deploy a simple yet production-ready Spring Boot application with a MySQL database on AWS using Elastic Beanstalk. The launch and configuration of the environment as a part of Elastic Beanstalk to launch resources using other AWS services as these resources still remain under your control. These resources can be accessed through other AWS service consoles like EC2 and RDS. 

With the help of deploying your Java enterprise application to the Amazon's AWS cloud computing helps to trade capital expense for the variable expense, benefits from massive economies of scale, delimits the storage capacity, increases the speed and agility and also ease out from maintaining data centers as well as gets global in minutes of time. So, what are you waiting for? Start now

Explore AWS Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

Subscribe For Free Demo

Free Demo for Corporate & Online Trainings.

About Author

Andrew McCallion

Andrew McCallion working as a Java developer at TatvaSoft UK. Besides of his profession Andrew is passionate about writing articles on java development services, emerging technologies and innovations in software industry.


DMCA.com Protection Status