设置调用Lambda函数的有效负载

时间:2021-01-18 13:45:19

I am trying to invoke a Lambda function from another Lambda function in Java. I am following the code provided in this Question "How to call an aws java lambda function from another AWS Java Lambda function when both are in same account, same region".

我试图从Java中的另一个Lambda函数调用Lambda函数。我遵循本问题“如何在另一个AWS Java Lambda函数中调用aws java lambda函数时,两者都在同一个帐户,同一区域”中提供的代码。

Refer to this statement in the code:

请参阅代码中的以下语句:

invokeRequest.setPayload(ipInput);

Where I am guessing the ipInput variable is a String.

我在猜测ipInput变量是一个String。

What I need to know is how should I set a payload, that is not String? In my case, the Lambda function accepts a List<Double> input. From what I read, it seems I need to convert it to a JSON String. I am sceptical about how? Is there a difference between the JSON representation of Double[] and List<Double>? Also, is there any helper method in AWS SDK (or the Collections API), which can do that cleanly?

我需要知道的是我应该如何设置有效载荷,而不是String?在我的例子中,Lambda函数接受List 输入。从我读到的,似乎我需要将其转换为JSON字符串。我对如何持怀疑态度? Double []和List 的JSON表示之间是否有区别?此外,AWS SDK(或Collections API)中是否有任何帮助方法,可以干净利落地执行此操作?

1 个解决方案

#1


2  

There is a post on the AWS Devloper blog regarding this topic.

AWS Devloper博客上有关于此主题的帖子。

You could implement a proxy.

您可以实现代理。

Otherwise you could check the AWS SDK directly on github or go to the official java-doc there seem to be two options for your payload either you pass a ByteBuffer or a String. It seems like you cannot pass a Double or a Double[] directly. You have to wrap those in a JSON-String. I'm receiving JSON messages containing numbers and it works quite well. Try something like:

否则,您可以直接在github上检查AWS SDK,或者转到官方的java-doc,无论是传递ByteBuffer还是String,您的有效负载似乎都有两个选项。好像你不能直接传递Double或Double []。您必须将它们包装在JSON-String中。我收到包含数字的JSON消息,但效果很好。尝试以下方法:

String myDoubles = "{\"doubles\": [1487851012.924, 1487851012.925]}"
invokeRequest.setPayload(myDoubles);

#1


2  

There is a post on the AWS Devloper blog regarding this topic.

AWS Devloper博客上有关于此主题的帖子。

You could implement a proxy.

您可以实现代理。

Otherwise you could check the AWS SDK directly on github or go to the official java-doc there seem to be two options for your payload either you pass a ByteBuffer or a String. It seems like you cannot pass a Double or a Double[] directly. You have to wrap those in a JSON-String. I'm receiving JSON messages containing numbers and it works quite well. Try something like:

否则,您可以直接在github上检查AWS SDK,或者转到官方的java-doc,无论是传递ByteBuffer还是String,您的有效负载似乎都有两个选项。好像你不能直接传递Double或Double []。您必须将它们包装在JSON-String中。我收到包含数字的JSON消息,但效果很好。尝试以下方法:

String myDoubles = "{\"doubles\": [1487851012.924, 1487851012.925]}"
invokeRequest.setPayload(myDoubles);