EC2 Complete Tutorials

0

 Table of Contents

  1. Prerequisites
  2. Launching an EC2 Instance
  3. Connecting to an EC2 Instance
  4. Configuring Security Groups
  5. Creating and Using Key Pairs
  6. Elastic IPs
  7. EC2 Instance Types
  8. Volume Management with EBS
  9. Monitoring with CloudWatch
  10. Automating with EC2 User Data
  11. Stopping and Terminating EC2 Instances
  12. Best Practices for EC2 Usage

1. Prerequisites

  • AWS Account: Create an AWS account at AWS Sign-Up.
  • AWS CLI (optional): Download and configure the AWS CLI for command-line management of EC2.
    • Install: AWS CLI
    • Configure:


      aws configure
      Enter AWS Access Key ID, Secret Access Key, region, and output format.

2. Launching an EC2 Instance

Follow these steps to launch an instance from the AWS Console:

Step 1: Login to AWS Console

Step 2: Go to the EC2 Dashboard

  • Navigate to EC2 under the "Services" section.

Step 3: Launch Instance

  • Click on Launch Instance.

Step 4: Choose AMI (Amazon Machine Image)

  • Amazon Linux 2 or Ubuntu are popular choices.
  • AMIs come pre-configured with an OS and software.

Step 5: Select Instance Type

  • Choose an instance type (e.g., t2.micro) which is free-tier eligible.
  • Larger instances offer better CPU, RAM, and network speeds.

Step 6: Configure Instance Details

  • Specify the number of instances and VPC (Virtual Private Cloud) or subnet.
  • Choose Auto-assign Public IP to enable SSH access.
  • Add any IAM role if needed (for access to S3, CloudWatch, etc.).

Step 7: Add Storage

  • Use EBS volumes (default is 8 GB).
  • You can add additional volumes if required.

Step 8: Configure Security Group

  • Security groups act as firewalls.
  • Open SSH (Port 22) for your IP address to allow remote access.

Step 9: Review and Launch

  • Review the configurations and click Launch.
  • AWS will ask for a key pair—choose or create a new one.

3. Connecting to an EC2 Instance

Using SSH from Linux/Mac

bash

chmod 400 your-key.pem ssh -i your-key.pem ec2-user@your-ec2-public-ip

Using SSH from Windows (via PuTTY)

  • Convert .pem to .ppk using PuTTYgen.
  • Use the .ppk file to connect via PuTTY.

4. Configuring Security Groups

  • Go to the EC2 Dashboard > Security Groups.
  • Add Inbound Rules for SSH (Port 22), HTTP (Port 80), or HTTPS (Port 443) as needed.
  • Ensure that only trusted IP addresses have access to critical ports.

5. Creating and Using Key Pairs

  • Go to EC2 Dashboard > Key Pairs.
  • Create a new key pair and download the .pem file.
  • Store it securely—it’s required to connect to the instance.

6. Elastic IPs

  • Elastic IPs are static public IPs assigned to instances.
  • Why use Elastic IP?: If an instance restarts, its public IP changes. Elastic IP ensures it remains the same.
  • Go to EC2 Dashboard > Elastic IPs > Allocate new IP.
  • Associate it with your instance.

7. EC2 Instance Types

  • EC2 instances come in different types:
    • t2.micro: General purpose, free tier.
    • m5.large: Balanced CPU and memory.
    • r6g.8xlarge: Memory-optimized for databases.
    • p4d: GPU instances for ML workloads.

8. Volume Management with EBS

  • EBS (Elastic Block Store) provides persistent storage.
  • Attach additional volumes from the Volumes section.
  • Use the following commands to mount the EBS volume:
    bash

    sudo mkdir /mnt/data sudo mount /dev/xvdf /mnt/data

9. Monitoring with CloudWatch

  • CloudWatch helps monitor CPU, network, and disk performance.
  • Go to CloudWatch Dashboard and create custom alarms for usage metrics (e.g., high CPU utilization).

10. Automating with EC2 User Data

  • You can run shell scripts at the time of instance launch using User Data.
  • Example:
    bash

    #!/bin/bash yum update -y yum install httpd -y systemctl start httpd
  • This script installs and starts the Apache web server during the instance launch.

11. Stopping and Terminating EC2 Instances

  • Stop: The instance shuts down, but you can restart it later.
  • Terminate: Deletes the instance and its attached storage (unless marked to persist).

How to Stop/Terminate:

  • Go to EC2 Dashboard > Select instance > Actions > Stop/Terminate.

12. Best Practices for EC2 Usage

  • Security:

    • Keep your key pair secure.
    • Regularly update the OS for security patches.
  • Scaling:

    • Use Auto Scaling Groups to dynamically increase or decrease instances based on traffic.
  • Cost Optimization:

    • Use Spot Instances for non-critical workloads (up to 90% savings).
    • Use Reserved Instances for predictable workloads.
  • Backup:

    • Take EBS Snapshots for backup.
    • Use AMI to create custom machine images for re-deployment.

Summary

In this guide, you learned:

  1. How to launch and connect to an EC2 instance.
  2. How to manage security groups, key pairs, and volumes.
  3. Elastic IPs, CloudWatch monitoring, and User Data automation.
  4. Best practices for cost, security, and scalability.

This tutorial offers a deep dive into every aspect of EC2. Let me know if you need further guidance or any specific help related to your instance setup!

Click to Learn AWS visit Shiva Concept Solution



Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)