S3 Programmatic access with AWS-CLI

S3 Programmatic access with AWS-CLI

ยท

3 min read

S3 : Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.

We learn all the below commands in this blog.

-->copy file S3 bucket to local

-->using CLI create bucket

-->Create a bucket in the specified region

-->Move a local file to the specified bucket

-->Delete an S3 object -->Delete a bucket

Task 1: Launch an EC2 instance using the AWS Management Console and connect to it using Secure Shell (SSH).

You can visit my blog ( https://utkarsh80.hashnode.dev/amazon-elastic-compute-cloud ) to learn about launching EC2 instances.

Task 2: Create an S3 bucket and upload a file to it using the AWS Management Console.

You can visit my blog ( https://utkarsh80.hashnode.dev/how-to-host-a-static-website-using-amazon-s3#heading-task-1-create-a-new-s3-bucket ) to learn about Create a S3 Bucket

Task 3: Setup and install AWS CLI and configure your account credentials

You can visit my blog( https://utkarsh80.hashnode.dev/iam-programmatic-access-and-aws-cli#heading-setup-and-install-aws-cli-and-configure-your-account-credentials ) to learn about Install AWS CLI

After Configure the AWS CLI with your access key ID and secret access key using aws configure

Use the aws s3 ls command to check the list of S3 buckets from your EC2 instance:

After executing the command we got some error:

Now need to set Permissions page will open in that select Attach policies directly and select Administrator Access AmazonS3FullAccess and scroll down and click on Next.

Now, try again with aws s3 ls command

Copying an S3 object to a local file

The following cp command copies a single object to a specified file locally:

aws s3 cp s3://mybucket/test.txt /home/ubuntu

output:

Create a bucket

The following mb command creates a bucket. In this example, the user makes the bucket mybucket. The bucket is created in the region specified in the user's configuration file:

aws s3 mb s3://mybucket

We can also see in the S3 console that the new bucket has been created.

Create a bucket in the specified region

The following mb command creates a bucket in a region specified by the --region parameter. In this example, the user makes the bucket mybucket in the region us-east-2:

aws s3 mb s3://mybucket --region us-east-2

We can also see in the S3 console that the new bucket has been created in the specified region.

Move a local file to the specified bucket

The following mv command moves a single file to a specified bucket and key.

aws s3 mv test.txt s3://mybucket/test2.txt

We can also see in the S3 console go to the specific bucket where you upload the file.

The following rm command deletes a single s3 object:

aws s3 rm s3://mybucket/test2.txt

The following rb command removes a bucket. In this example, the user's bucket is mybucket. Note that the bucket must be empty in order to remove:

aws s3 rb s3://mybucket

Happy Learning

Thank you for the reading!๐Ÿ˜Š

ย