Reputation: 3709
I am trying to upload a csv file from my local to aws s3 bucket. Given below is the code I am using but it doesn't seen to upload the file to the s3 folder defined. Could anyone assist.
import boto3
from botocore.client import Config
ACCESS_KEY_ID = 'accesskeyid'
ACCESS_SECRET_KEY = 'secretkeyid'
BUCKET_NAME = 'bucketname'
data = open('/desktop/file.csv', 'rb')
s3 = boto3.resource(
's3',
aws_access_key_id=ACCESS_KEY_ID,
aws_secret_access_key=ACCESS_SECRET_KEY,
config=Config(signature_version='s3v4')
)
s3.Bucket(BUCKET_NAME).put_object(Key='/sub-folder/sub-folder2/file.csv', Body=data)
print ("Uploaded successfully")
Could anyone help me in finding where I am going wrong. Thanks
Upvotes: 1
Views: 571
Reputation: 456
You need to remove the /
from the beginning of the Key
argument.
Using your existing code, the file path will be: BUCKET_NAME//sub-folder/sub-folder2/file.csv
.
Upvotes: 1