douren6035 2015-11-02 14:42
浏览 97

AWS Lambda使用参数/有效负载调用函数

I started with AWS Lambda today and I can't succeed in passing a payload to the function. On the server side I try to read all the event data but it is empty. What am I doing wrong here?

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

Returns:

Received event: {}

Function code on AWS:

console.log('Loading function');

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

};

  • 写回答

1条回答 默认 最新

  • dongma1666 2016-03-31 23:38
    关注

    In python I send the payload like this:

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

    where event is a dictionary and, json.dumps serialize event to a JSON formatted string

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