Simple monitoring using requests and unittest on AWS Lambda
How to use:
- Create a Simple Notification Service (SNS) topic with email recipients and set the ARN as SNS_TOPIC_ARN in checks.py
- Copy checks_example.py to checks.py and customize with your test cases
- Create an IAM role called
lambda_snswith the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sns:*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
- Run
make packageto create function_package.zip, upload to Lambda - Configure Lambda:
Runtime: Python 2.7 Handler: lambda_function.lambda_handler Role: lambda_sns
-
Configure trigger: CloudWatch Events - Schedule Rule Name: (whatever you want) Schedule expression: rate(5 minutes) or any interval you like Enable Trigger checkbox
-
Run your lambda function with a failing test to make sure that SNS is configured correctly with the right permissions.
You can test your checks on your computer outside of Lambda by running
python lambda_function.py
with the AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID environment variables exported into your shell.