I am trying to call a simple Aws Lambda function using PHP as Instructed in the documentation, but I am not getting the desired response.
PHP Lambda client
require './aws/aws-autoloader.php';
use Aws\Lambda\LambdaClient;
$client = LambdaClient::factory(array(
'version' => "latest",
'credentials' => array(
'key' => '*******',
'secret' => '*******'
),
'region' => '*******'
));
$response = $client->invoke([
'FunctionName' => 'myLambda', // REQUIRED
'InvocationType' => 'RequestResponse',
'Payload' => '{"key":"value"}',
]);
echo "<pre>";
print_r($response);
print_r($response->data);
?>
Node.js Lambda function This has nothing but this simple code that returns "success" on the successful execution of the Lambda function. Its working finds in the Amazon Lambda console.
exports.handler = function(event, context){
context.succeed("success");
};
Response from Amazon I am getting a Private data object, that I cannot access. And according to the documentation, Payload is supposed to be the response from the function. But, I am getting an Object, which again I cannot access because the parent object data is private.
Aws\Result Object
(
[data:Aws\Result:private] => Array
(
[Payload] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #6
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
[StatusCode] => 200
[FunctionError] =>
[LogResult] =>
[@metadata] => Array
(
[statusCode] => 200
[effectiveUri] => https://lambda.*********.amazonaws.com/2015-03-31/functions/myLambda/invocations
[headers] => Array
(
[content-type] => application/json
[date] => Wed, 06 Apr 2016 12:33:05 GMT
[x-amzn-remapped-content-length] => 0
[x-amzn-requestid] => ******-*****-*****-****-*******************
[content-length] => 9
[connection] => keep-alive
)
[transferStats] => Array
(
[http] => Array
(
[0] => Array
(
)
)
)
)
)
)
So, how do I access the Response from the Lambda function? What might be the issue here?
I am able to access the Payload by using print_r($response['Payload']); But, Still, it's useless because the Payload is not coming as expected.