简体   繁体   English

Luigi直接将文件写入S3

[英]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. 我正在用Luigi创建一个数据管道,我正在尝试将处理后的数据直接写入S3存储桶。 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? 我们可以直接将文件写入S3存储桶吗?

Problem solved! 问题解决了! It's because of the format of the s3 buckt. 这是因为s3 buckt的格式。 The correct format should be 's3://mybucket/myfile' The 405 ERROR is caused by boto not recognizing the bucket name. 正确的格式应为's3:// mybucket / myfile'405 ERROR是由boto无法识别存储桶名称引起的。 Also need to mention that boto does not recognize bucket name with '.' 另外需要提一下boto不能用'。'识别桶名。 in it in Python 2.7.*, so you have to use a valid bucket name or change it in the config file. 在Python 2.7。*中,所以你必须使用有效的存储桶名称或在配置文件中更改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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