Dive into Cloud Mastery : Launch and Connect to AWS EC2 ??

Dive into Cloud Mastery : Launch and Connect to AWS EC2 ??

Welcome to our step-by-step guide on launching and accessing an EC2 instance in AWS! Whether you’re new to Amazon Web Services (AWS) or you’re looking to expand your cloud computing skills, this tutorial is perfect for you.

In this hands-on guide, we’ll take you through the entire process of creating your own virtual server in the AWS cloud and connecting to it. EC2 instances are essentially virtual machines that you can use to host and run your applications on the cloud. By the end of this guide, you’ll be equipped with the knowledge and confidence to launch your EC2 instance and access it remotely.

So, Let’s get started and unlock the full potential of AWS EC2 together!


AUTHORS : Manasvi Mathur ? Aniruddh Saxena


Amazon EC2 (Elastic Compute Cloud) Overview

Amazon EC2 is a web service provided by AWS that allows users to run virtual servers (instances) in the cloud. It is designed to provide scalable computing capacity, enabling businesses and developers to deploy and manage applications without the need to invest in physical hardware.


Key Features of AWS EC2 :

  1. Scalability: Easily scale up or down the number of instances based on demand.
  2. Customizable Instances: Choose instance types with specific CPU, memory, storage, and networking configurations to meet your needs.
  3. Cost-Efficiency: Pay only for the compute capacity you use with flexible pricing options like On-Demand, Reserved, and Spot instances.
  4. Global Availability: Deploy instances in various AWS regions and Availability Zones for redundancy and reduced latency.
  5. Security: Utilize security groups, key pairs, and VPC (Virtual Private Cloud) for robust security.
  6. Automation: Automate scaling and management with services like Auto Scaling and Elastic Load Balancer (ELB).


General Use Cases :

  • Hosting Websites and Applications: Perfect for web hosting with reliable and scalable infrastructure.
  • Data Processing: Run large-scale analytics and batch processes.
  • Development & Testing: Create isolated environments for testing applications.
  • IoT Applications: Host and process data for IoT devices.


Real-Life Companies Using AWS EC2 :

  1. Amazon : Handles peak traffic during Black Friday and holiday sales.
  2. Netflix : Powers global video streaming with EC2.
  3. Airbnb : Processes big data for user experience improvements.
  4. Fortnite : Hosts low-latency multiplayer game servers.
  5. Zillow : Trains machine learning models for real estate insights.
  6. Coursera : Hosts courses and scales for millions of learners.
  7. Udemy : Provides infrastructure for global education.
  8. Disney : Renders animations and processes video content.
  9. GE Healthcare : Analyzes medical data and supports genomic research.
  10. Tesla : Manages IoT data from connected vehicles.


Prerequisites :

AWS Console Account : Ensure you have an AWS account. It is recommended to utilize free-tier services to avoid costs.


Step-by-Step Instructions :

1. Log in to the AWS Management Console

2. Access the EC2 Service

  • Search for “EC2” in the search bar or locate it in the services menu.

3. Launch an Instance

  • Click on the?“Launch Instance”?button.

4. Provide Instance Name and Tags

  • Enter a name for your instance and assign tags if necessary.


5. Choose your OS and Software - The Amazon Machine Image (AMI)

An AMI is a template that contains the operating system and software required to launch your instance.

  • Choose an AMI (e.g., Amazon Linux 2) that is free-tier eligible.


6. Choose your Hardware - The Instance Type

An instance type determines the CPU, memory, storage, and networking capacity of the host computer used for your instance.

  • Select?t2.micro?(default/free)

EC2 Instance Types :

  • General Purpose: For balanced workloads (e.g.,?t2.micro,?t3.medium).
  • Compute Optimized: For compute-intensive applications (e.g.,?c5.large,?c6g.xlarge).
  • Memory Optimized: For high-memory needs (e.g.,?r5.large,?x1e.32xlarge).
  • Storage Optimized: For heavy storage I/O (e.g.,?i3.large,?d2.xlarge).
  • Accelerated Computing: For GPU workloads (e.g.,?p4d.24xlarge).
  • Burstable Instances: For spiky workloads (e.g.,?t2.nano,?t4g.micro).

7. Configure Key Pair

  • Create a new key pair, Enter key pair name (for eg: key_pair_1)
  • Important: Download and securely store the private key file.

NOTE:?If you already have a key pair, you can use an existing one to connect to your instance.


Role of Key Pair in AWS Cloud :

1. Secure Authentication:

  • Key pairs are used to securely authenticate to your AWS EC2 instances.
  • Instead of passwords, AWS uses cryptographic?key pairs?(public and private keys) to ensure secure access.

2. How It Works:

  • When you launch an EC2 instance, you associate it with a?key pair.
  • AWS keeps the?public key?on the instance, while you download the?private key?(saved as a?.pem?file) to your local system.
  • To connect to the instance (via SSH), your local SSH client uses the?private key, which is matched against the stored public key.

