使用boto3创建具有图层的Lambda函数时出现问题 [英] Problem creating Lambda function that has a Layer using boto3

查看:56
本文介绍了使用boto3创建具有图层的Lambda函数时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我尝试使用boto3 Lambda create_function()创建Lambda函数,并且尝试通过Layers=['string']参数包含Layers,则会收到以下错误消息: Unknown parameter in input: "Layers", must be one of: FunctionName, Runtime, Role, Handler, Code, Description, Timeout, MemorySize, Publish, VpcConfig, DeadLetterConfig, Environment, KMSKeyArn, TracingConfig, Tags

If I try to use boto3 Lambda create_function() to create a Lambda function, and I try to include Layers via Layers=['string'] parameter, I get the following error message: Unknown parameter in input: "Layers", must be one of: FunctionName, Runtime, Role, Handler, Code, Description, Timeout, MemorySize, Publish, VpcConfig, DeadLetterConfig, Environment, KMSKeyArn, TracingConfig, Tags

...有什么想法吗? 文档建议这样做应该可以,但是显然这里有些问题.注意:我在update_function_configuration()中的图层"也有类似的问题.

... any ideas? The documentation suggests that this should work, but something is clearly off here. NOTE: I also have a similar problem with "Layers" in update_function_configuration() as well.

我的猜测是,AWS Lambda控制台使用的boto3版本尚未更新/刷新以支持Layers.因为当我在具有最新版本的boto3的计算机上本地运行相同的代码时,它运行时没有任何问题.我已经尝试过在AWS控制台中同时使用列出的Python运行时3.6和3.7,但是都没有用.这些运行时分别具有1.7.74和1.9.42的boto3版本.但是我的本地计算机有1.9.59.因此,也许在1.9.42和1.9.59之间添加了Lambda层.

My guess is that the version of boto3 that the AWS Lambda console uses has not been updated/refreshed yet to support Layers. Because when I run the same code locally on a machine with a fairly recent version of boto3, it runs without any problems. I have already tried using both listed Python runtimes of 3.6 and 3.7 that in the AWS console, but neither worked. These runtimes have respective versions of boto3 of 1.7.74 and 1.9.42. But my local machine has 1.9.59. So perhaps the addition of Lambda Layers occurred between 1.9.42 and 1.9.59.

推荐答案

我的猜测是,AWS Lambda控制台使用的boto3版本尚未更新/刷新以支持Layers.

My guess is that the version of boto3 that the AWS Lambda console uses has not been updated/refreshed yet to support Layers.

完全正确. AWS通常会定期更新AWS Lambda上的可用库,但是由于未知原因,现在已经有几个月没有更新了.

That's completely right. AWS usually updates the available libraries on AWS Lambda regularly, but hasn't updated them for several months now for unknown reasons.

受支持的API端点实际上不是在boto3中定义的,而是在botocore中定义的. 当前 botocore 1.10.74可在AWS Lambda上使用,而对AWS Lambda层的支持已添加<9> .

The supported API endpoints are actually not defined in boto3, but in botocore. Currently botocore 1.10.74 is available on AWS Lambda, while support for AWS Lambda Layers got added in botocore 1.12.56.

为避免代码与可用库的版本之间出现这种不兼容性,您应创建一个部署程序包,其中除了您的AWS Lambda函数代码外还包含boto3botocore,因此您的代码使用捆绑版本而不是AWS提供的版本.这就是AWS作为其最佳做法的一部分所建议的好吧:

To avoid such incompatibilities between your code and the versions of available libraries, you should create a deployment package containing boto3 and botocore in addition to your AWS Lambda function code, so your code uses your bundled versions instead the ones AWS provides. That's what AWS suggests as part of their best practices as well:

控制函数的部署包中的依赖项.

AWS Lambda执行环境包含许多库,例如适用于Node.js的AWS开发工具包和Python运行时(可在此处找到完整列表:

The AWS Lambda execution environment contains a number of libraries such as the AWS SDK for the Node.js and Python runtimes (a full list can be found here: Lambda Execution Environment and Available Libraries). To enable the latest set of features and security updates, Lambda will periodically update these libraries. These updates may introduce subtle changes to the behavior of your Lambda function. To have full control of the dependencies your function uses, we recommend packaging all your dependencies with your deployment package.

这篇关于使用boto3创建具有图层的Lambda函数时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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