2016-05-12 52 views
3

我創建與路易吉數據管道,我試圖將處理過的數據S3桶直接寫。我使用的代碼是: 路易吉寫文件直接到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鬥?

回答

2

問題解決了! 這是因爲s3 buckt的格式。 正確的格式應爲「S3:// mybucket/MYFILE」 的405錯誤是由伯特不承認桶名稱引起的。 另外需要提到的是boto不能識別存儲桶名稱。在Python 2.7。*中,因此您必須使用有效的存儲桶名稱或在配置文件中更改它。