[英]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
我似乎無法在谷歌上找到一個很好的例子,而且文檔......不太理想。 我用 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 員工的說明和帖子,您不必為 create 函數使用 base64 編碼。 他們一定是搞混了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.