Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3 select_object_content query call

I have the following function call that works

def s3_select():
    client = boto3.client("s3")
    bucket = "test"
    key = "test.json"
    expression_type = "SQL"
    expression = """SELECT * FROM S3Object"""
    input_serialization = {"JSON": {"Type": "Document"}}
    output_serialization = {"JSON": {}}
    response = client.select_object_content(
        Bucket=bucket,
        Key=key,
        ExpressionType=expression_type,
        Expression=expression,
        InputSerialization=input_serialization,
        OutputSerialization=output_serialization
    )
    for event in response["Payload"]:
        print(event)

Instead of pulling in the entire content of my json in S3, how do I modify my expression, to just pull some field in the json.

Example if my test.json contains a key called TEST_KEY How can my expression change to just pull TEST_KEY from the json file?


1 Answers

For the case you've detailed, all you'd have to change is your expression, like

expression = """SELECT s.TEST_KEY FROM S3Object s"""
like image 99
Julio Cezar Silva Avatar answered Aug 09 '26 01:08

Julio Cezar Silva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!