-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate.yaml
More file actions
59 lines (52 loc) · 1.73 KB
/
template.yaml
File metadata and controls
59 lines (52 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
LogPulse: Real-time CloudWatch Logs Analyzer & Slack Notifier
Reads CloudWatch Logs, filters for specific error patterns, and sends notifications to Slack.
Globals:
Function:
Timeout: 10
MemorySize: 128
Runtime: nodejs20.x
Parameters:
SlackWebhookUrl:
Type: String
Description: "The Slack Incoming Webhook URL to send notifications to."
LogGroupName:
Type: String
Description: "The existing CloudWatch Log Group to subscribe to."
FilterPattern:
Type: String
Default: "CRITICAL-ERROR"
Description: "The pattern to filter logs for."
Resources:
LogAnalyzerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: handlers/logAnalyzer.handler
Environment:
Variables:
SLACK_WEBHOOK_URL: !Ref SlackWebhookUrl
Policies:
- AWSLambdaBasicExecutionRole
# Permission for CloudWatch Logs to invoke the Lambda
LambdaInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref LogAnalyzerFunction
Action: lambda:InvokeFunction
Principal: logs.amazonaws.com
SourceArn: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${LogGroupName}:*"
# The Subscription Filter that connects the Log Group to Lambda
LogSubscriptionFilter:
Type: AWS::Logs::SubscriptionFilter
Properties:
LogGroupName: !Ref LogGroupName
FilterPattern: !Ref FilterPattern
DestinationArn: !GetAtt LogAnalyzerFunction.Arn
DependsOn: LambdaInvokePermission
Outputs:
LogAnalyzerFunctionArn:
Description: "Log Analyzer Lambda Function ARN"
Value: !GetAtt LogAnalyzerFunction.Arn