functions/notify_slack.py) that handles CloudWatch alarms, GuardDuty findings, Security Hub findings, and more. If you need different formatting, additional logic, or a completely different notification target, you can provide your own Python file.
How it works
Setlambda_source_path to the path of your Python file, relative to the root module. The module derives the handler name from the filename automatically:
lambda_source_path = "functions/mylambda.py", the handler becomes mylambda.lambda_handler. Your Python file must define a function named lambda_handler.
Example custom function
The following is thefunctions/mylambda.py example included in the module repository. It sends the raw SNS message body to a Slack channel using urllib3:
SLACK_WEBHOOK_URL, SLACK_CHANNEL, SLACK_USERNAME, and SLACK_EMOJI environment variables are always set by the module and available to your function.
Deploy a custom function
Write your custom Lambda handler
Create a Python file with a
lambda_handler(event, context) function. The file name (without the .py extension) becomes the handler module name. Place it anywhere accessible from your Terraform root module.Reference the file with lambda_source_path
Pass the path to your file using
lambda_source_path. The path is relative to your Terraform root module (where you run terraform apply).Handle multiple functions sharing the same source path
If you deploy multiple module instances from the same source file, the module uses a hash of the source path to name the deployment package. Because both instances share the same path, they would produce the same hash and conflict.Use
hash_extra to add a unique string to the hash for each instance:When
lambda_source_path is null (the default), the module uses its own bundled functions/notify_slack.py. You only need to set lambda_source_path when you want to override the default handler.