3. Security Best Practices:

  • Keep the private key secure and never share it.
  • If the private key is lost, you won’t be able to log in to the instance (manual recovery methods would then be needed).

Key Pair Types:

  1. RSA: A widely used encryption algorithm for creating key pairs. RSA keys are the default for many AWS instances and have been in use for decades.
  2. ED25519: A modern and more secure elliptic curve encryption algorithm. It is faster, offers stronger security, and is typically recommended for more security-sensitive use cases.

Private Key File Format:

  • .pem: The default private key file format used by AWS for key pairs (especially for RSA). It is used to authenticate users with EC2 instances.
  • .ppk: A format used by?PuTTY, a popular SSH client for Windows. You can convert?.pem?files to?.ppk?using tools like PuTTYgen.


Click on "Create new key pair"


Enter


Key_pair_1.pem Will be Automatically Downloaded when you will click on Create Key pair



8. Configure Network Settings

  • Create a security group to allow?SSH?and?HTTP?traffic.

1. Network:

  • VPC (Virtual Private Cloud): The virtual network where your EC2 instance will reside. You can choose an existing VPC or create a new one during instance launch. (vpc-01fc975d391cd629f)

2. Subnet:

  • A subnet is a range of IP addresses within a VPC. Each EC2 instance needs to be placed in a subnet. Subnets can be either public (with internet access) or private (without internet access). You select a subnet to determine the availability zone.

3. Auto-Assign Public IP: (Enable)

  • When you launch an EC2 instance, you can enable?Auto-Assign Public IP?to allow the instance to get a public IP address automatically. This is essential for accessing the instance over the internet. By default, this option is enabled for instances launched in a public subnet.

4. Firewall — Security Groups:

  • Security Groups?act as a virtual firewall for your EC2 instances, controlling inbound and outbound traffic. They allow you to specify which traffic is permitted or denied.
  • Common Ports to Allow:
  • SSH (Port 22): For remote access to Linux EC2 instances.
  • HTTP (Port 80): For web traffic to your instance (for websites).
  • HTTPS (Port 443): For secure web traffic (encrypted websites).
  • You configure security group rules to permit or block specific traffic based on IP addresses and ports.

5. IP Address:

  • Private IP: Automatically assigned to each EC2 instance when launched. It’s used for communication within the same VPC.
  • Public IP: If enabled (via?Auto-Assign Public IP), this IP allows external access to the EC2 instance over the internet.



9. Configure your Storage

An Amazon EBS volume is a storage device that functions like a physical hard drive. The root volume is a special EBS volume that stores the AMI, which includes the operating system and software needed to boot your instance.

  • Specify storage requirements (default is 8 GB for free-tier).



10. Advanced Details

  • 1. Domain Join Directory:?Allows EC2 to join an Active Directory domain.
  • 2. IAM Instance Profile:?Grants the EC2 instance specific permissions to interact with AWS services.
  • 3. Hostname Type:?IP Name/DNS Hostname: Automatically assigns DNS names for the instance.
  • 4. Instance Auto-Recovery:?Automatically recovers an EC2 instance if impaired due to hardware issues.
  • 5. Shutdown Behavior:?Defines instance shutdown behavior (Stop or Terminate).
  • 6. Hibernate Behavior: Stop/Hibernate: Saves memory state (hibernate) or just stops the instance.
  • 6. Hibernate Behavior: Stop/Hibernate: Saves memory state (hibernate) or just stops the instance.
  • 7. Termination Protection:?Prevents accidental termination of the instance.
  • 8. Stop Protection:?Enable/Disable: Prevents the instance from being stopped unless protection is disabled.
  • 9. Detailed CloudWatch Monitoring:?Provides enhanced instance performance monitoring.
  • 10. Credit Specification:?Defines CPU crediting for burstable instance types (e.g., T2).
  • 11. Placement Group:?Configures how instances are distributed across hardware (cluster, spread, or partition).
  • 12. EBS-Optimized Instance:?Dedicated throughput between EC2 and EBS for improved I/O performance.
  • 13. Instance Bandwidth Configuration:?Configures the network bandwidth for the instance.
  • 14. Purchasing Option:?Spot Instances/Capacity Reservation: Allows selecting discounted or reserved instance options.
  • 15. Tenancy:?Specifies whether the instance runs on dedicated hardware or shared (default).
  • 16. RAM Disk ID & Kernel ID:?Specifies custom RAM disk or kernel for the instance.
  • 17. Nitro Enclave: Isolated, secure environments running alongside EC2 for sensitive data processing.
  • 18. License Configurations:?Configuration for using custom or AWS-provided licenses.
  • 19. CPU Options:?Configure CPUs to optimize performance or save on licensing costs.
  • 20. Metadata Accessible:?Controls whether EC2 instance metadata is accessible by applications.
  • 21. Metadata IPv6 Endpoint:?Configures IPv6 endpoint for metadata access.
  • 22. Metadata Version:?Chooses metadata service version (V1 or V2).
  • 23. Metadata Response Hop Limit:?Limits metadata exposure across multiple network hops.
  • 24. Allow Tags in Metadata:?Enables including tags in instance metadata.
  • 25. User Data:?Custom scripts executed on instance startup.

