我正在使用 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/