-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
271 lines (258 loc) · 8.71 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: >
eventbridge-integration-solution-zendesk-attachment-processing
(qs-1qpmal5co)
Metadata:
AWS::ServerlessRepo::Application:
Name: Amazon-EventBridge-Integration-Solution-Zendesk-Attachment-Processing
Description: This application demonstrates processing Zendesk ticket attachments using AWS Step Functions, AWS Lambda, and the Zendesk Amazon EventBridge Integration.
Author: AWS Quick Start
LicenseUrl: LICENSE
ReadmeUrl: README.md
Labels: ['amazon', 'eventbridge', 'integration', 'solution', 'lambda', 'step_functions', 'aws', 'attachment']
HomePageUrl: https://aws.amazon.com/quickstart/eventbridge/zendesk-attachment-processing/
SemanticVersion: 0.1.2
SourceCodeUrl: https://github.com/aws-quickstart/eventbridge-integration-solution-zendesk-attachment-processing
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Amazon EventBridge Integration Solution
Parameters:
- EventSourceName
- Label:
default: Amazon S3 Bucket for Attachment Files
Parameters:
- BucketName
- Label:
default: Zendesk Configuration
Parameters:
- ZendeskAPIToken
- ZendeskEmail
- ZendeskSubdomain
ParameterLabels:
EventSourceName:
default: Event Source Name
BucketName:
default: Bucket Name
ZendeskAPIToken:
default: API Token
ZendeskEmail:
default: Email
ZendeskSubdomain:
default: Subdomain
Parameters:
# Follow instructions in the EventBridge console to set up Zendesk as a partner event source.
# Pass the partner event source name as your EventSourceName parameter.
# Ex: aws.partner/zendesk.com/1234/default
EventSourceName:
Type: String
AllowedPattern: aws\.partner(/[\.\-_A-Za-z0-9]+){2,}
MinLength: 1
MaxLength: 256
Description: Name of the Zendesk Partner Event Source to associate with an Event Bus. For example, aws.partner/zendesk.com/1234/default
ZendeskAPIToken:
Type: String
NoEcho: true
MinLength: 1
Description: The Zendesk API token used to access the Zendesk API
ZendeskEmail:
Type: String
MinLength: 1
Description: The Zendesk agent email used for Zendesk API access
ZendeskSubdomain:
Type: String
MinLength: 1
Description: The Zendesk subdomain which is a unique identifier of your Zendesk account
BucketName:
Type: String
Default: ''
AllowedPattern: '[a-zA-Z0-9.-]*'
MaxLength: 63
Description: Name of the Amazon S3 Bucket to create to store Zendesk attachment files for processing. Leave blank for an automatically generated name.
Globals:
Function:
Timeout: 30
Runtime: python3.8
Conditions:
AutoGenerateBucketName:
!Equals [ !Ref BucketName, '' ]
Resources:
# EventBridge
ZendeskEventBus:
Type: AWS::Events::EventBus
Properties:
EventSourceName: !Ref EventSourceName
Name: !Ref EventSourceName
# S3 bucket
AttachmentFileBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
BucketName:
!If [ AutoGenerateBucketName, !Ref 'AWS::NoValue', !Ref BucketName ]
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
# Lambda functions
GetAttachment:
Type: AWS::Serverless::Function
Properties:
Handler: app.lambda_handler
CodeUri: src/get_attachment
Description: A function that retrieves a file attached to a Zendesk comment.
Policies:
- S3WritePolicy:
BucketName: !Ref AttachmentFileBucket
Environment:
Variables:
S3_BUCKET: !Ref AttachmentFileBucket
GetText:
Type: AWS::Serverless::Function
Properties:
Handler: app.lambda_handler
CodeUri: src/get_text
Description: A function that extracts text from a given file using Textract.
Policies:
- TextractPolicy: {}
- S3ReadPolicy:
BucketName: !Ref AttachmentFileBucket
Environment:
Variables:
S3_BUCKET: !Ref AttachmentFileBucket
DetectImages:
Type: AWS::Serverless::Function
Properties:
Handler: app.lambda_handler
CodeUri: src/detect_images
Description: A function that analyizes images from a given file using Textract.
Policies:
- RekognitionDetectOnlyPolicy: {}
- S3ReadPolicy:
BucketName: !Ref AttachmentFileBucket
Environment:
Variables:
S3_BUCKET: !Ref AttachmentFileBucket
PostComment:
Type: AWS::Serverless::Function
Properties:
Handler: app.lambda_handler
CodeUri: src/post_comment
Description: A function that posts the extracted text and objects detected in a comment on the Zendesk ticket.
Environment:
Variables:
ZENDESK_EMAIL: !Ref ZendeskEmail
ZENDESK_SUBDOMAIN: !Ref ZendeskSubdomain
ZENDESK_TOKEN: !Ref ZendeskAPIToken
# Step Functions state machine
AttachmentProcessor:
Type: AWS::Serverless::StateMachine
Properties:
Definition:
StartAt: GetAttachment
States:
GetAttachment:
Type: Task
Resource: !GetAtt GetAttachment.Arn
Next: isSupportedFileType
isSupportedFileType:
Type: Choice
Choices:
- Variable: "$.accepted_file_type"
BooleanEquals: true
Next: GetTextAndImages
- Variable: "$.accepted_file_type"
BooleanEquals: false
Next: UnsupportedFileTypeSucceed
Default: FileTypeCheckFail
UnsupportedFileTypeSucceed:
Type: Succeed
FileTypeCheckFail:
Type: Fail
Cause: Could not determine if supported or unsupported file type.
GetTextAndImages:
Type: Parallel
Next: PostComment
Branches:
- StartAt: GetText
States:
GetText:
Type: Task
Resource: !GetAtt GetText.Arn
End: true
- StartAt: DetectImages
States:
DetectImages:
Type: Task
Resource: !GetAtt DetectImages.Arn
End: true
PostComment:
Type: Task
Resource: !GetAtt PostComment.Arn
End: true
Events:
EventBridgeRule:
Type: EventBridgeRule
Properties:
EventBusName: !Ref ZendeskEventBus
Pattern:
account:
- !Ref "AWS::AccountId"
detail-type:
- "Support Ticket: Attachment Linked to Comment"
Policies:
- LambdaInvokePolicy:
FunctionName: !Ref GetAttachment
- LambdaInvokePolicy:
FunctionName: !Ref GetText
- LambdaInvokePolicy:
FunctionName: !Ref DetectImages
- LambdaInvokePolicy:
FunctionName: !Ref PostComment
Type: STANDARD
Outputs:
EventBridgeEventBus:
Description: SaaS Event Bus ARN
Value: !GetAtt ZendeskEventBus.Arn
EventBridgeRule:
Description: Implicit EventBridge Rule ARN
Value: !GetAtt AttachmentProcessorEventBridgeRule.Arn
AttachmentProcessor:
Description: AttachmentProcessor state machine ARN
Value: !Ref AttachmentProcessor
AttachmentProcessorIamRole:
Description: Implicit IAM Role created for AttachmentProcessor state machine
Value: !GetAtt AttachmentProcessorRole.Arn
GetAttachmentFunction:
Description: GetAttachment Function ARN
Value: !GetAtt GetAttachment.Arn
GetAttachmentFunctionIamRole:
Description: Implicit IAM Role created for GetAttachment Function
Value: !GetAtt GetAttachmentRole.Arn
GetTextFunction:
Description: GetText Function ARN
Value: !GetAtt GetText.Arn
GetTextFunctionIamRole:
Description: Implicit IAM Role created for GetText Function
Value: !GetAtt GetTextRole.Arn
DetectImagesFunction:
Description: DetectImages Function ARN
Value: !GetAtt DetectImages.Arn
DetectImagesFunctionIamRole:
Description: Implicit IAM Role created for DetectImages Function
Value: !GetAtt DetectImagesRole.Arn
PostCommentFunction:
Description: PostComment Function ARN
Value: !GetAtt PostComment.Arn
PostCommentFunctionIamRole:
Description: Implicit IAM Role created for PostComment Function
Value: !GetAtt PostCommentRole.Arn
S3Bucket:
Description: S3 Bucket to save attachments for processing
Value: !GetAtt AttachmentFileBucket.Arn