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.
print(cmd)to see what it is try to run. You can also use an f-string, such ascmd = f"aws s3 sync '{folder_name}/' '{s3path}{folder_name}/'".cmd = 'aws s3 sync "'+folder_name+'/" "'+s3path+folder_name+'/"'