This repository has been archived by the owner on Dec 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
142 lines (132 loc) · 4.37 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Zendesk Translator
Zendesk Translator lambda via partner eventbridge
Parameters:
Environment:
Type: String
DebugParam:
Type: String
ZendeskKeySSMParameterPath:
Type: String
ZendeskUsernameMail:
Type: String
ZendeskSubdomain:
Type: String
ZendeskTicketLangFieldId:
Type: String
KmsKeyId:
Type: String
EventBusName:
Type: String
AllowedPattern: aws\.partner(/[\.\-_A-Za-z0-9]+){2,}
MinLength: 1
MaxLength: 256
Description: Name of the Amazon EventBridge Zendesk Event Source to associate with an Event Bus. For example, aws.partner/zendesk.com/123456/default
#Manual step needs to be done before this can be run and that is to setup the eventbridge in the console of AWS Eventbridge (and follow instructions on zendesk side)
Resources:
ZendeskEventBus:
Type: AWS::Events::EventBus
Properties:
Name: !Ref EventBusName
EventSourceName: !Ref EventBusName
EBZendeskTranslate:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub eb-zendesk-translate-${Environment}
CodeUri: lambda/
Handler: app.lambdaHandler
Runtime: nodejs12.x
Timeout: 10
Environment:
Variables:
DEBUG: !Ref DebugParam
ZENDESK_ACCESS_TOKEN_PARAM_KEY: !Ref ZendeskKeySSMParameterPath
ZENDESK_SUBDOMAIN: !Ref ZendeskSubdomain
ZENDESK_EMAIL: !Ref ZendeskUsernameMail
ZENDESK_TICKET_LANG_FIELD_ID: !Ref ZendeskTicketLangFieldId
Policies:
- Version: '2012-10-17'
Statement:
- Sid: AWStranslate
Effect: Allow
Action:
- comprehend:DetectDominantLanguage
- translate:TranslateText
Resource: '*'
- Sid: AWSssmParameterStore
Effect: Allow
Action:
- ssm:GetParameter
Resource:
- !Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/config/zendesk-translation/*"
- Sid: KmsDecryptZendesKey
Effect: "Allow"
Action:
- kms:Decrypt
Resource:
- !Sub "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${KmsKeyId}"
Events:
InternalNote:
Type: EventBridgeRule
Properties:
EventBusName: !Ref EventBusName
Pattern:
account:
- !Sub '${AWS::AccountId}'
detail-type:
- "Support Ticket: Comment Created"
detail:
ticket_event:
type:
- "Comment Created"
comment:
body:
- "prefix": "#translate"
is_public:
- false
author:
is_staff:
- true
ticket:
via:
channel:
- "email"
- "web"
CustomerUpdate:
Type: EventBridgeRule
Properties:
EventBusName: !Ref EventBusName
Pattern:
account:
- !Sub '${AWS::AccountId}'
detail-type:
- "Support Ticket: Comment Created"
detail:
ticket_event:
type:
- "Comment Created"
comment:
is_public:
- true
author:
is_staff:
- false
ticket:
via:
channel:
- "email"
- "web"
ZendeskTranslatorLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/eb-zendesk-translate-${Environment}
RetentionInDays: 5
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
EBZendeskTranslate:
Description: "Zendesk Translator lambda ARN"
Value: !GetAtt EBZendeskTranslate.Arn