-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
110 lines (104 loc) · 2.56 KB
/
template.yaml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
SNSToLambdaToSlack
- SNS -> Subscription, Lambda -> Slack
Globals:
Function:
Timeout: 30
Parameters:
NotifyLambdaName:
Type: String
Default: SNSToLambdaToSlack
Description: Set a clear name for identity
SlackHookUrl:
Type: String
Default: ""
Description: "Set slack url, http://..."
InfoChannel:
Type: String
Default: "#general"
Description: Set slack url
IssueChannel:
Type: String
Default: "#general"
Description: Set slack url
Resources:
notifyLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: app/
Handler: app.lambda_handler
FunctionName: !Ref NotifyLambdaName
Description: "sns->lambda->slack"
MemorySize: 128
Runtime: python3.8
Environment:
Variables:
hookUrl: !Ref SlackHookUrl
InfoChannel: !Ref InfoChannel
IssueChannel: !Ref IssueChannel
InfoTopicArn: !Ref InfoSNS
IssueTopicArn: !Ref IssueSNS
Events:
infoEvent:
Type: SNS
Properties:
Topic: !Ref InfoSNS
issueEvent:
Type: SNS
Properties:
Topic: !Ref IssueSNS
## SNS
InfoSNS:
Type: AWS::SNS::Topic
Properties:
DisplayName: !Join
- "-"
- - !Ref NotifyLambdaName
- "INFO"
TopicName: !Join
- "-"
- - !Ref NotifyLambdaName
- "INFO"
InfoSNSTopicSubscription:
Type: AWS::SNS::Subscription
Properties:
Endpoint: !Join
- ':'
- - 'arn:aws:lambda'
- !Ref AWS::Region
- !Ref 'AWS::AccountId'
- 'function'
- !Ref notifyLambda
Protocol: lambda
TopicArn: !Ref InfoSNS
IssueSNS:
Type: AWS::SNS::Topic
Properties:
DisplayName: !Join
- "-"
- - !Ref NotifyLambdaName
- "ISSUE"
# 透過 AWS::SNS::Topic 建立訂閱, 無法在 CFN 刪除時, 一並刪除
# Subscription:
# - Endpoint: !GetAtt
# - myLambda
# - Arn
# Protocol: lambda
TopicName: !Join
- "-"
- - !Ref NotifyLambdaName
- "ISSUE"
IssueSNSTopicSubscription:
Type: AWS::SNS::Subscription
Properties:
Endpoint: !Join
- ':'
- - 'arn:aws:lambda'
- !Ref AWS::Region
- !Ref 'AWS::AccountId'
- 'function'
- !Ref notifyLambda
Protocol: lambda
TopicArn: !Ref IssueSNS