Upload file to S3 bucket
Tags: #aws #cloud #storage #S3bucket
Author: Maxime Jublou

Input

Install packages

1
!pip install boto3 getpass4
Copied!

Import library

1
import boto3
Copied!

Variables

1
ACCESS_KEY_ID = "**********"
2
SECRET_ACCESS_KEY = "**********"
3
4
BUCKET_NAME = "naas-example"
5
BUCKET_OBJECT_KEY = 'naas_happy_hour.mp3'
Copied!

Model

Connect to AWS

1
s3 = boto3.client('s3',
2
aws_access_key_id=ACCESS_KEY_ID,
3
aws_secret_access_key=SECRET_ACCESS_KEY)
Copied!

Output

Upload data

1
with open(BUCKET_OBJECT_KEY, "rb") as f:
2
s3.upload_fileobj(f, BUCKET_NAME, BUCKET_OBJECT_KEY)
Copied!
Copy link
Edit on GitHub