简体   繁体   English

在 AWS Lambda 中,python 脚本是否必须命名为 handler.py

[英]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 the Handler method defined in main.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

  • template.yml模板.yml
LambdaFunction:
  Type: AWS::Lambda::Function
  Properties:
    Handler: index.handler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 handler.py在App Engine批量上传/下载中的作用是什么? - What is the role of handler.py in App Engine bulk upload/download? AWS Lambda函数处理程序python - aws lambda function handler python 带有类的 AWS Lambda Python 处理程序 - AWS Lambda Python Handler with class AWS Lambda:无法导入模块“python_handler”:没有名为“_cffi_backend”的模块 - AWS Lambda: Unable to import module 'python_handler': No module named '_cffi_backend' “无法在Google App Engine灵活环境中导入google / appengine / ext / deferred / handler.py” - “Failed to import google/appengine/ext/deferred/handler.py” in Google App Engine Flexible Environment 在 AWS Lambda 中执行 Py 脚本时出现 UnboundLocalError - UnboundLocalError while executing Py script in AWS Lambda 带有 Zappa 的 AWS Lambda 在“导入模块‘处理程序’:没有名为‘werkzeug’的模块”上失败 - AWS Lambda with Zappa fails on “import module 'handler': No module named 'werkzeug' ” AWS Lambda - Python - ModuleNotFoundError:没有名为“pandas”的模块 - AWS Lambda - Python - ModuleNotFoundError: No module named 'pandas' 使用 python 在 AWS lambda 中从部署包(作为层添加)调用.py 脚本 - Call .py script from deployment package(added as a layer)in AWS lambda using python AWS Lambda Python软件包-没有名为redis的模块 - AWS Lambda Python package - no module named redis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM