Stefan
Stefan

Reputation: 1258

AWS Lamba invoke function with parameters/payload

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

};

Upvotes: 1

Views: 2106

Answers (1)

antonio
antonio

Reputation: 487

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

Upvotes: 2

Related Questions