Reputation: 3355
Does the python script have to be named as handler.py in AWS Lambda?
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'? Thanks.
Upvotes: 1
Views: 1948
Reputation: 1001
Nope it need not necessarily be named as handler.py.
you can name whatever you want but in lambda handler give as
file_name.function_name
Just like a import
If you what have your handler file inside folders kindly include
init.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
Upvotes: 2
Reputation: 3217
Does the python script have to be named as handler.py in AWS Lambda
Shortly No, you could specify any method which could process lambda event. (Usually combination is event + context (event, context)
Just wondering where we can configure this or does it have to be '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.
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Handler: index.handler
Upvotes: 2
Reputation: 12359
You can name this Python script whatever you want. 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.
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. For example,
main.Handler
calls theHandler
method defined inmain.py
.
Upvotes: 2