# #Day43:-S3 Programmatic access with AWS-CLI 💻 📁

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1709906858246/fbbbe373-e818-400d-a273-4b08a4b337c9.png align="center")

### 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.

### Task-01

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

* Open the Amazon Management Console and sign in.
    
* Use the console to access the EC2 service and start an instance.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFHA13xHSZBeg/article-inline_image-shrink_1500_2232/0/1679034759984?e=1715212800&v=beta&t=C7IzeTFW6u_pVBX358TAI44fYb3ULjLuFvxqILVZn-Y align="left")

* Connect to the EC2 instance using SSH.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGSXpbU7Ff_OA/article-inline_image-shrink_1500_2232/0/1679034850728?e=1715212800&v=beta&t=O6N5i2DThfhDsXpNR3WknLv2VRNM_-NXDkwQaDWygAw align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQEtG6x2i2CP0g/article-inline_image-shrink_1500_2232/0/1679034883016?e=1715212800&v=beta&t=xfCX0r3hP3C8YGLK_8SL6phW7xByE9v_5gE3giJUJQA align="left")

**Use the AWS Management Console to create an S3 bucket and add a file to it.**

* Go to the S3 service in your Amazon Management Console after logging in.
    
* Choose "Create bucket" from the menu.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQH0_4dKFaBMMQ/article-inline_image-shrink_1500_2232/0/1679035069473?e=1715212800&v=beta&t=hGW9bMjlb6b8WTKua1Sb6pOcMDFbALdCUWLD-F-lBVA align="left")

* Click "Create" after giving your bucket a distinct name and choosing the region you want it to be created in.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQE_znxlnfRTVA/article-inline_image-shrink_1500_2232/0/1679035147213?e=1715212800&v=beta&t=HRqUW4SNx0hN_y6Y01-yxDiFYVR65Li2tlhBMZhxpXY align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFDgkJrwtchaQ/article-inline_image-shrink_1500_2232/0/1679035159388?e=1715212800&v=beta&t=6MwM8rsacYoaRZRMfuCmnIpGRirbMsAVK90VGYD0rt8 align="left")

* Click on 'Create Bucket'
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQHZ3bNEo_TGhw/article-inline_image-shrink_1500_2232/0/1679035320135?e=1715212800&v=beta&t=-KCe79KbC6-l_1cxvEUILg9hK36yjKsi6215vdrTgS4 align="left")

* To upload a file, click the "Upload" button.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGtigCpTB0YWQ/article-inline_image-shrink_1500_2232/0/1679035410815?e=1715212800&v=beta&t=gINd0zpM9Chs9Mycu8e7dZKlIMPKiHLfRQH4sUVL1B0 align="left")

* Choose the file you wish to upload by clicking the "Add files" button in the "Upload" window.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQH3n2pKt9opYA/article-inline_image-shrink_1500_2232/0/1679035462080?e=1715212800&v=beta&t=Gpsni4-z0yES8YnOEK_ba3klv6_Ka5vBd5nW0PtcFxM align="left")

* Click "Next" after selecting your file.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQEixjHVPr6aJA/article-inline_image-shrink_1500_2232/0/1679035617729?e=1715212800&v=beta&t=c5KPgLL1drivGXyMSlBJRdS2MXf6vOcUutLadHii4zg align="left")

* You may see the file in your S3 bucket once the upload is finished.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQElbY8hT9_qHw/article-inline_image-shrink_1500_2232/0/1679035785351?e=1715212800&v=beta&t=ccquDAi90FyjO8NkkuJvBywHBHeLe1GaGuPj3k82Ky4 align="left")

**Use the AWS Command Line Interface to access the file from the EC2 instance (AWS CLI).**

* Activate the AWS CLI.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGqcavf1LTWHQ/article-inline_image-shrink_1500_2232/0/1679035851839?e=1715212800&v=beta&t=kwezexwpedAcpnqho4lpnv18YBNA9I4mziUk2N5LIDI align="left")

* Check aws-cli installed or not using checking aws version
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGGyHYPOATFpw/article-inline_image-shrink_1500_2232/0/1679035886489?e=1715212800&v=beta&t=cwElp228IqhAsr7C2FvUP6mImxLk2_5F34pFwXWgXZE align="left")

* After setting up the Amazon CLI, configure your account credentials by launching a terminal and using the command aws configure.
    
* Type in your Secret Access Key and AWS Access Key ID.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQHGksuomQf6Pg/article-inline_image-shrink_1500_2232/0/1679035943132?e=1715212800&v=beta&t=BBrZ4SLn8tugouQ_qRMfGSazYCHdsplT5anU-0BVNqQ align="left")

* List s3 buckets using the below command:
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFG_Y-h09cJtg/article-inline_image-shrink_1500_2232/0/1679035986860?e=1715212800&v=beta&t=rvNRCTGlmtEVj6TtWRoBCA5Sqt-fsJ-5MJrDslO1Oi0 align="left")

* To copy the file from your S3 bucket to your EC2 instance, use the aws s3 cp command.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFpeSpxMQRSZw/article-inline_image-shrink_1500_2232/0/1679036054639?e=1715212800&v=beta&t=bMhsKT_yKvCm8OYZqRp7qewpdF3iE1SeWmFLFSFRwrE align="left")

