AWS S3 with python by Shoeb Ahmed
Published: 2022-06-16 07:18:59


## AWS S3 with python by Shoeb Ahmed

Amazon Web Services is an online platform that provides scalable and cost-effective cloud computing solutions.

Here we are going to explore all the methods (functions) present in boto3 packages, and we are going to S3 bucket resources.

And I am going to skip lots of theoretical concepts and jump step by step.

Make sure we have an AWS account and a root user.

Once you logged in, we just need an Access key to get a connection from AWS and python.

What we need to do, is go to the home console and see on the top right corner, click on your username as shown below:

![](https://cdn-images-1.medium.com/max/3150/1*UoSccDQH5_2qMb8d9eb3iw.png)

After clicking the drop-down click on security credentials.

![](https://cdn-images-1.medium.com/max/2000/1*Rl9HznTAgavPSNn_qCZ3GA.png)

After clicking on security credentials, we will redirect to the security page, and click on the Access Keys.

![](https://cdn-images-1.medium.com/max/2554/1*XfZugyhEKm_AGGtO-j-DeQ.png)

After clicking the Access keys, click on “Create New Access Key”, and a pop-up window comes up, and click on “Download key files”.

![](https://cdn-images-1.medium.com/max/2480/1*j1aG8fn6xSemvKWqEzvpLw.png)

Excel sheet file will be downloaded, what we have to do is that we are going to copy the AWS Access Key ID and AWS Secret Key ID.

My goal is to explore all the functions (methods) in S3 Bucket.

Let’s start coding.

And though I am going to do any task with Pandas DataFrame only. If you want any other file format, please go to my profile and find my email id and message me or write a comment.
{% gist https://gist.github.com/shoeb370/930f452c7d6ccdd6b4312c3fec49bd1b.js %}
After running the code you will observe that your new bucket is created in S3.

![](https://cdn-images-1.medium.com/max/2000/1*w5Ivzae15b0QWoA-JkCRPA.png)

Now what we are going to do, we are going to upload the csv file in S3 bucket.

First we will create a simple DataFrame
{% gist https://gist.github.com/shoeb370/6593811f0719ec1bc8a94cbf88d0ef73.js %}
![](https://cdn-images-1.medium.com/max/2000/1*OnzrzKba_8-0q-PN8kMk8w.png)

![](https://cdn-images-1.medium.com/max/2000/1*M1DTK2j1NNx8DjVQh7mBlg.png)

Now we are going to upload a CSV file which is stored in the local system, without creating a folder inside the bucket.
{% gist https://gist.github.com/shoeb370/b66494f23da6e2b42d051e969677bb7c.js %}
![](https://cdn-images-1.medium.com/max/2000/1*otPF5UIaqWui2TABTv0ZMw.png)

Now we are going to create a folder inside the bucket, inside that folder we are going to upload the code.
{% gist https://gist.github.com/shoeb370/7d31153dbd22d1d9c81a519d509570b5.js %}
![](https://cdn-images-1.medium.com/max/2054/1*JDIMqcYgRmOcm2szq0PHbA.png)

If you have a bytes-like file (i.e. binary file) or stream file so we can use uploadfileobj functions.
{% gist https://gist.github.com/shoeb370/0bf7b5b115342c47cf1107ac5ec86dd5.js %}
![](https://cdn-images-1.medium.com/max/2000/1*Mk6EE15bUblrsJ8bqGQbjA.png)

We can also upload by using the PutObject request, you must have the s3:PutObject in your IAM permissions.
{% gist https://gist.github.com/shoeb370/f2b47a9211a243a9957a758be0f34ad6.js %}
![](https://cdn-images-1.medium.com/max/2000/1*24qmx1dL_1al1b4Zq8zZUg.png)