The Serverless Framework can notify you in Slack, Email, SNS Topics, or via webhooks when alerts are generated for your application. Multiple notifications can be added to an application, each of which can be configured differently for different alerts, stages or services.
Fill out the form and click add notification to save the new notification. The notification can be scoped to include only the alerts, stages or services you want.
In order for Serverless Framework to notify you in a SNS Topics, it must be granted permission to publish to the topic. If you have an existing SNS Topic this is how you configure the Access Policy on the Topic to grant Serverless Framework permission to publish notifications to the topic.
Statement array in the JSON editor.{
"Sid": "ServerlessFrameworkEnterprise-Publish",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::802587217904:root"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:region:account-id:sns-topic-name"
}
Serverless Framework supports the creation of SNS Topics and the corresponding SNS Topic Policy from your serverless.yml file. The following snippet performs the following:
Once the service, SNS Topic and SNS Topic Policies are deployed via serverless deploy, go to
SNS in the AWS Console and identify the SNS Topic ARN to use with the notification.
custom:
topicName: notify
functions:
alertSnsConsumer:
handler: handler.snsConsumer
events:
- sns:
arn:
Ref: AlarmTopic
topicName: ${self:custom.topicName}
resources:
Resources:
AlarmTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: 'Serverless Alerts'
TopicName: ${self:custom.topicName}
AlarmTopicPolicy:
Type: AWS::SNS::TopicPolicy
DependsOn:
- AlarmTopic
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AllowServerlessFrameworkEnterpriseToPublish
Effect: Allow
Principal:
AWS: 'arn:aws:iam::802587217904:root'
Action: 'sns:Publish'
Resource:
Ref: AlarmTopic
Topics:
- Ref: AlarmTopic
Outputs:
SnsTopicArn:
Description: ARN for the SNS Alarm Topic
Value:
Ref: AlarmTopic
After your deploy is complete, run sls info -v to show the information about your service. At the bottom, in the Stack Outputs section, the ARN for your SNS Topic will be displayed as the SnsTopicArn output.