简体   繁体   中英

Luigi write file directly to S3

I'm creating a data pipeline with Luigi and I'm trying to write the processed data to S3 bucket directly. The code I used is:

import luigi
from luigi.s3 import S3Target, S3Client

class myTask(luigi.Task):
    def requires(self):
        return otherTask()

    def output(self):
        client = S3Client('ACCESS_KEY', 'SECRET_KEY')
        return S3Target('s3.amazonaws.com/mybucket/myfolder/myfile.tsv', client=client)

    def run(self):
         fo = self.output().open('w')
         with self.input().open('r') as f:
            data = dosomething_to_input(f)
            fo.write(data)
         fo.close()

After I run the script, I got Error:

S3ResponseError: S3ResponseError: 405 Method Not Allowed

Can we directly write file into S3 bucket?

Problem solved! It's because of the format of the s3 buckt. The correct format should be 's3://mybucket/myfile' The 405 ERROR is caused by boto not recognizing the bucket name. Also need to mention that boto does not recognize bucket name with '.' in it in Python 2.7.*, so you have to use a valid bucket name or change it in the config file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM