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
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);