I am wondering how you can separate the handler from the Lambda’s core logic. I am always putting all my boto3 code inside the Lambda handler but how to define multiple functions in a Lambda function and use these functions inside the handler ? It seems it is a best practice to do that.
For example:
def list_users():
# list iam users here
def list_user_tags():
# list tags of these users here
def something_else():
# do something else
def handler_name(event, context):
# return the result here
2
Answers
You can define a service class that is separate from the handler. Based on the event, you can invoke different methods in service class. You can also extend this idea more via Factory pattern.
You can call the other functions from the handler function, such as: