S3
Amazon Simple Storage Service (Amazon S3) is an object storage service that provides a secure and scalable way to store and access data on the cloud. It is designed for storing any kind of data, such as text files, images, videos, backups, and more. Read more here
Task-01
Launch an EC2 instance using the AWS Management Console and connect to it using Secure Shell (SSH).
Create an S3 bucket and upload a file to it using the AWS Management Console.
Access the file from the EC2 instance using the AWS Command Line Interface (AWS CLI).
Read more about S3 using aws-cli here
Step1 :
Create an instance from the Amazon console
Once it is created, click on connect
Navigate to SSH client and copy the Example
Now open your terminal in a directory, where your pem. file is available
and paste the SSH command
ssh -i "rjthapaa.pem" ubuntu@ec2-34-235-115-80.compute-1.amazonaw..
-
we have connected to the instance now
Step2 : Creating a S3 bucker in AWS console
Navigate to S3 in aws console
Click on Create bucket
Provide a unique bucket name and selected region
Under Object Ownership
Click on Create bucket
We will upload a file to S3 bucket using SSH
-
Uploaded a file called rootkey.csv in S3 bucket
Now we need to access this file from S3 bucket using Aws CLI. For that you need to install AWS CLI and configure it
Once the configuration is done, try to access the S3 bucket using below command
s3 url will be available
Amazon S3>Buckets>rjtapaas3bucket>rootkey.csv
# List downs the available s3 buckets $ aws s3 ls # Copies the root.key.csv file from S3 to ec2 instance $ aws cp s3://rjtapaas3bucket/rootkey.csv /home/ubuntu
See the file from the s3 bucket downloaded to the terminal
Task-02
Create a snapshot of the EC2 instance and use it to launch a new EC2 instance.
Download a file from the S3 bucket using the AWS CLI.
Verify that the contents of the file are the same on both EC2 instances.
Navigate to Ec2 > Snapshot > Create snapshot
Set the Resource type as Instance and select the instance ID
Volumes can be optional and click on Create snapshot
Successfully created a snapshot
Now we will use a snapshot to launch an Ec2 instance
Select the snapshot and under Actions > Create image from snapshot
-
Provide the required details for the snapshot
Click on Create image
Image is created in Amazon machine Images (AMIS)
Now select the AMI image and click on Launch instance from AMI
Provide the name details for instance and launch the instance
Log in as a "Ubuntu user" rather than a "root user"
Now we will try to access the S3 bucket and download a file from it using AWS CLI
aws s3 ls aws s3 cp s3://BUCKET_NAME/PATH/TO/FILE /PATH/TO/LOCAL/FILE
AWS CLI S3 Commands
Command to list all of the S3 buckets in your AWS account.
aws s3 ls
Command to list the objects in an S3 bucket.
aws s3 ls s3://bucket-name
Command to create a new S3 bucket with the specified name.
aws s3 mb s3://bucket-name
Command to delete a specified S3 bucket.
aws s3 rb s3://bucket-name
Command to upload a file to an S3 bucket.
aws s3 cp file.txt s3://bucket-name
Command to download a file from an S3 bucket to your local file system.
aws s3 cp s3://bucket-name/file.txt .
Command to upload a file from Local to Instance
scp -i "rjthapaa.pem" rootkey.csv ubuntu@ec2-54-205-10-188.compute-1.amazonaws.com:/home/ubuntu
Here we are downloading a file name rootkey.csv from the instance to the local machine
Command to download a file from Instance to local
scp -i "rjthapaa.pem" ubuntu@ec2-54-205-10-188.compute-1.amazonaws.com:/home/ubuntu/file.txt .
A file.txt file is been downloaded from the instance to the local machine