[英]Does the python script have to be named as handler.py in AWS Lambda
Does the python script have to be named as handler.py in AWS Lambda?在 AWS Lambda 中,python 脚本是否必须命名为 handler.py?
I can't remember where I read this from, it says lambda is configured to look for a specific file, usually named 'handler.py',just wondering where we can configure this or does it have to be 'handler.py'?我不记得我从哪里读到的,它说 lambda 被配置为查找一个特定的文件,通常命名为“handler.py”,只是想知道我们可以在哪里配置它或者它必须是“handler.py”? Thanks.谢谢。
Nope it need not necessarily be named as handler.py.不,它不必命名为 handler.py。
you can name whatever you want but in lambda handler give as您可以命名任何您想要的名称,但在 lambda 处理程序中将其命名为
file_name.function_name文件名.函数名
Just like a import就像导入一样
If you what have your handler file inside folders kindly include如果你的文件夹中有你的处理程序文件,请包括
init .py初始化.py
in all folders and perform a normal import like below在所有文件夹中并执行如下正常导入
src/
__init__.py
app.py
You can do import as src.app.function_name in handler config您可以在处理程序配置中作为 src.app.function_name 导入
You can name this Python script whatever you want.您可以随意命名此 Python 脚本。 Be sure to reference it properly.请务必正确引用。
You can tell the Lambda runtime which handler method to invoke by setting the handler parameter on your function's configuration.您可以通过在函数的配置中设置 handler 参数来告诉 Lambda 运行时调用哪个处理程序方法。
When you configure a function in Python, the value of the handler setting is the file name and the name of the handler module, separated by a dot.在 Python 中配置函数时,处理程序设置的值是文件名和处理程序模块的名称,用点分隔。 For example,
main.Handler
calls theHandler
method defined inmain.py
.例如,main.Handler
调用main.py
定义的Handler
方法。
Does the python script have to be named as handler.py in AWS Lambda在 AWS Lambda 中,python 脚本是否必须命名为 handler.py
Shortly No, you could specify any method which could process lambda event.很快不,您可以指定任何可以处理 lambda 事件的方法。 (Usually combination is event + context (event, context) (通常组合是事件+上下文(事件,上下文)
Just wondering where we can configure this or does it have to be 'handler.py'?只是想知道我们可以在哪里配置它还是必须是“handler.py”?
It really depends how you build and deploy your lambda but shortly handler property is telling you which method to be invoked and you could specify is as relative path to your deployment package - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-handler .这实际上取决于您如何构建和部署 lambda,但很快 handler 属性会告诉您要调用哪个方法,您可以指定作为部署包的相对路径 - https://docs.aws.amazon.com/AWSCloudFormation/latest /UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-handler 。
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Handler: index.handler
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.