Lambda异步调用抛出错误,同步调用工作正常

时间:2017-08-08 21:07:16

标签: php lambda aws-lambda guzzle

我有以下代码:



<?php
echo('Success');

//Setup the API
require 'vendor/autoload.php';
use Aws\Lambda\LambdaClient;

//Login to the Dynamo DB
$client = LambdaClient::factory(array(
'version' => 'latest',
  'region'  => 'us-east-1',
  'credentials' => array(
    'key' => 'My Key',
    'secret'  => 'My Secret',
  )
));

$rawdata = file_get_contents('php://input');

//echo("Raw Data:");
//echo($rawdata);

$client->invoke([
	'FunctionName' => 'LocationUpdate',
	'InvocationType' => 'Event',
	'Payload' => $rawdata
]);
&#13;
&#13;
&#13;

当我运行代码时,没有调用类型,它工作得很好。但是,当我使用调用类型为Event或DryRun来运行它时,它不起作用,而是抛出以下错误。我做错了什么?

&#13;
&#13;
<b>Fatal error</b>:  Uncaught Guzzle\Common\Exception\RuntimeException: Unable to parse response body into JSON: 4 in /var/www/html/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:861
Stack trace:
#0 /var/www/html/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/JsonVisitor.php(22): Guzzle\Http\Message\Response-&gt;json()
#1 /var/www/html/vendor/guzzle/guzzle/src/Guzzle/Service/Command/OperationResponseParser.php(134): Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor-&gt;before(Object(Guzzle\Service\Command\OperationCommand), Array)
#2 /var/www/html/vendor/guzzle/guzzle/src/Guzzle/Service/Command/OperationResponseParser.php(86): Guzzle\Service\Command\OperationResponseParser-&gt;visitResult(Object(Guzzle\Service\Description\Parameter), Object(Guzzle\Service\Command\OperationCommand), Object(Guzzle\Http\Message\Response))
#3 /var/www/html/vendor/guzzle/guzzle/src/Guzzle/Service/Command/DefaultResponseParser.php(39): Guzzle\Service\Command\OperationResponseParser-&gt;handleParsing(Object(Guzzle\Serv in <b>/var/www/html/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php</b> on line <b>861</b><br />
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我继续下载PHAR lambda文件,而不是使用之前使用的过时技术(guzzle),它现在运行得很好。

https://github.com/aws/aws-sdk-php/releases

http://docs.aws.amazon.com/aws-sdk-php/v2/guide/installation.html