【问题标题】:Lambda Async invocation throws errors, synchronous invocation works fineLambda 异步调用抛出错误,同步调用工作正常
【发布时间】:2017-08-09 08:01:11
【问题描述】:

我有以下代码:

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

当我运行代码时,没有调用类型,它工作得很好。但是,当我使用 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 />

【问题讨论】:

  • $rawdata 里面是什么?你为什么声明$contxt而不使用?
  • 上下文是我很久以前得到的一些示例代码遗留下来的。 (哎呀!),原始数据是 php 输入。我正在使用以下{"Serial":"GP40ovf9","Lat":"34.0","Lon":"-84","SoC":"100","Accuracy":"8.0"} 进行测试

标签: php lambda aws-lambda guzzle


【解决方案1】:

我继续下载了 PHAR lambda 文件,而不是使用我以前使用的过时技术(guzzle),现在它可以完美运行了。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    相关资源
    最近更新 更多