AWS Lamba调用带有参数/有效载荷的函数


AWS Lamba invoke function with parameters/payload

我今天开始使用AWS Lambda,但我无法成功地将有效负载传递给函数。在服务器端,我尝试读取所有事件数据,但它是空的。我在这里做错了什么?

$client = LambdaClient::factory(array(
'profile' => 'default',
'key' => AWS_ACCESS_KEY_ID,
'secret' => AWS_SECRET_ACCESS_KEY,
'region'  => 'eu-west-1'
));
$payload = array('key1' => '1');
$result = $client->invoke(array(
'FunctionName' => 'hello',
'InvocationType' => 'RequestResponse',
'LogType' => 'Tail',
'Payload' => json_encode($payload)
));

退货:

Received event: {}

AWS上的功能代码:

console.log('Loading function');
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));

};

在python中,我发送的有效载荷如下:

from boto3 import client as botoClient
import json
lambdas = botoClient("lambda")
def lambda_handler(event, context):
    response = lambdas.invoke(FunctionName="myLambdaFunct", InvocationType="RequestResponse", Payload=json.dumps(event));

其中event是一个字典,json.dumps将事件序列化为json格式的字符串