Links

Upload file to S3 bucket

Tags: #aws #cloud #storage #S3bucket #snippet #operations# AWS - Upload file to S3 bucket
Author: Maxime Jublou
Description: This notebook provides instructions on how to upload a file to an Amazon Web Services (AWS) S3 bucket, allowing for secure storage and easy access to the file. It is a simple and efficient way to store and manage data in the cloud.

Input

Import library

try:
import boto3
except:
!pip install boto3 getpass4
import boto3

Variables

ACCESS_KEY_ID = "**********"
SECRET_ACCESS_KEY = "**********"
BUCKET_NAME = "naas-example"
BUCKET_OBJECT_KEY = "naas_happy_hour.mp3"

Model

Connect to AWS

s3 = boto3.client(
"s3", aws_access_key_id=ACCESS_KEY_ID, aws_secret_access_key=SECRET_ACCESS_KEY
)

Output

Upload data

with open(BUCKET_OBJECT_KEY, "rb") as f:
s3.upload_fileobj(f, BUCKET_NAME, BUCKET_OBJECT_KEY)