Passing payload to AWS Lambda function using AWS PHP SDK

I am trying to use aws-php sdk to call an aws lambda function and get the return value as follows:

    $client = LambdaClient::factory([
        'key' => 'mykey',
        'secret' => 'mysecret',
        'region' => 'us-west-2'
    ]);

    $payload = [
        'key1' => 'value1',
        'key2' => 'value2',
        'key3' => 'value3'
    ];

    $result = $client->invoke([
        'FunctionName' => 'testFunction',
        'Payload' => json_encode($payload)
    ]);

For some reason, I get an ErrorException in StatusCodeVisitor.php on line 21. "Invalid line offset" StatusCode ""

When I do not turn on

'Payload' => json_encode($payload) 

Then I don't get the error, but I also don't pass any data to my lambda function, which defeats the target.

Can anyone see anything that I could do wrong? This seems like a trivial example.

Edit - add a link to the documentation for this function

http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Lambda.LambdaClient.html#_invoke

+4
source
1

, - aws sdk php. , , JSON PHP sdk Array.

$ .

$payload = array('test1', 'test3', 'test3');

, $ , -

exports.handler = function(event, context) {
    console.log('value1 =', event[0]);
    console.log('value2 =', event[1]);
    console.log('value3 =', event[2]);
    context.succeed(event);  // Echo back the first key value
    // context.fail('Something went wrong');
};

​​.

$payload = array(
                "key1" => array(),
                "key2" => array()
            );
+5

Source: https://habr.com/ru/post/1589084/


All Articles