demircioglu
demircioglu

Reputation: 3465

External function call returns Top-level JSON object must contain "data" JSON array element error

I have a use case to utilize external functions.

Followed the steps in External Function Sample

Created the same function in the above GitHub repo, I was able to test the lambda function stand alone and from API on AWS, but when I call the external function from Snowflake it returns this error

Error parsing JSON response for external function EXT_FUNC_TEST with request batch id: 1234. Error: top-level JSON object must contain "data" JSON array element

Update: Here is the test payload input and response in lambda

input

{"body": "{ \"data\": [ [ 0, 1 ], [ 1, 5], [2, \"a string\" ] ] }"}

response

{"statusCode": 200, "body": "{\"data\": [[0, 4], [1, 8], [2, \"Error processing this row...\"]]}"}

Snowflake call select Ext_Func_test(3) generates input in CloudWatch as

{"data": [[0, 3]]}

how to incorporate body in to the input?

Upvotes: 1

Views: 2390

Answers (1)

Nitya
Nitya

Reputation: 74

Snowflake expects the response to be in a particular format. https://docs.snowflake.com/en/sql-reference/external-functions-general.html#data-format-sent-by-snowflake

Something like:

{
    "data":
        [
            [ 0, 1995 ],
            [ 1, 1974 ],
            [ 2, 1983 ],
            [ 3, 2001 ]
        ]
}

Does the response look like the above example when you test your lambda from AWS API?

Upvotes: 3

Related Questions