我正在尝试创建一个PHP脚本,该脚本根据我在服务器上压缩的一些代码创建一个函数。我手动将文件上传到lambda,它运行良好。但是,当我尝试使用aws-sdk创建函数时,它失败了,并显示错误消息。有人知道线索吗?
代码:
private function createLambdaFunction() {
$result = $this->lambdaConn->createFunction(array(
'FunctionName' => $this->lambdaFunctionName,
'Runtime' => $this->runtime,
'Role' => $this->role,
'Handler' => $this->lambdaFunctionName.".".$this->handler,
'Description' => $this->description,
'Timeout' => $this->timeout,
'MemorySize' => $this->memorySize,
'Code' => array(
'ZipFile' => 'fileb://test.zip'
)
));
错误:
PHP Fatal error: Uncaught AwsLambdaExceptionLambdaException: AWS
Error Code: InvalidParameterValueException,
Status Code: 400, AWS Request ID: asdf, AWS Error Type: user,
AWS Error Message: Could not unzip uploaded file. Please check
your file, then try to upload again., User-Agent:
aws-sdk-php2/2.8.10 Guzzle/3.9.3 curl/7.35.0 PHP/5.5.9-1ubuntu4.9
我似乎在谷歌上找不到一个好的例子,而且文档……不太理想。我用php创建了zip文件,所以我尝试传递var、文件的完整路径、文件的相对路径等。最后学会了必须使用fileb://prevention,但最终没有解决任何问题。
好吧,我不确定为什么会出现这种情况,但你需要对你的zip文件进行base64编码,比如:
$result = $this->lambdaConn->createFunction(array(
'FunctionName' => $this->lambdaFunctionName,
'Runtime' => $this->runtime,
'Role' => $this->role,
'Handler' => $this->lambdaFunctionName . "." . $this->handler,
'Description' => $this->description,
'Timeout' => $this->timeout,
'MemorySize' => $this->memorySize,
'Code' => array(
'ZipFile' => 'fileb://'.base64_encode(file_get_contents('test.zip'))
)
));
我不知道为什么需要这样做,因为根据AWS员工的陈述和帖子,创建函数不必使用base64编码。他们一定把什么或什么搞混了。