塞納里奧:
- 使用 boto3 提交 Athena 查詢并輸出到 s3
- 在 s3 中下載結果
Error: An error occurred (404) when calling the HeadObject operation: Not Found
aws s3 cp奇怪的是該檔案存在于 S3 中,我可以使用命令將其復制下來。但我就是無法用 boto3 下載,也無法執行head-object。
aws s3api head-object --bucket dsp-smaato-sink-prod --key /athena_query_results/c96bdc09-d545-4ee3-bc66-be3be928e3f2.csv
它確實有效。我檢查了帳戶政策,并授予了管理員政策。
# snippets
def s3_donwload(url, target=None):
# s3 = boto3.resource('s3')
# client = s3.meta.client
client = boto3.client("s3", region_name=constant.AWS_REGION, endpoint_url='https://s3.ap-southeast-1.amazonaws.com')
s3_file = urlparse(url)
if target:
target = os.path.abspath(target)
else:
target = os.path.abspath(os.path.basename(s3_file.path))
logger.info(f"download {url} to {target}...")
client.download_file(s3_file.netloc, s3_file.path, target)
logger.info(f"download {url} to {target} done!")
uj5u.com熱心網友回復:
看一下s3_file.path-- 它的值是否以斜線開頭?如果是這樣,則需要更改,因為 Amazon S3 密鑰不以斜杠開頭。
我建議您列印 的內容netloc,path并target查看它實際傳遞的值。
與 S3 URL一起使用有點奇怪os.path,因此可能需要進行一些調整。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/495373.html
