How to create an AWS EC2 instance

From PheonixSolutions
Jump to navigation Jump to search

20/04/2022

How to create an AWS EC2 instance

[edit]

Creating an AWS EC2 Instance

Step 1: Open the AWS Management Console, open the services drop-down and click on EC2 under the compute category

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image40.png

Basic steps to follow to create an Amazon EC2 instance are depicted in the image below:

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image12.png

Step 2: Creation of an instance

  • First, click on Launch Instance

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image33.png

  • Now, in the Choose AMI section, scroll down and choose Ubuntu and click on Next

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image37.png

  • Choose the free tier eligible t2.micro Instance and proceed with Next: Configure Instance Details

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image14.png

  • Configure instance details and then click on Next

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image8.png

  • Next is adding storage. Here, you don’t need to change the size because for a basic Ubuntu instance it is 8 GiB

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image44.png

  • Now add a tag with the attributes Key and Value, name them as it is in the image below. Key and Value pairs are to identify the particular instance while it is running

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image15.png

  • Now proceed with the next step, Create a new security group, and then click on Review and Launch

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image42.png

  • Review your instance specifications once and then launch it

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image2.png

Step 3: Creating a new key pair

  • Choose to Create a new key pair from the popup box, give a name for the key pair, and then click on Download Key Pair. Then, proceed with Launch Instances

  • Keep the downloaded key pair file in a safe location so that you can access it later

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image50.png

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image25.png

Step 4: Viewing your AWS instances

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image9.png

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image21.png

  • Wait till the launch is initiated, then click on instances under the INSTANCES option and view the instance which you have created

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image20.png

  • Wait till your instance initializes, that is, till your 2/2 checks are done

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image19.png

Now it gets interesting; here, you will connect the instance using an SSH client and then host your own website

Step 5: Connecting the instance through an SSH client

  • Download PuTTY: a free SSH client

Website link: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

  • Choose 32 or 64 bits according to your system’s specifications. Then, install it like you install any other application on your system

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image17.png

  • Install PuTTY

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image41.jpg

  • PuTTY only accepts private key files with the extension ‘.ppk’, so you have to convert your ubuntudemo.pem to a .ppk extension

  • Now, open PuTTYgen and load ‘ubuntudemo.pem’. A dialog box appears where you have to press OK

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image34.png

  • Click on save private key and proceed with a Yes in the dialog box. After that store it in a location from where you can access it easily

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image7.png

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image11.png

  • Open PuTTY, type ubuntu@”your public ip” which you can find in the description tab for your instance

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image48.png

  • First, type Host Name in the box with the port number, 22

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image47.png

  • Second, go to Connection → SSH → Auth. Now, click on Browse and add the .ppk file which you have created

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image46.png

  • Click on Open and then press Yes on the PuTTY Security Alert box

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image28.png

  • Now, you have successfully launched your Ubuntu instance!

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image26.png

Step 6: Running a simple HTML page via this instance

  • First, update the Ubuntu instance using this command

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image10.png

  • Then, install apache2. Apache2 is a web server which is commonly used in Linux systems

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image39.png

  • Type the below commands to enter into that directory and check whether index.html exists

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image24.png

  • Go back to your instances page and click on ‘launch-wizard-4’ under security groups

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image45.png

  • Go to Inbound and click on Edit. Then, add an HTTP rule with Source as ‘Anywhere’

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image13.png

  • On your browser, use your public IP address, put it in the URL box and run

  • You have now successfully hosted your first website via a Cloud instance

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image35.png

  • Let’s now see how to edit and run your own HTML page instead of the Apache2 default page

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image23.png

  • For one last time, run the public IP address of your instance in the browser

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image1.png

Congratulations! You have created your first Ubuntu instance and have run your webpage on it!

Hope this Amazon EC2 tutorial was helpful to you. Do let us know in the comment section below.

06/07/2022

How to restore the EC2 instance in AWS

[edit]

Step1: Log into your AWS account with the root user.

Step2: Go to the EC2 and launch the Instance/Server.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image49.png

Step3: Log into the server in the terminal with the root user.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image16.png

Step4: Write some data and install Apache/Ngnix on the Server.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image52.png

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image18.png

Step5: Check whether Apache/Ngnix working or not.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image4.png

Step6: Log in back into the AWS account.

Step7: Navigate AWS>>EC2>>Snapshots.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image36.png

Step8: Create Snap by exiting the instance/Server.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image29.png

Step9: Terminate the instance/Server.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image22.png

Step10: Navigate to Snapshots Right-click on Snap and create an Image.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image32.png

Step11: Launch the instance with My AMI.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image5.png

Step12: Log into the server.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image27.png

Step12: Check the data and check whether the Apache/Ngnix working or not on the server

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image30.png

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image43.png

*******Our Data is restored*******

17/08/2022
IAM User

Aws Identity and Access Management (IAM) is a web service that helps you securely control access to AWS resources for your user. You use IAM to control who can use your AWS resources (authentication) and what resources they can use and in what ways(authentication)

They are four basic components in IAM

  1. Users

  2. Groups

  3. Roles

  4. Policies

Users

How to create an IAM user in AWS?

[edit]
  1. Log into the AWS Management Console.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image3.png

  1. Navigate IAM >> users >> add user. And click on add user

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image51.png

  1. Set user details and select AWS access type.


    https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image31.png

  2. And click on “Next permissions” and attach the policies to the user.


    https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image6.png


    Note:- There are no exciting groups and users. We have to give “Attached exciting policies directly”

  3. Click on “Next Tags” and give tags to the user.

  4. Review the user details and attached policies and Click on the “Create user”

  5. While creating a user we get Access Key ID and Secret Access Key.


    https://wiki.pheonixsolutions.com/index.php/File:Vertopal_af148ecce5154cd7bf1f16de238aea81-media-image38.png