我正在使用 S3 Select 从 S3 Bucket 读取 csv 文件并输出为 CSV。在输出中,我只看到行,但看不到标题。如何获得包含标题的输出。
import boto3
s3 = boto3.client('s3')
r = s3.select_object_content(
Bucket='demo_bucket',
Key='demo.csv',
ExpressionType='SQL',
Expression="select * from s3object s",
InputSerialization={'CSV': {"FileHeaderInfo": "Use"}},
OutputSerialization={'CSV': {}},
)
for event in r['Payload']:
if 'Records' in event:
records = event['Records']['Payload'].decode('utf-8')
print(records)
Run Code Online (Sandbox Code Playgroud)
CSV
Name, Age, Status
Rob, 25, Single
Sam, 26, Married
Run Code Online (Sandbox Code Playgroud)
s3select 的输出
Rob, 25, Single
Sam, 26, Married
Run Code Online (Sandbox Code Playgroud)