繁体   English   中英

使用 Zip 的 AWS Lambda PHP 创建函数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM