This app contains a monitoring SNS topic that can get notifications from other AWS resources.
A Lambda function will send every notification arriving to SNS to Slack using a Slack WebHook.
This app is built using AWS SAM and required SAM CLI https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
The Lambda function is written in Python and is using AWS Lambda Powertools https://awslabs.github.io/aws-lambda-powertools-python/latest/ Lambda Powertools is set to:
- send Lambda function logs to CloudWatch
- send tracing info to X-Ray
- get SNS message as class rather than as default Lambda event
dict
- Navigate to https://.slack.com/services/new
- Search for and select "Incoming WebHooks".
- Choose the default channel where messages will be sent and click "Add Incoming WebHooks Integration".
- Copy the webhook URL from the setup instructions and use it in the next section.
sam build --use-container --cached --parameter-overrides Env=develop SlackChannel=#develop-notifications SlackHookURL=<YOUR_WEBHOOK_URL>
sam local invoke -e events/sns-cloudwatch.json LambdaSlack --parameter-overrides 'Env=develop SlackChannel=#develop-notifications SlackHookURL=<YOUR_WEBHOOK_URL>' --debug
sam deploy --stack-name monitoring-and-alerting-<ENVIRONMENT> --s3-bucket <YOUR_S3_BUCKET> --s3-prefix monitoring_and_alerting --capabilities CAPABILITY_IAM --parameter-overrides Env=develop SlackChannel=#develop-notifications SlackHookURL=<YOUR_WEBHOOK_URL>-
Other AWS resources can get the SNS topic ARN using one of the following ways:
- SSM Parameters store. The SSM Parameter name is
alerting-sns-topic-arn-<environment>
- CloudFormation stack outputs. After deployment navigate to CloudFormation -> monitoring-and-alerting -> Outputs
- SAM outputs will contain the ARN, for example:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Outputs
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key SNSTopicAlertingArn
Description Alerting SNS Topic ARN
Value arn:aws:sns:us-east-1:12345678:monitoring-and-alerting-SNSTopicAlerting-ABCD1234
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------