DEV Community

Peter Johnson
Peter Johnson

Posted on

Upload files to AWS S3 using Python

Hi, guys in this blog I'm going to share how you can upload files to AWS S3 using Python. Before getting started make sure that you have got the following requirements installed on your machine:

  • AWS CLI
  • Configured IAM user
  • Python

To operate we will be using Boto3 which is an AWS SDK for Python which provides API for AWS infrastructure services.

We will be making use of the upload_file method. This method accepts a file name, a bucket name, and an object name.

import boto3
s3_client = boto3.client("s3")
perform = s3_client.upload_file("FILE PATH","BUCKET NAME", "OBJECT NAME")
Enter fullscreen mode Exit fullscreen mode

Explaining the code:

First of all, we import boto3, then we create an S3 client so that we can access the different methods offered by boto3, and we'll be using the upload_file method to upload our file. Upon running the code the mentioned file will be uploaded to the respective S3 bucket.

It's this simple to upload a file from your machine to an S3 bucket using Python, Hope that this was helpful to you.

Top comments (0)