I want to upload folder in S3, but I have lot of folders which have space between their names. It’s an automate process, so could not change the name of the folders manually (from abc d to ‘abc d’).
folder_name = abc d
import os
cmd = 'aws s3 sync'+''+folder_name+'/'+''+s3path+folder_name+'/'
os.system(cmd)
Will be pasting ,my code here. Will be glad if it helps:)
!pip install boto3 ##install boto3
!pip install s3fs ##required package
import boto3
import pandas as pd
s3 = boto3.client('s3')
s3 = boto3.resource(
service_name='s3',
region_name='us-east-2',
aws_access_key_id='',
aws_secret_access_key='')
# Upload files to S3 bucket
s3.Bucket('bucket_name').upload_file(Filename='foo.csv', Key='foo.csv')
s3.Bucket('bucket_name').upload_file(Filename='bar.csv', Key='bar.csv')
for obj in s3.Bucket('bucket_name').objects.all():
print(obj)
Note :
- the last for loop will print the keys of files that you’ve
uploaded (for confirmation).
- aws_access_key_id and aws_secret_access_key – both of these will be available in
your aws profile.