Create an EC2 Instance with EC2 User Data Script to launch Website

Configurare noua (How To)

Situatie

Amazon EC2 is one of the most popular AWS offerings. It stands for Elastic Compute Cloud. This is the way to do Infrastructure as a Service on AWS. EC2 is not just one service.

Solutie

Pasi de urmat

C2 User Data Script:

It is a bootstrap script to configure the instance at the first launch. Bootstrapping means launching commands when the machine starts. So, that EC2 User data script is only run once and when it first starts, and then will never be run again. So the EC2 User Data has a very specific purpose. It is to automate boot tasks such as

  • Install updates.
  • Install software.
  • Download common files from the Internet.
  • Go to the AWS Management Console (https://aws.amazon.com/console/). On services, tab search for EC2 and click on instances in the sidebar for creating an EC2 Instance.
  • First, enter a name tag for the instance. This will act as key-value pair and if you wanted to add additional tags to tag your instance differently, then you could click on “Add additional tags”.
  • Next, you need to choose a base image for your EC2 instance i.e. operating system of your instance. You can see a full catalog of OS that you can search but in this article, we’re going to use Amazon Linux, which is provided by AWS.

Launch an EC2 instance

Next, we need to choose an instance type. Instance types are going to differ based on the number of CPUs they have, the amount of memory they have, and how much they cost. In this article, we are going to have a T2 micro selected. This one is free tier eligible, so it will be free to launch them. If you wanted to compare the instance types click on “Compare Instance types” it shows you all the types of instances as well as how much memory they have and so on.

Next, create a key pair to log into your instance. So this is necessary if we use the SSH utility to access our instance. We could proceed without a key pair, but for now, let’s go ahead and create a new key pair.

  • Give a name to Key Pair.
  • Then you need to choose a key pair type (RSA encrypted or ED25519 encrypted), here we’ll be using the RSA encrypted.
  • And then we have to select key pair formats. If you have Mac or Linux or Windows 10 then you can use the .pem format.
  • If you have Windows less than version 10, for example, Windows 7 or Windows 8, then you can use a .ppk format.
  • When you create a key pair it will be downloaded automatically to your pc.

Key pair configurations

Next, we have to go into network settings. Leave the settings to default Our instances are going to get a public IP and then there is going to be a security group attached to our instance (which is going to control the traffic from and to our instance ) and therefore we can add rules. The first security group created will be called launch-wizard-1 which is created by the console directly and we can define multiple rules here. So the first rule we want to have is to allow SSH traffic from anywhere and to allow HTTP traffic from the internet.

Next, we need to configure the storage for this instance let’s have an eight-gigabyte gp2 root volume because, in the free tier, we can get up to 30 gigabytes of EBS General Purpose SSD storage. If you go into advanced details you could configure them a little more advanced in terms of storage, volume, encryption, and keys. One important thing to note here is the “delete on termination’ should be “Yes”. By default, it is enabled to yes, which means that once we terminate our EC2 instance, then this volume is also going to be deleted.

Network and Storage Settings

Tip solutie

Permanent

Voteaza

(3 din 4 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?