相关疑难解决方法(0)

S3 选择 CSV 标头

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

amazon-s3 amazon-web-services amazon-s3-select

5
推荐指数
1
解决办法
3878
查看次数