简体   繁体   English

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

[英]Setting payloads for invoking Lambda Functions

I am trying to invoke a Lambda function from another Lambda function in Java. 我试图从Java中的另一个Lambda函数调用Lambda函数。 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" . 我正在遵循以下问题中提供的代码: “当两者位于同一账户,同一区域时,如何从另一个AWS Java Lambda函数调用aws java lambda函数”

Refer to this statement in the code: 在代码中引用此语句:

invokeRequest.setPayload(ipInput); invokeRequest.setPayload(ipInput);

Where I am guessing the ipInput variable is a String. 我猜ipInput变量是一个字符串。

What I need to know is how should I set a payload, that is not String? 我需要知道的是如何设置有效载荷(不是String)? In my case, the Lambda function accepts a List<Double> input. 就我而言,Lambda函数接受List<Double>输入。 From what I read, it seems I need to convert it to a JSON String. 从我阅读的内容来看,似乎需要将其转换为JSON字符串。 I am sceptical about how? 我对如何表示怀疑? Is there a difference between the JSON representation of Double[] and List<Double> ? Double[]List<Double>的JSON表示形式之间有区别吗? Also, is there any helper method in AWS SDK (or the Collections API), which can do that cleanly? 此外,AWS开发工具包(或Collections API)中是否有任何辅助方法可以干净地做到这一点?

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 . 否则,您可以直接在github上检查AWS开发工具包,或转到官方的java-doc ,您的有效负载似乎有两个选择,要么传递ByteBuffer要么传递String It seems like you cannot pass a Double or a Double[] directly. 看来您不能直接传递DoubleDouble[] You have to wrap those in a JSON-String. 您必须将它们包装在JSON-String中。 I'm receiving JSON messages containing numbers and it works quite well. 我正在接收包含数字的JSON消息,并且效果很好。 Try something like: 尝试类似的方法:

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

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

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