Skip to content

Instantly share code, notes, and snippets.

@chrisj-au
Last active November 26, 2020 23:53
Show Gist options
  • Save chrisj-au/a5a9c3faaa1f83cb6def43aedfc707a5 to your computer and use it in GitHub Desktop.
Save chrisj-au/a5a9c3faaa1f83cb6def43aedfc707a5 to your computer and use it in GitHub Desktop.
CloudFormation: Lambda Error Notification
## Add SNS Notifications of Lambda failures. Only alarms on text sent to CloudWatch logs
Parameters:
AppName:
Type: String
SNSEmail:
Type: String
Resources:
Lambda:
Type: AWS::Serverless::Function
Properties:
Description: Do a lambda thing!
FunctionName: !Ref AppName
## More properties needed..
LambdaLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${Lambda}"
RetentionInDays: 14
FailedAuthMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Ref LambdaLogGroup
FilterPattern: >-
"[ERROR]"
MetricTransformations:
- MetricValue: '1'
DefaultValue: '0'
MetricNamespace: LambdaMetrics
MetricName: LambdaFailures
LambdaErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: github_gobbler_lambda_error
AlarmDescription: >-
A CloudWatch Alarm that triggers if there are errors returned from the Lambda
MetricName: LambdaFailures
Namespace: LambdaMetrics
Statistic: Sum
Period: '300'
EvaluationPeriods: '1'
Threshold: '1'
ComparisonOperator: GreaterThanOrEqualToThreshold
AlarmActions:
- Ref: NotifySNS
TreatMissingData: notBreaching
NotifySNS:
Type: AWS::SNS::Topic
Condition: NotifyOnLambdaError
Properties:
DisplayName: !Sub ${AppName}-Lambda-Error
Subscription:
- Endpoint: !Ref SNSEmail
Protocol: Email
TopicName: !Sub ${AppName}Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment