使用 Python 在 AWS Glue 中打开和读取文件

File open and read in AWS Glue with Python

我在下面有一个简单的 python 代码。这是在桌面上编写的,现在我想将其重新创建为 aws glue 或 lambda,我必须从 s3 目录中读取 testfile.csv 并将其放入 txt 中,如下所示。如何在 aws glue/lambda 环境中重新创建此打开和读取。欢迎任何意见。

filepath = testfile.csv
txt = open(filepath).read()

我找到了解决方法。第一行将文件存储为字节对象,第二行将其转换为字符串并存储为 txt。

object = s3client.get_object(Bucket='mybucket',Key='testfile.csv')
txt = (object['Body'].read().decode('utf-8'))