Python Boto3 'StreamingBody' 对象没有属性 'iter_lines'

标签 python aws-lambda boto3 aws-glue botocore

我正在使用 Boto3 在 Python 脚本中读取 Athena 查询的结果。

我有以下代码,可以在 AWS Lambda 中正常运行。

def get_athena_results(s3_bucket, s3_output_path, execution_id):
    s3client = boto3.client('s3')
    key = s3_output_path + '/' + execution_id + '.csv'
    obj = s3client.get_object(Bucket=s3_bucket, Key=key)
    results_iterator = obj['Body'].iter_lines()
    results = [r for r in results_iterator]
    return results

当我在 AWS Glue Python Shell(不是 Spark 作业)中运行相同的函数时,出现错误:

Unexpected error: <class 'AttributeError'>
'StreamingBody' object has no attribute 'iter_lines'

这对我来说没有意义,因为 botocore.response.StreamingBody 类有一个 iter_lines 方法,并且它在 AWS Lambda 中运行良好。

https://botocore.amazonaws.com/v1/documentation/api/latest/reference/response.html

知道为什么 AWS Glue Python Shell 中会发生这种情况吗?

谢谢

最佳答案

发生错误的原因是,在发布问题时,Glue 的 Boto3 是以前的版本,而不是 lambda 中可用的版本,其中 iter_lines() 不可用。

关于Python Boto3 'StreamingBody' 对象没有属性 'iter_lines',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57793635/

相关文章:

python - 从数据存储中获取一个随机实体

python - AWS 物联网数据 : CERTIFICATE_VERIFY_FAILED

amazon-web-services - 如何将过滤器与 boto3 vpc 端点服务结合使用?

amazon-web-services - 如何使用 boto3 将 ENI 附加到 lambda

amazon-s3 - AWS lambda tar 文件提取似乎不起作用

Python 2.7 AWS Lambda 支持将于 2020 年终止?

python - 如何在 EC2 实例中使用 boto3

python - 导入错误 : cannot import name 'Serial' from 'serial' (unknown location)

python - 在 APScheduler 中超出计划的手 Action 业执行

python - 使用 Python 通过 Selenium WebDriver 打开 chrome 扩展