【发布时间】:2018-09-21 19:49:20
【问题描述】:
您好,感谢您的帮助,
我在不使用 API 的情况下将 php-sdk 用于 aws lambda 调用方法。
我正在关注https://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Lambda.LambdaClient.html#_invoke 中的文档
奇怪的是,我将 SNS 类与位于 ~/.aws/credentials 和 ~/.aws/config 中的外部凭证文件一起使用,它工作正常,所以我认为凭证没有问题,尽管我可能是错的。
我的代码是:
$client = LambdaClient::factory([
'version' => 'latest',
'key' => $f_key,
'secret' => $f_secret,
'region' => 'us-east-1'
]);
$result = $client->invoke(array(
'FunctionName' => 'MY_FUNC',
// NOT SET AWS SAYS IT DEFAULTS
// 'InvocationType' => 'string',
// 'LogType' => 'string',
// 'Qualifier' => 'string',
'ClientContext' => '
'ClientContext' => '{
"id": 1006410,
"title": "LAMBDA TEST"
}',
',
'Payload' => 'mixed type: string|resource|\Guzzle\Http\EntityBodyInterface',
));
我得到的错误:
PHP Fatal error: Uncaught exception 'Aws\Lambda\Exception\LambdaException' with message 'Error executing "Invoke" on "https://lambda.us-east-1.amazonaws.com/2015-03-31/ARN_REMOVED/invocations"; AWS HTTP error: Client error: `POST https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/ARN_REMOVED/invocations` resulted in a `403 Forbidden` response:
{"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access (truncated...)
InvalidSignatureException (client): The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. - {"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for in /home/USER/Documents/symphonic/SMS-v1/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 191
【问题讨论】:
-
ClientContext不应该是一个包含 base64 编码 JSON 的字符串,而不是一个数组吗?我建议您在完全删除该元素的情况下进行测试。 -
@Michael-sqllbot 我认为您是正确的,现在查看我的代码,我发现它是数组格式并且可能没有正确编码谢谢您的建议我会尝试一下,如果它工作我会接受你的回答
-
@Michael-sqllbot 非常感谢!这对我有用:
-
$str = '{"Type":"User"}'; $base64str = base64_encode($str); 'ClientContext' => $base64str,
标签: php amazon-web-services aws-lambda