2017-08-08 75 views
-1

我有以下代碼:LAMBDA異步調用拋出錯誤,同步調用工作正常

<?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([ 
 
\t 'FunctionName' => 'LocationUpdate', 
 
\t 'InvocationType' => 'Event', 
 
\t 'Payload' => $rawdata 
 
]);

當我運行的代碼,而無需調用類型,它的偉大工程。但是,當我使用Event或DryRun調用類型運行它時,它不起作用,而是引發以下錯誤。我究竟做錯了什麼?

<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 />

+0

裏面是什麼'$ rawdata'?你爲什麼要聲明'$ contxt'而不是使用? –

+0

上下文來自我很久以前獲得的一些示例代碼。 (哎呀!),原始數據是php的輸入。我正在使用以下的「{」Serial「:」GP40ovf9「,」Lat「:」34.0「,」Lon「:」 - 84「,」SoC「:」100「,」準確性「:」8.0「 – Reid

回答