【问题标题】:Luigi write file directly to S3Luigi 直接将文件写入 S3
【发布时间】:2016-05-12 14:14:03
【问题描述】:

我正在使用 Luigi 创建数据管道,并尝试将处理后的数据直接写入 S3 存储桶。我使用的代码是:

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()

运行脚本后,出现错误:

S3ResponseError: S3ResponseError: 405 Method Not Allowed

我们可以直接将文件写入S3存储桶吗?

【问题讨论】:

    标签: python amazon-s3 luigi


    【解决方案1】:

    问题解决了! 这是因为 s3 buckt 的格式。 正确的格式应该是 's3://mybucket/myfile' 405 ERROR 是由于 boto 无法识别存储桶名称引起的。 还需要提到 boto 不识别带有 '.' 的存储桶名称。在 Python 2.7.* 中,因此您必须使用有效的存储桶名称或在配置文件中更改它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2018-07-07
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-29
      相关资源
      最近更新 更多