Running microservices on AWS EC2

In this section, we will set up account and customer microservices on the EC2 instance. We are using Spring Boot 2.0 in this example:

  1. We have to install Java 8 as well our EC2 instance using the following command:
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie

You can also refer to the following link:

http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz

The preceding command will download a jdk-8u131-linux-x64.tar.gz file. We extract this file using the following command:

$ sudo tar -xvf jdk-8u131-linux-x64.tar.gz
  1. After untar, let's set up the JAVA_HOME and PATH environment variables, as follows:
$ JAVA_HOME=/home/ec2-user/jdk1.8.0_131
$ PATH=/home/ec2-user/jdk1.8.0_131/bin:$PATH
$ export JAVA_HOME PATH

Let's check the Java version, using the following command:

  1. As you can see, we have set up Java 8 in the EC2 instance. Let's run a microservice on this EC2 instance.

Execute the following commands in sequence:

$ sudo docker run -p 80:8761 dineshonjava/doj:1.0
$ sudo docker run -p 8181:6060 dineshonjava/account:1.0
$ sudo docker run -p 8282:6060 dineshonjava/customer:1.0
  1. Let's validate that all the services are working by opening the following URL in the browser:

http://ec2-18-219-255-59.us-east-2.compute.amazonaws.com/

Note that we will be using the public IP or public DNS of the EC2 instance. This URL will open the Eureka dashboard, as shown in the following screenshot:

As you can see in the preceding screenshot, we have registered two microservices, Account and Customer, with the Eureka server running on the AWS EC2 instance.

  1. Let's deploy the customer microservice to AWS EC2 using the Docker image with the following command:
$ sudo docker run -p 80:6060 dineshonjava/customer:1.0 
  1. Let's test this microservice using the browser by navigating to the following URL:

http://ec2-18-219-255-59.us-east-2.compute.amazonaws.com/customer/1001

It will render the details of a customer with the customer ID 1001, as shown in the following screenshot:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.203.96