Uploading a file to a S3 bucket with a prefix using Boto3
import boto3
s3 = boto3.resource('s3')
s3.meta.client.upload_file( 'csv1.csv', "bucketname", "prefixna/csv1.csv")
I'm assuming you have all this set up:
- AWS Access Key ID and Secret Key set up (typically stored at
~/.aws/credentials
- You have access to S3 and you know your bucket names & prefixes (subdirectories)
According to the Boto3 S3 upload_file
documentation, you should upload your upload like this:
upload_file(Filename, Bucket, Key, ExtraArgs=None, Callback=None, Config=None)
import boto3
s3 = boto3.resource('s3')
s3.meta.client.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt')
The key to note here is s3.meta.client
. Don't forget that--it worked for me!
I hope that helped.
Turns out I needed SSE:
transfer = S3Transfer(s3_client)
transfer.upload_file('/tmp/hello.txt', bucket_name, prefix+'hello-remote.txt', extra_args={'ServerSideEncryption': "AES256"})