DEV Community

Peter Johnson
Peter Johnson

Posted on

4 1

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.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay