如何读取文件夹中的所有文件并上传到具有相同名称的S3

时间:2019-01-11 05:00:16

标签: python csv boto

我需要读取指定文件夹中的所有文件并将其上传到S3存储桶。下面是我的代码。我想知道如何读取所有文件并上传所有文件。也建议我其他方式

 import time, boto3, csv
 from botocore.client import Config

 def upload():                   # uploading the data to AWS

     ACCESS_KEY_ID = '******'
     ACCESS_SECRET_KEY = '***********'
     BUCKET_NAME = '*******'

     data= open('/mnt/usbdrive/odolift/data/*'.'csv', 'rb') #reading the recieved data and preparing for write into the S3 bucket      
     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=data/*+'.csv', 
      Body=data)    # uploading the data into S3 bucket

      print ("data uploaded to AWS")

0 个答案:

没有答案