简体   繁体   English

从 Redshift 调用 Lambda UDF 时出错

[英]Error when calling Lambda UDF from Redshift

When calling a python lambda UDF from my Redshift stored procedure i am getting the following error.从我的 Redshift 存储过程调用 python lambda UDF 时,我收到以下错误。 Any idea what could be wrong?知道有什么问题吗?

ERROR: Invalid External Function Response Detail:    
----------------------------------------------- 
error: Invalid External Function Response code: 
8001 context: Extra rows in external function response query: 0 
location: exfunc_data.cpp:330 process: padbmaster [pid=8842] 
----------------------------------------------- 

My Python Lambda UDF looks as follows.我的 Python Lambda UDF 如下所示。

def lambda_handler(event, context):
    #...
    result = DoJob()
    #...
    
    ret = dict()
    ret['results'] = result
    ret_json = json.dumps(ret)
    return ret_json

The above lambda function is associated to an external function in Redshift by name send_email_lambda .上述 lambda function 与 Redshift 中名为send_email_lambda的外部 function 相关联。 The permissions and invocation works without any issues.权限和调用没有任何问题。 I am calling the lambda function as follows.我按如下方式调用 lambda function。

select send_email_lambda('sebder@company.com',
                   'recipient1@company.com',
                   'sample body',
                   'sample subject);

Edit: As requested, adding the event payload passed from redshift to lambda.编辑:根据要求,添加从 redshift 传递到 lambda 的事件有效负载。

{
   "user":"awsuser",
   "cluster":"arn:aws:redshift:us-central-1:dummy:cluster:redshift-test-cluster",
   "database":"sample",
   "external_function":"lambda_send_email",
   "query_id":178044,
   "request_id":"20211b87-26c8-6d6a-a256-1a8568287feb",
   "arguments":[
      [
         "sender@company.com",
         "user1@company.com,user2@company.com",
         "<html><h1>Hello Therer</h1><p>A sample email from redshift. Take care and stay safe</p></html>",
         "Redshift email lambda UDF",
         "None",
         "None",
         "text/html"
      ]
   ],
   "num_records":1
}

It looks like a UDF can be passed multiple rows of data.看起来 UDF 可以传递多行数据。 So, it could receive a request to send multiple emails.因此,它可能会收到发送多封电子邮件的请求。 The code needs to loop through each of the top-level array, then extract the values from the array inside that.代码需要遍历每个顶级数组,然后从其中的数组中提取值。

It looks like it then needs to return an array that is the same length as the input array.看起来它需要返回一个与输入数组长度相同的数组。

For your code, create an array with one entry and then return the dictionary inside that.对于您的代码,创建一个包含一个条目的数组,然后在其中返回字典。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM