AWS CLI 创建 Lambda 函数无法解压缩上传的文件 [英] AWS CLI create Lambda function cannot unzip uploaded file

查看:23
本文介绍了AWS CLI 创建 Lambda 函数无法解压缩上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 AWS CLI 创建 AWS Lambda 函数.因此,我通过传入 --generate-cli-skeleton 参数,然后相应地替换值,生成了用于 aws lambda create-function 函数的 JSON 输入框架.

I'm trying to create an AWS Lambda function using the AWS CLI. So I generated the JSON input skeleton for use with the aws lambda create-function function by passing in the --generate-cli-skeleton parameter and then substituting the values accordingly.

问题是,当我执行创建函数的命令时,它给了我这个错误:

The problem is that when I execute the command to create the function it gives me this error:

调用 CreateFunction 操作时发生客户端错误 (InvalidParameterValueException):无法解压缩上传的文件.请检查您的文件,然后再次尝试上传.

这是我运行命令的方式:

This is how I run the command:

aws lambda create-function --cli-input-json file://C:\Projects\Automated_Deployment\lambda_function_deploy.json

.json 文件的内容是:

{
    "FunctionName": "MyFunction",
    "Runtime": "nodejs",
    "Role": "arn:aws:iam::------------:role/lambda_dynamo",
    "Handler": "index.handler",
    "Code": {
        "ZipFile": "fileb://C:/Projects/src/zip/MyFunction.zip"
    },
    "Description": "description goes here",
    "Timeout": 10,
    "MemorySize": 128,
    "Publish": true
}

令人惊讶的是,如果我尝试在不使用 JSON 文件的情况下创建函数并在命令行中提供所有参数,那么它就可以工作.因此,例如,这完全没有问题:

Surprisingly if I try to create the function without using the JSON file and providing all the parameters in the command-line then it works. So for instance, this works without any issues at all:

aws lambda create-function --function-name MyFunction --runtime nodejs --role arn:aws:iam::------------:role/lambda_dynamo --handler index.handler --zip-file fileb://C:/Projects/src/zip/MyFunction.zip

这是同一个 .zip 文件.关于我在这里做错了什么的任何提示?我尝试将 "ZipFile": "fileb://C:/Projects/src/zip/MyFunction.zip" 替换为:

This is the same .zip file. Any hints as to what am I doing wrong here? I have tried replacing "ZipFile": "fileb://C:/Projects/src/zip/MyFunction.zip" with:

"ZipFile": "file://C:/Projects/src/zip/MyFunction.zip""ZipFile": "C:/Projects/src/zip/MyFunction.zip" 但问题仍然存在.

"ZipFile": "file://C:/Projects/src/zip/MyFunction.zip" and "ZipFile": "C:/Projects/src/zip/MyFunction.zip" but the issue remains.

我发现了 --debug 选项,我们可以将其传递给 CLI 命令.问题是当我们从 JSON 提供输入时,该工具没有正确读取 ZipFile.因此,例如,如果我运行提供命令本身所有参数的命令,我可以看到正确 base64 编码的 zip 文件,即:

I found out the --debug option which we can pass to the CLI command. The problem is that the tool is not reading the ZipFile properly when we provide the input from JSON. So for instance if I run the command providing all the parameters in the command itself, I can see the zip file properly base64 encoded i.e.:

2016-02-08 10:43:59,831 - MainThread - botocore.endpoint - DEBUG - Making request for <botocore.model.OperationModel object at 0x0000000004149F28> (verify_ssl=True) with params: {'body': '{"Code": {"ZipFile": "UEsDBBQAAAAIAFiGPUiLOeW/nwcAANsdAAAIAAAAaW5kZXguanO1Gdtu2zb0PUD+gdVDI2OOmrZrBzgICi9OC29FYsRpX4pCUCQ65iJLqk 
.... 
redacted

但是当我提供来自 JSON 文件的参数时,即 --cli-input-json 然后命令 base64 对 JSON 中 ZipFile 键的值进行编码(这是该文件的 URI,即 fileb://C:/Projects/src/zip/MyFunction.zip)

But when I provide the parameters from the JSON file i.e. --cli-input-json then the command base64 encodes the value of the ZipFile key in the JSON (which is the URI to that file i.e. fileb://C:/Projects/src/zip/MyFunction.zip)

现在我不确定我们需要为 ZipFile 键提供什么值,还是工具/命令中的错误?

Now I'm not sure what value we need to provide to the ZipFile key, or is it a bug in the tool/command?

如果我提供我的 zip 文件的 base64 编码字符串,该命令将再次对该字符串进行 base64 编码,这将给出相同的错误(即无法解压缩.)所以我的问题是什么ZipFile 需要的字段?带有 file://协议或 fileb://的 URL ?Zip 文件的内容是 base-64 编码的吗?

If I provide the base64 encoded string of my zip file, the command will base64 encode that string again which will gave the same error (i.e. cannot unzip.) So my question is what does the field ZipFile require? A URL with file:// protocol or fileb:// ? Zip file's contents base-64 encoded?

推荐答案

用于 lambda 创建函数的 aws cli 文档 实际上并未将 ZipFile 作为 --code 的一部分列出选项.

The aws cli docs for lambda create-function don't actually list ZipFile as part of the --code option.

Python AWS 开发工具包文档 do list ZipFile - 它应该是字节,并且是包含部署包的 zip 文件的内容".

The Python AWS SDK docs do list ZipFile - it should be bytes, and be 'The contents of your zip file containing your deployment package'.

在 python 中,您可以通过读取 zip 文件的内容来执行此操作,但我不确定您将如何以合适的格式执行此操作以进入 json 文件 - 我不确定您是否可以.

In python you can do this by reading the contents of the zip file, but I'm not sure how you would do this in a suitable format to go into a json file - I'm not certain that you can.

我想知道 cli 文档是否准确,并且此命令的 --generate-cli-skeleton 输出不准确,并且 lambda 部署包必须存储在 s3 中以在传递给 --cli-input-json 的文件中被引用,或者作为 cmd 行选项传递,正如你最终所做的那样.

I wonder if perhaps the cli docs are accurate, and the output of --generate-cli-skeleton for this command is not, and that the lambda deployment package must either be stored in s3 to be referenced in the file passed to --cli-input-json, or passed as a cmd line option, as you ended up doing.

这篇关于AWS CLI 创建 Lambda 函数无法解压缩上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