AWS Lambda PHP 使用 Zip 创建函数
AWS Lambda PHP Create Function with Zip
我正在尝试创建一个 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 Aws\Lambda\Exception\LambdaException: 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
我似乎无法在 google 上找到一个很好的例子,而且文档也...不太理想。我用 php 创建了 zip 文件,所以我尝试传递那个 var、文件的完整路径、文件的相对路径等。最后了解到你必须使用 fileb:// 前缀,但那没有' 最终修复任何东西。
好的,我不确定为什么会这样,但您需要对 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 员工的 post,您不必为创建函数使用 base64 编码。他们一定是搞混了。
我正在尝试创建一个 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 Aws\Lambda\Exception\LambdaException: 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
我似乎无法在 google 上找到一个很好的例子,而且文档也...不太理想。我用 php 创建了 zip 文件,所以我尝试传递那个 var、文件的完整路径、文件的相对路径等。最后了解到你必须使用 fileb:// 前缀,但那没有' 最终修复任何东西。
好的,我不确定为什么会这样,但您需要对 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 员工的 post,您不必为创建函数使用 base64 编码。他们一定是搞混了。