DEV Community

Cover image for Launch an Amazon EC2 instance
Jawad Ahmed
Jawad Ahmed

Posted on

Launch an Amazon EC2 instance

Step # 1:

  • Search for EC2 in the search bar of console and select the first option.

Image description

Step # 2:

  • Now click on the launch instance as shown below:

Image description

Step # 3:

  • Write down the name of the server you want to create i.e server01. Now scroll down a little and in the quick start section select Amazon Linux, there is subsection name Amazon machine image (AMI), there select an option of amazon linux 2 AMI as shown below:

Image description

Step # 4:

  • In the key pair section select processed without key pair, it is recommended if you want to add security like private and public key to execute the application.

Image description

Step # 5:

  • Now go to the Network section and click on the edit on the right side. In the type section select the HTTP option as shown below':

Image description

Step # 6:

  • Now go to the advanced details and scroll down to the bottom, in the user data section, paste the code like shown below:
    #!/bin/bash
    sudo yum update -y
    sudo yum install -y httpd
    sudo yum install -y git
    export META_INST_ID=curl http://169.254.169.254/latest/meta-data/instance-id
    export META_INST_TYPE=curl http://169.254.169.254/latest/meta-data/instance-type
    export META_INST_AZ=curl http://169.254.169.254/latest/meta-data/placement/availability-zone
    cd /var/www/html
    echo "<!DOCTYPE html>" >> index.html
    echo "" >> index.html
    echo "

    " >> index.html echo " " >> index.html echo " " >> index.html ...... ..... echo " " >> index.html echo "" >> index.html echo "" >> index.html sudo service httpd start
    Step # 7:
  • At last review the summary on the right side and click on the launch instance. The instance will be launched successfully.
    Now open the instance section and click on the server created in order to check the status, as shown below:

Image description

Step # 8:

After clicking on the above link it give below details:

Image description

It shows the successful creation of the instance along with the region given.

Top comments (0)