DEV Community

Surav Shrestha
Surav Shrestha

Posted on

Launch and Connect to AWS EC2 Instance

Amazon EC2

Introduction

Launching and connecting to an AWS EC2 instance is a fundamental task for any cloud-based development or application hosting. This guide will walk you through the steps to create and connect to an EC2 instance on AWS, and then verify the connection by running some basic commands.

Prerequisites

Before starting, ensure you have an AWS account. ☁️

Step 1: Launch an EC2 Instance

  1. Log in to your AWS Management Console. πŸ”‘

  2. Navigate to the EC2 Dashboard and click on "Launch Instance". πŸš€
    Launch Instance

  3. Configure the instance settings as follows (leave other settings as default):

    • Enter the name of the EC2 Instance (e.g., "My EC2 Instance"). πŸ–₯️ Enter the name of the EC2 Instance
    • Select Ubuntu as the Amazon Machine Image (AMI). 🐧 Select Ubuntu as the AMI
    • Create a key pair to access the instance from the command line. πŸ”‘ Create a key pair button click
    • Enter an appropriate name for the key pair. πŸ“ Key pair configurations This will save the key pair file (named ec2-instance.pem in this case) to your local machine. πŸ’Ύ
    • Configure the Security Group - add a rule to allow HTTP traffic (port 80). πŸ”’ Allow HTTP traffic
  4. Review your settings and launch the instance. βœ…
    EC2 Instance summary

Step 2: Connect to Your EC2 Instance

After the instance is successfully running:

  1. Click on the Instance ID of the EC2 instance you just created. πŸ†”
    EC2 Dashboard Running Instances Running Instances

  2. On the Instance summary page, click on the Connect button. πŸ”Œ
    EC2 Instance summary

  3. Copy the command to connect to the EC2 instance. πŸ“‹
    Connect to the EC2 Instance

  4. Open a new local terminal from where the private key was saved. πŸ–₯️

  5. Run this command to ensure your key is not publicly viewable:

    sudo chmod 400 "ec2-instance.pem"
    
  6. Paste the command copied from Step 3 to connect to your instance:

    sudo ssh -i "ec2-instance.pem" ubuntu@ec2-18-208-219-229.compute-1.amazonaws.com
    

Step 3: Verify Your EC2 Instance

After connecting to the EC2 instance, you can use commands as you would on your local machine. Here are some common commands to verify and manage your instance:

  1. Update the package list:

    sudo apt update
    
  2. Upgrade the installed packages:

    sudo apt upgrade -y
    

Conclusion

You've successfully launched, connected to, and verified your AWS EC2 instance. This setup can now serve as the foundation for your web applications or development environment. 🌐

Additional Resources

If you have any questions or run into issues, feel free to leave a comment below.

Happy cloud computing! β˜οΈπŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Top comments (0)