我今天开始使用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));
};
答案 0 :(得分:1)
在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));
其中事件是字典,json.dumps将事件序列化为JSON格式的字符串