AWS Fundamentals - Launching EC2 Instances and Managing S3 Buckets

AWS Fundamentals - Launching EC2 Instances and Managing S3 Buckets

·

5 min read

Introduction :

Amazon Web Services (AWS) is a widely-used cloud computing platform that offers a wide range of services to build, deploy, and manage applications in the cloud. In this blog, we will walk through two essential tasks: Launching an EC2 instance and managing an S3 bucket. We'll cover the steps to create an EC2 instance, connect to it using Secure Shell (SSH), and then demonstrate how to create an S3 bucket, upload a file to it, and access that file from the EC2 instance using the AWS Command Line Interface (AWS CLI). Additionally, we'll explore some commonly used AWS CLI commands for Amazon S3.

Task-01: Launching an EC2 Instance and Accessing it via SSH

Amazon Elastic Compute Cloud (EC2) provides scalable compute capacity in the cloud. Let's go through the steps to launch an EC2 instance and access it using Secure Shell (SSH).

  1. Launch an EC2 Instance

    • Log in to the AWS Management Console.

    • Navigate to the EC2 dashboard.

    • Click on "Launch Instance" and select an Amazon Machine Image (AMI) of your choice.

    • Choose an instance type based on your requirements.

    • Configure instance details such as network settings, security groups, and storage.

    • Review the configuration and launch the instance.

  2. Connect to the EC2 Instance via SSH

    • Retrieve the public IP address or public DNS of the EC2 instance from the EC2 dashboard.

    • Open your terminal or SSH client and use the following command to connect to the instance:

    ssh -i <path-to-your-key.pem> ec2-user@<public-ip-or-dns>

Task-02: Managing an S3 Bucket and Accessing Data from EC2

Amazon Simple Storage Service (S3) is a highly scalable object storage service that allows you to store and retrieve any amount of data. Let's learn how to create an S3 bucket, upload a file to it, and access the file from the EC2 instance using AWS CLI.

Step 1: Create a Snapshot of the EC2 Instance

  1. Go to the AWS Management Console and navigate to the EC2 dashboard.

  2. In the left navigation pane, click on "Instances" and select the EC2 instance for which you want to create a snapshot.

  3. Right-click on the selected instance and choose "Create Image (EBS AMI)."

  4. Enter a descriptive name and description for the snapshot, then click "Create Image."

  5. The snapshot creation process will start, and you can monitor its progress in the "Snapshots" section of the EC2 dashboard.

Step 2: Launch a New EC2 Instance from the Snapshot

  1. Once the snapshot is created, go to the "AMIs" section in the EC2 dashboard.

  2. Select the snapshot you just created, click on "Actions," and choose "Launch Instance."

  3. Follow the instance launch wizard, selecting the desired instance type, network settings, security groups, and other configurations.

  4. Click "Launch" to start the new EC2 instance using the snapshot as its base.

  1. Create an S3 Bucket and Upload a File

    • Go to the AWS Management Console and navigate to the S3 service.

    • Click on "Create Bucket" and provide a unique name and region for your bucket.

    • Once the bucket is created, click on it and choose "Upload."

    • Select a file from your local system to upload to the bucket.

  2. Access the File from EC2 using AWS CLI

    • Log in to your EC2 instance using SSH, as described in Task-01.

    • Install AWS CLI on the EC2 instance using the following commands:

    sudo yum update -y
    sudo yum install -y aws-cli
  • After installation, run the following command to configure AWS CLI with your credentials:
    aws configure
  • Enter your AWS Access Key ID, Secret Access Key, default region, and preferred output format.
  1. Download the File from S3 Bucket

    • Use the AWS CLI command to download the file from the S3 bucket to your EC2 instance:
    aws s3 cp s3://<bucket-name>/file.txt .
  1. Verify File Contents on Both EC2 Instances

    • Use the cat command to view the contents of the file on the EC2 instance:
    cat file.txt

Commonly Used AWS CLI Commands for Amazon S3

  • List all S3 buckets in your AWS account:
aws s3 ls
  • Create a new S3 bucket:
aws s3 mb s3://bucket-name
  • Delete an S3 bucket:
aws s3 rb s3://bucket-name
  • Upload a file to an S3 bucket:
aws s3 cp file.txt s3://bucket-name
  • Download a file from an S3 bucket to your local system:
aws s3 cp s3://bucket-name/file.txt .
  • Sync the contents of a local folder with an S3 bucket:
aws s3 sync local-folder s3://bucket-name
  • List objects in an S3 bucket:
aws s3 ls s3://bucket-name
  • Delete an object from an S3 bucket:
aws s3 rm s3://bucket-name/file.txt
  • Generate a pre-signed URL for an S3 object:
aws s3 presign s3://bucket-name/file.txt
  • Retrieve a list of all S3 buckets using the S3 API:
aws s3api list-buckets

Conclusion

Mastering AWS services like EC2 and S3 is essential for efficiently deploying applications in the cloud. In this blog, we covered the step-by-step process of launching an EC2 instance, accessing it via SSH, creating an S3 bucket, uploading a file, and accessing that file from the EC2 instance using AWS CLI. Additionally, we explored some commonly used AWS CLI commands for Amazon S3. By understanding these tasks, you'll be better equipped to manage your cloud infrastructure effectively and leverage AWS services to their full potential. Happy cloud computing!

Did you find this article valuable?

Support DevOpsculture by becoming a sponsor. Any amount is appreciated!