DEV Community

Harshad D
Harshad D

Posted on

Step-by-Step Guide to Launch and Manage an AWS EC2 Instance with S3 Integration

1. Introduction to AWS EC2 and S3 Integration

AWS (Amazon Web Services) offers a wide range of cloud solutions, with EC2 being a popular service for scalable computing capacity. This guide walks you through launching an EC2 instance, connecting it via SSH using PuTTY, integrating with an S3 bucket, and cleaning up resources.

2. Creating an EC2 Instance

Step 2.1: Choose Amazon Linux as the AMI

  • Log in to your AWS Management Console.
  • Navigate to the EC2 Dashboard and click Launch Instance.
  • Select Amazon Linux as your Amazon Machine Image (AMI).

Image description

Step 2.2: Choose Instance Type

  • Select t2.micro (Free Tier eligible) as the instance type.

Image description

Image description

Step 2.3: Key Pair Creation

  • Create a new key pair or use an existing one.
  • Download the .pem file and store it securely (you’ll need it to connect via SSH).

Image description

Image description

Step 2.4: Configure Security Group

  • Set up inbound rules to allow SSH (port 22) access.
  • Review and launch your instance.

Image description

Image description

3. Connecting to the Instance with PuTTY

Step 3.1: Install PuTTY

  • Download PuTTY and PuTTYgen from the official website.
  • Install and extract PuTTY on your system.

Image description

Image description

Image description

Step 3.2: Edit Security Group Inbound Rules

  • Ensure that the SSH port is open to your local machine’s IP.

Step 3.3: Convert Key Pair Using PuTTYgen

  • Use PuTTYgen to convert the .pem file to a .ppk file for use with PuTTY.

Step 3.4: Connect Using PuTTY

  • Open PuTTY and enter the Public IPv4 address of your EC2 instance in the Host Name field.
  • Navigate to Connection > SSH > Auth and upload the .ppk file.
  • Click Open to connect to your EC2 instance as the ec2-user.

Image description

4. Assigning an IAM Role for S3 Bucket Access

Step 4.1: Create an IAM Role

  • Go to the IAM Dashboard and create a new role.
  • Assign the AmazonS3FullAccess policy to the role.

Image description

Step 4.2: Attach the Role to the EC2 Instance

  • Navigate to the EC2 Dashboard, select your instance, and choose Actions > Security > Modify IAM Role.
  • Attach the newly created role to the instance.

Image description

Image description

Image description

5. Uploading Files to S3 via EC2 Terminal

Step 5.1: Create an S3 Bucket

  • Navigate to the S3 Dashboard and create a new bucket.

Image description

Step 5.2: Upload a File

  • SSH into your EC2 instance.
  • Use the AWS CLI to upload a file to the S3 bucket:

          - aws s3 cp <local-file-path> s3://<your-bucket-name>/
    

Image description

6. Cleaning Up Resources

Step 6.1: Terminate the EC2 Instance

  • Go to the EC2 Dashboard and terminate the instance.

Image description

Image description

Step 6.2: Delete the IAM Role

  • Navigate to the IAM Dashboard and delete the role.

Image description

Image description

Step 6.3: Remove S3 Bucket (Optional)

  • Delete the S3 bucket if you no longer need it.
Retry later

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Retry later