## Task-02

**Create a snapshot of the EC2 instance and use it to launch a new EC2 instance.**

The EC2 instance that you wish to take a snapshot of should be selected.

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQEKfKKFbR_IKw/article-inline_image-shrink_1500_2232/0/1679036131097?e=1715212800&v=beta&t=a6x-pW7itmyJj-EpE9wubgJtf8toITrCNoo6R_EU5to align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQEat8NzHU6W6g/article-inline_image-shrink_1500_2232/0/1679036144189?e=1715212800&v=beta&t=-g2Zy7BgLvtKPOAxnuomi9sl2xyBhJmWR-Xm8h1OImM align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGg714dyu_udg/article-inline_image-shrink_1500_2232/0/1679036274211?e=1715212800&v=beta&t=LDzGMUjU4sF2IKB_KTJiFDZu9TkqcCeXO0YzLEOj_HY align="left")

* a snapshot was taken.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFUDLnxjbiH9Q/article-inline_image-shrink_1500_2232/0/1679036300084?e=1715212800&v=beta&t=-k6P7zDt2x-vR6GkmtBZ2G8eZEBA4ygPCZbq3EFfAdw align="left")

Launch a new EC2 instance using a snapshot.

Generate an image from the snapshot by clicking Actions on the right side of the screen.

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGlbopPZXF1hQ/article-inline_image-shrink_1500_2232/0/1679036356452?e=1715212800&v=beta&t=nKAYnoKbnRZt9oDJDaYmSKrUXU73HGP-jJdSgeCBFrU align="left")

Give the image a name and a description in the "Create Image from Snapshot" dialogue.

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFZs-ExoEat5Q/article-inline_image-shrink_1500_2232/0/1679036494317?e=1715212800&v=beta&t=LWFpkJKQD-t8EZcK3Lx6cFfyScEO19q811kLkscOWs0 align="left")

Click on "Create an image."

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQEVDP3v4aOh1Q/article-inline_image-shrink_1500_2232/0/1679036551324?e=1715212800&v=beta&t=7IvUFYtjQ0nX7KVPQQHC5H-f54vFzrhek3iR_MVrvHM align="left")

Visit the "AMIs" section of the EC2 Dashboard after the image has been produced.

check image is created.

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFa3ecH8jzv3A/article-inline_image-shrink_1500_2232/0/1679036669780?e=1715212800&v=beta&t=1IPuact2q8F71KZQMejmvpC7sXwJlkqjrCkPayx-Tyo align="left")

Right-click on the freshly built AMI to select "Start Instance."

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQHrcY8tOH6NwQ/article-inline_image-shrink_1500_2232/0/1679036714847?e=1715212800&v=beta&t=f5OiBlOEeOpKQNFec02kZiZWLEQOPrGRRVwO59fGZDo align="left")

Choose the configuration choices for the new instance in the "Launch Instance" window.

Choose the VPC and subnet where you want the new instance to start.

You can change the storage volumes in the "Add Storage" section to suit your needs.

After looking over the instance's specifications, click "Launch instance" to start a fresh instance.

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFBy5KpLV18iw/article-inline_image-shrink_1500_2232/0/1679036790355?e=1715212800&v=beta&t=sw_IZYgunMWkO1DRLRXntmKSpLFqPXpf4Tl92cSs5U8 align="left")

Connect to the instance using SSH:

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQErOfIHehf4jA/article-inline_image-shrink_1500_2232/0/1679036912850?e=1715212800&v=beta&t=cjGYY7P7hKzS4KnvOL5CsNaxecZw00dRsrwpdM5Gors align="left")

here login as the user "ubuntu" rather than the user "root"

Download a file from the S3 bucket using the AWS CLI.

aws s3 cp command to download the file from your S3 bucket to your EC2 instance.

```apache
aws s3 cp s3://BUCKET_NAME/PATH/TO/FILE /PATH/TO/LOCAL/FILE
```

### AWS CLI commands for S3:

Here are some commonly used AWS CLI commands for Amazon S3:

**aws s3 ls** \- This command lists all of the S3 buckets in your AWS account.

**aws s3 mb s3://bucket-name** - This command creates a new S3 bucket with the specified name.

**aws s3 rb s3://bucket-name** - This command deletes the specified S3 bucket.

**aws s3 cp file.txt s3://bucket-name** - This command uploads a file to an S3bucket.

**aws s3 cp s3://bucket-name/file.txt .** - This command downloads a file from an S3 bucket to your local file system.

**aws s3 sync local-folder s3://bucket-name** - This command syncs the contents of a local folder with an S3 bucket.

**aws s3 ls s3://bucket-name** \- This command lists the objects in an S3 bucket.

**aws s3 rm s3://bucket-name/file.txt -** This command deletes an object from an S3 bucket.

**aws s3 presign s3://bucket-name/file.txt** \- This command generates a pre-signed URL for an S3 object, which can be used to grant temporary access to the object.

**aws s3api list-buckets** \- This command retrieves a list of all S3 buckets in your AWS account, using the S3 API.
