Spinning up an AWS EC2 instance

Amazon Web Services (AWS) provides lots of platforms for cloud computing solutions. You can use AWS to build and deploy applications. Amazon EC2 is a service that provides resizable computing capacity in the cloud and makes web-scale cloud computing easier for developers.

Another platform is the AWS Elastic Container Service. It is used to deploy microservices using Docker. Microservices can be deployed to Amazon ECS by creating a Docker image of your application. You can easily push this Docker image to the Amazon Elastic Container Registry (ECR).

In this chapter, I will deploy a microservice using a Docker image of your application to the Amazon EC2. I will use the Docker registry to the Docker Hub to push a Docker image. Let's see how to set up an Amazon EC2 instance:

  1. First of all, we need to have an Amazon account. You can create an Amazon Free Tier account at https://aws.amazon.com/free/:
  1. Log in to the AWS Management Console. After a successful login, you should see the following screen:

The preceding screenshot displays all the available AWS services. You can use any service by just clicking and configuring it accordingly.

  1. Click on the EC2 service on the Amazon AWS dashboard, as shown in the following screenshot:

In the preceding screenshot, the EC2 dashboard displays all the available options for the EC2 instance.

  1. To create an EC2 instance, click on the Launch Instance button. It will render options to choose an Amazon Machine Image (AMI), as shown in the following screenshot:

As you can see in the preceding screenshot, you can select any AMI according to your application and business requirements. AWS has more than 35 AMIs, depending on your application requirements and usage. They have multiple platforms, such as Linux, Windows, and more.

  1. Select any AMI. We are going to use a Linux-based AMI and SSD volume type with 64-bit OS. The following screenshot illustrates how to select an instance type of this AMI:

The preceding screenshot has displayed all the available options to choose an instance type. Here, I have chosen the t2.micro instance. Amazon EC2 provides lots of instance types according to different use cases. Instances are used to run applications as virtual machines. They have different capacities with various combinations of CPU, memory, storage, and networking capacity. This gives you the flexibility to choose the appropriate mix of resources for your applications.

  1. AWS also allows you to configure EC2 instances to suit your requirements. Let's click on the Configure Instance Details button, as shown in the preceding screenshot:

As you can see in the preceding screenshot, you can launch multiple instances from the same AMI, and other options are also included.

  1. Also, you can add additional EBS volumes and instance store volumes to your instance as per as your application requirement, as shown in the following screenshot:
  1. After attaching additional storage, let's add a tag to this instance to help you manage your instances, images, and other Amazon EC2 resources. As shown in the following screenshot, you can see I have added the key Name and value of this key, AccountService:
  1. You can also configure the security group for this instance to protect it and make it secure. It is very simple to configure the security group to this instance by clicking the Configure Security Group button in the preceding screenshot. There are a lot of security groups available for several requirements, such as firewall rules that control the traffic for your instance, as shown in the following screenshot:
  1. After configuring the security group, let's click on the Review and Launch button, shown in the preceding screenshot. It will ask you to create a key pair, as shown in the following screenshot:

In the preceding screenshot, I have created a key pair with the name dineshonjava and saved it to the local drive. We will use this dineshonjava.pem file to access this instance using SSH.

Next, you can also configure a key pair to access this instance from clients such as PuTTY or FileZilla. If you have an existing key pair, then just use it for this instance, or you can create a new key pair. A key pair consists of a public key that AWS stores, and a private key file that you store.

  1. Let's launch this t2.micro instance of the AWS EC2 service. It will display the following message:

As you can see in the preceding screenshot, we have successfully launched an EC2 service instance. Let's click on the generated instance ID to see this running instance, as shown in the following screenshot:

You have seen how to configure and launch the EC2 service instance (t2.micro). We have named the instance AccountService.

The AWS EC2 instance is very simple to configure and launch. It is very easy to use and it has several benefits, including the following:

  • Elastic web-scale computing
  • Completely controlled
  • Flexible cloud hosting services
  • Integrated
  • Reliable
  • Secure
  • Inexpensive
  • Easy to start

Now that you have seen the benefits of the AWS EC2 instance, let's look at the microservices architecture on AWS in the next section.

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

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