-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
192 lines (187 loc) · 7.06 KB
/
template.yml
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: A collection of utilities that integrate with Zendesk
Parameters:
PrxZendeskApiUsername: { Type: String }
PrxZendeskApiToken: { Type: String, NoEcho: true }
SlackAccessToken: { Type: String, NoEcho: true }
SlackChannelId: { Type: String }
SlackSigningSecret: { Type: String, NoEcho: true }
Resources:
NodejsSlackSdkLambdaLayer:
Type: AWS::Serverless::LayerVersion
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Metadata:
BuildMethod: makefile
Properties:
Description: Slack SDK npm libraries for Node.js
ContentUri: lib/nodejs-slack-sdk
CompatibleRuntimes:
- nodejs22.x
SuspendedTicketsPollerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/suspended-tickets-poller
Description: >-
Polls Zendesk for new suspended tickets and react when they are found,
like by sending notifications to Slack.
Environment:
Variables:
ZENDESK_API_USERNAME: !Ref PrxZendeskApiUsername
ZENDESK_API_TOKEN: !Ref PrxZendeskApiToken
SLACK_ACCESS_TOKEN: !Ref SlackAccessToken
SLACK_CHANNEL_ID: !Ref SlackChannelId
SUSPENDED_TICKET_CACHE_TABLE_NAME: !Ref SuspendedTicketsPollerCache
Events:
Poller:
Properties:
Description: Runs the Zendesk suspended tickets poller
Enabled: true
Schedule: rate(20 minutes)
Type: Schedule
Handler: index.handler
Layers:
- !Ref NodejsSlackSdkLambdaLayer
MemorySize: 128
Policies:
- Statement:
- Action:
- dynamodb:GetItem
- dynamodb:PutItem
Effect: Allow
Resource: !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${SuspendedTicketsPollerCache}
Version: "2012-10-17"
Runtime: nodejs22.x
Tags:
prx:meta:tagging-version: 2021-04-07
prx:cloudformation:stack-name: !Ref AWS::StackName
prx:cloudformation:stack-id: !Ref AWS::StackId
prx:ops:environment: Production
prx:dev:application: Zendesk Toolkit
Timeout: 16
SuspendedTicketsPollerLogGroup:
Type: AWS::Logs::LogGroup
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
LogGroupName: !Sub /aws/lambda/${SuspendedTicketsPollerFunction}
RetentionInDays: 14
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Zendesk Toolkit }
SuspendedTicketsPollerErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: "MINOR [Zendesk] Suspended Tickets Poller <prod> EXPERIENCING ERRORS"
AlarmDescription: >-
The error rate on the Zendesk app suspended tickets poller has
exceeded 0.
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: FunctionName
Value: !Ref SuspendedTicketsPollerFunction
EvaluationPeriods: 2
MetricName: Errors
Namespace: AWS/Lambda
Period: 60
Statistic: Sum
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Zendesk Toolkit }
Threshold: 0
TreatMissingData: notBreaching
SuspendedTicketsPollerCache:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
AttributeDefinitions:
- AttributeName: suspension_id
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: suspension_id
KeyType: HASH
SSESpecification:
SSEEnabled: false
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Zendesk Toolkit }
TimeToLiveSpecification:
AttributeName: cache_expiration
Enabled: true
SlackInteractivityEndpointFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/slack-interactivity-endpoint
Description: >-
Polls Zendesk for new suspended tickets and react when they are found,
like by sending notifications to Slack.
Environment:
Variables:
ZENDESK_API_USERNAME: !Ref PrxZendeskApiUsername
ZENDESK_API_TOKEN: !Ref PrxZendeskApiToken
SLACK_ACCESS_TOKEN: !Ref SlackAccessToken
SLACK_SIGNING_SECRET: !Ref SlackSigningSecret
FunctionUrlConfig:
AuthType: NONE
InvokeMode: BUFFERED
Handler: index.handler
Layers:
- !Ref NodejsSlackSdkLambdaLayer
MemorySize: 128
Runtime: nodejs22.x
Tags:
prx:meta:tagging-version: 2021-04-07
prx:cloudformation:stack-name: !Ref AWS::StackName
prx:cloudformation:stack-id: !Ref AWS::StackId
prx:ops:environment: Production
prx:dev:application: Zendesk Toolkit
Timeout: 16
SlackInteractivityEndpointLogGroup:
Type: AWS::Logs::LogGroup
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
LogGroupName: !Sub /aws/lambda/${SlackInteractivityEndpointFunction}
RetentionInDays: 14
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Zendesk Toolkit }
SlackInteractivityEndpointErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: "MINOR [Zendesk] Slack Interactivity <prod> EXPERIENCING ERRORS"
AlarmDescription: >-
The error rate on the Zendesk app Slack interactivity endpoint has
exceeded 0.
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: FunctionName
Value: !Ref SlackInteractivityEndpointFunction
EvaluationPeriods: 2
MetricName: Errors
Namespace: AWS/Lambda
Period: 60
Statistic: Sum
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:ops:environment, Value: Production }
- { Key: prx:dev:application, Value: Zendesk Toolkit }
Threshold: 0
TreatMissingData: notBreaching