[Python] Upload file in the S3 bucket

Jua KIM·2021년 11월 29일
0

Using boto3 client

import boto3

s3c = boto3.client('s3')
s3_bucket_name = "{s3 bucket name: ex) s3_bucket}"
s3_key = "{s3 key name: ex) test/test.csv}"

file_path = "{file path}"
file = open(file_path, 'r')

s3c.put_object(Bucket=s3_bucket_name, Key=s3_key, Body= file)

Using boto3 resource

import boto3

s3_resource = boto.resource('s3')
s3_bucket_name = "{s3 bucket name: ex) s3_bucket}"
s3_key = "{s3 key name: ex) test/test.csv}"

file_path = "{file path}"
file = open(file_path, 'r')

s3.Object(bucket_name=s3_bucket_name, key=s3_key).put(Body=file)
profile
AI/ML engineer

0개의 댓글