Example: User Data ( Optional)

# Install Apache HTTP server
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html        

11. Summary

  • Specify the number of instances you want to launch in the summary section.


12. Review and Launch

  • Review all settings to ensure everything is correct
  • Click?“Launch Instance”.


13. Click On View All Instance

  • Once the instance is launched, you’ll see a success message.

  • Scroll down and click on the “View all Instances” button.


14. Check Instance State : “Running”

  • In the instances list, locate your newly launched instance and wait for it to reach the “running” state with passing status checks.


15. Connect To Your Instance

15.1 Connect via EC2 Instance Connect (for Linux/Unix instances)

EC2 Instance Connect is a feature that enables you to connect to your EC2 Linux instance directly from the AWS Management Console without needing to configure SSH key pairs or manage SSH access manually. This is especially useful for one-time or emergency access.

1?? Ensure EC2 Instance is Running

  • Open the EC2 Dashboard in the AWS Management Console.
  • Ensure the instance you want to connect to is running.
  • Check that the instance has an Elastic IP or a public IP assigned to it.

2?? Open the EC2 Console

  • Go to the EC2 Dashboard.
  • Under Instances, click on the instance that you want to connect to.

3?? Use EC2 Instance Connect

  • In the Instance Description section, click on the Connect button at the top of the screen.
  • Choose EC2 Instance Connect (Browser-Based SSH connection).
  • In the Connect to your instance dialog, make sure EC2 Instance Connect is selected.
  • You should see a Connect button at the bottom. Click it.

Select
In "Connect to Instance "


AWS will open a browser-based terminal that allows you to execute commands on your EC2 instance. You can now start managing your EC2 instance directly from the browser

Now that you have connected to your EC2 instance through your operating system, you can execute any Linux command to verify that it is working properly.

15.2 Connect via SSH for Windows Users (Using PuTTY )

Windows does not include an SSH client by default. However, you can use PuTTY, a popular third-party application for SSH access.

1??Download and Install PuTTY

  • Install PuTTY on your Windows system.
  • Download PuTTY from here.

2?? Convert PEM File to PPK Format

PuTTY uses the PPK (PuTTY Private Key) format for SSH keys, so you need to convert your PEM file to PPK format using PuTTYgen.

  • Open PuTTYgen (installed with PuTTY).
  • Click Load and select your .pem file.
  • Once the PEM file is loaded, click Save private key to save it as a .ppk file.

3??Configure PuTTY for SSH

  • Open PuTTY.
  • In the Host Name field, enter the Public IP address of your EC2 instance.
  • Under Connection > SSH > Auth, click Browse and select your .ppk file.
  • Click Open to start the SSH session.
  • Log in as ec2-user (for Amazon Linux/2) or ubuntu (for Ubuntu).


Instance Management in AWS EC2

1?? Stopping an EC2 Instance

  • You can stop an EC2 instance, which will halt the instance while retaining the associated data (like EBS volumes). The instance can be started again later.
  • Stopping an instance does?not?incur running costs, but storage costs for the attached volumes will still apply.

2?? Terminating an EC2 Instance

  • Terminating an EC2 instance will?permanently delete?the instance and its associated data.
  • Important: Always backup your data before terminating an instance, especially if it’s running important workloads.

3?? Rebooting an EC2 Instance

  • Rebooting an EC2 instance simply?restarts?the instance, keeping all configurations and data intact.
  • This action does not incur additional charges. It is often used to apply changes (e.g., system updates) or troubleshoot instance issues.
  • You can reboot an instance from the?EC2 Dashboard?or by using the CLI command:

aws ec2 reboot-instances --instance-ids i-xxxxxxxxxxxxxxxxx        

Conclusion :

In this guide, we’ve walked through the essential steps to launch and access EC2 instances in AWS. By following these steps, you now have the knowledge to create and manage your own virtual server in the cloud. EC2 instances offer great flexibility and scalability for running your applications.

Keep exploring EC2’s features and configurations to fully harness the power of AWS cloud services. Do let us know if you encounter any issues, If you found this useful, feel free to share it within your community.

For more cloud computing and AWS content, feel free to connect with us on :

Manasvi Mathur | LinkedIn

Aniruddh Saxena | LinkedIn?

Thank You For Reading!

?? Check Out Our Other Hands-On Tutorials Here :

?? Creating Linux Server And Configuring Web Servers on Virtual MachineCustom Webpage Deployment & Configuration Read Here

?? Setting Up Active Directory on Windows Server and Joining a Client Machine to the Domain (With AWS Windows Server Setup) ??Read Here

?? Launching and Accessing an EC2 Instance — A Hands-On Tutorial ??Read Here


? THE END ?



要查看或添加评论,请登录

社区洞察

其他会员也浏览了