【问题标题】:AWS boto3 Athena query results are not saving to local pathAWS boto3 Athena 查询结果未保存到本地路径
【发布时间】:2019-05-21 01:03:37
【问题描述】:

我正在尝试运行一个简单的 athena 查询并尝试将结果保存到本地路径。

response = athena.start_query_execution(
    QueryString='select query',
    QueryExecutionContext={
        'Database': 'test'
    },
    ResultConfiguration={
        'OutputLocation': r'C:\Projects\Project0\'
    }

但我收到以下错误。

botocore.errorfactory.InvalidRequestException:发生错误 (InvalidRequestException) 调用 StartQueryExecution 时 操作:outputLocation 不是有效的 S3 路径。

是否可以将结果保存到本地路径?我在 boto3 文档中找不到任何信息。

【问题讨论】:

    标签: python amazon-web-services boto3 amazon-athena


    【解决方案1】:

    ResultConfiguration 不包含您的查询结果。您必须使用“QueryExecutionId”和get_query_results 函数进行第二次调用:

    exe = athena.start_query_execution(
        QueryString='select query',
        QueryExecutionContext={
            'Database': 'test'
        },
        ResultConfiguration={
            'OutputLocation': 's3 location'
        }
    result = athena.get_query_results(
        QueryExecutionId=exe['QueryExecutionId']
         )
    

    【讨论】:

      【解决方案2】:

      在 Athena 中,结果只能保存到 s3 位置。请参阅OutputLocation 以了解有关语义的更多信息。如果您希望在本地系统中获得此结果,则可以转到您作为输入提供的 s3 位置到您的 start_query_execution API 调用并从 s3 控制台下载结果或使用 aws s3 cp command

      【讨论】:

        猜你喜欢
        • 2018-12-17
        • 2018-05-07
        • 1970-01-01
        • 2019-03-22
        • 1970-01-01
        • 2019-11-07
        • 2020-09-19
        • 2017-11-20
        • 1970-01-01
        相关资源
        最近更新 更多