DEV Community

Cover image for Launch an EC2 instance with AMI in 1 minute (Step by Step guide) Updated 2022
Tanmay Shukla
Tanmay Shukla

Posted on • Updated on

Launch an EC2 instance with AMI in 1 minute (Step by Step guide) Updated 2022

This article will guide you to get started with AWS EC2, launch your first EC2 instance and Configure it.
After this step by step tutorial you will understand EC2 practically.

First of all, Go to AWS management console and login with root or IAM user. Then select EC2 by searching it on global search box.
1

Launch Your Amazon EC2 Instance

  • In the AWS Management Console on the Services menu, click EC2.
  • Click Launch instances > Launch instances. 2

Step-1: Give name and tags

  • First, give the name and tags to your instance. Tags enable you to categorize your AWS resources in different ways, for example, by purpose, owner, or environment.
  • Click Add Tag then configure:
    • Key: Name
    • Value: Web Server 47

Step-2: Choose Application and OS Images [Amazon Machine Image(AMI)]

  • Then choose instance type as 2nd step.
  • An Amazon Machine Image (AMI) provides the information required to launch an instance, which is a virtual server in the cloud. AMI includes
    • A template for the root volume for the instance (for example, an operating system or an application server with applications)
    • Launch permissions that control which AWS accounts can use the AMI to launch instances
    • A block device mapping that specifies the volumes to attach to the instance when it is launched
  • We can also create our own AMI but Quick Start list contains the most commonly-used AMIs.
  • Click select next Amazon Linux 2 AMI (at the top of the list). 4

Step-3: Choose an Instance Type

  • Amazon EC2 provides a wide selection of instance types optimized to fit different use cases. Instance types comprise varying combinations of CPU, memory, storage, and networking capacity and give you the flexibility to choose the appropriate mix of resources for your applications.
  • Under Instance type, from the Instance type list, you can select the hardware configuration for your instance.
  • A t2.micro instance has 1 vCPU and 1 GiB Memory. 5
  • Choose the t2.micro instance type, which is selected by default. The t2.micro instance type is eligible for the free tier. In Regions where t2.micro is unavailable, you can use a t3.micro instance under the free tier.

Step-4: Create Key pair (login)

We use key pair to securely connect to our instance.
6
Create new key-pair if don't have any, then give it name and select RSA. Finally download the PEM or PPK file.

🚨 ⚠️ Warning
Do not choose Proceed without a key pair (Not recommended). If you launch your instance without a key pair, then you can't connect to it.

Step-5: Configure Network settings

7

  • Next to Network settings, choose Edit. For Security group name, you'll see that the wizard created and selected a security group for you.
  • We can use this security group, or alternatively you can select the security group that you created when getting set up using the following steps:
    • Configure Security Group:
      • Keep the default selection, and select Create a new security group.
      • Security group name: Web Server security group
      • Description: Security group for my web server 8
  • Add SSH(port-22) and HTTP(port-80) rules in Inbound security groups rules to access our instance from putty(ssh) and through web browser(internet) respectively.
  • Keep the default selections for the other configuration settings for your instance.

Step-6: Configure Storage

  • Amazon EC2 stores data on a network-attached virtual disk called Elastic Block Store. 9
  • We will launch the Amazon EC2 instance using a default 8 GiB disk volume. This will be your root volume (also known as a 'boot' volume).

Step-7: Advanced Details

  • A field for User data will appear.
    • When you launch an instance, you can pass user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts.
    • Your instance is running Amazon Linux, so you will provide a shell script that will run when the instance starts.
  • Copy the following commands and paste them into the User data field:
#!/bin/bash
yum -y install httpd
systemctl enable httpd
systemctl start httpd
echo '<html><h1>Hello From Your Web Server!</h1></html>' > /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode
  • Leave everything else as default.

Review the Summary and Click Launch

10

Connect to your Instance

There are multiple ways to connect to your instance.

  1. Connect to EC2 instance using PuTTY
    11

    • Open PuTTY
    • Provide the public IPv4 address( of your ec2 instance in the Host Name section.
    • On the left menu, expand SSH and click on Auth
    • Click on Browse and open the .ppk file 12
    • Now click open and accept if comes in prompt then login as `ec2-user.

    🚩🚩 Important
    You can't connect to your instance unless you launched it with a key pair for which you have the .pem file and you launched it with a security group that allows SSH access from your computer. If you can't connect to your instance, see Troubleshoot connecting to your instance for assistance.

  2. Connect using EC2 Instance Connect

    • Supported Linux distributions:
      • Amazon Linux 2 (any version)
      • Ubuntu 16.04 or later
  • To connect to your instance using the browser-based client from the Amazon EC2 console
    • Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
    • In the navigation pane, choose Instances.
    • Select the instance and choose Connect.
    • Choose EC2 Instance Connect.
    • Verify the user name and choose Connect to open a terminal window. 67
    • When you hit coonect it will open terminal in your browser lik this: 75

Top comments (0)