How to Upload to an AWS S3 Bucket from a Raspberry Pi

 

 Learn how to easily upload images videos and other data to a cloud storage bucket, Amazon S3. This is essential for many IoT applications. It is free to get started all you will need is an AWS account and some simple Python code! We are using a Raspberry Pi 4b for this video but you can use any Raspberry Pi model other than the Pico W.

Before reading the remainder, be sure to subscribe and support the channel if you have not!

Subscribe:

Youtube

Support:

https://www.buymeacoffee.com/mmshilleh

 

 

 

1-) S3 Setup

The first thing you want to do is create an AWS account by going to

aws.amazon.com

It is free to get started.

Once you enter AWS go into the Console search S3, and select the S3 panel which will allow you to create an S3 bucket. You can click through the steps to generate an S3 bucket with the default settings.

 

Name the bucket however you like.

Now that you have an empty bucket the next thing you will need is to create users with admin privileges to that bucket so they can put objects into the bucket from the Python code. Search the terms 'Users' in the console select the Users panel and click Create New User.

 

 

You need to then select the user and create a group under the Groups tab (see images), make sure the group has administrative privileges, or else you will get an error when trying to place an item into the bucket.

 

 

 

Finally, you want to create an Access/Secret Key pair for the user (See Images), ensure you save the values somewhere safe because this can allow people access to your bucket which can be dangerous for your application security.

 

 

Now that you have that, we are done on the S3 side of things and we can jump to the code!

 

 

 

2-) Code

Open any editor you like on your Raspberry Pi and create a Python file with the code in the project downloads.

Replace the respective values for your keys and your bucket name. There are a total of 3 values in the code you need to replace.

In this code specifically, all we are doing is taking a photo and a video with the Raspberry Pi camera, saving it to a local path on our Raspberry Pi desktop, and then sending it to S3 with the boto3 client, which is the official Python SDK for S3.

If this is your first time using S3 in Python on the Raspberry Pi you will have to pip install boto3, and you will also have to pip install picamera if you choose to use a camera to take an image. Really you do not need a camera, you can just upload any image you want if you have an existing image.

Finally, if the code ran successfully, you can go and view the object in your S3 bucket by going back to the AWS website and going to the bucket. You should see the names of the objects you created. Select one, and from the top right section you can Open or Download the item!

Congrats! This is a very powerful tool you can utilize for applications, especially those involving IoT. You are not limited to images or videos in S3 buckets, you can add all sorts of data necessary for your cloud storage needs. Get creative ;)

Create a free account to access full content.

All access to code and resources on ShillehTek.

Signup Now

Already a member? Sign In

Explore More on Our Blog

How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

Learn how to set up the HCSR501 PIR sensor with a Raspberry Pi Pico to detect motion and trigger...

Powering the Raspberry Pi Pico W with the MB102 Power Supply

Powering the Raspberry Pi Pico W with the MB102 Power Supply

Learn how to power your Raspberry Pi Pico W projects easily and flexibly with the MB102 Power Supply Module...

How to Use L298N Motor Driver with Pico W

How to Use L298N Motor Driver with Pico W

Learn how to use the L298N motor driver to control DC motors with the Raspberry Pi Pico W in MicroPython.

Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

Discover how to set up, code, and activate the LED based on detected sound with the Raspberry Pi...

Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

In this tutorial, I’ll guide you through setting up the KY-037 sound sensor with a Raspberry Pi using...

How to Post to Reddit Using Python

How to Post to Reddit Using Python

Post to reddit automatically using a Python script.

How to Create a Time-Lapse Video with a Raspberry Pi Camera

How to Create a Time-Lapse Video with a Raspberry Pi Camera

Learn how to make a timelapse with your Raspberry Pi in Python.

How to Integrate the MPU6050 with the STM32 Blue Pill

How to Integrate the MPU6050 with the STM32 Blue Pill

Learn how to measure acceleration with the STM32 and the MPU6050 in the Arduino IDE.

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill...

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

In this tutorial, I'll show you how to automatically schedule tasks in AWS at regular intervals using AWS...

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.