forked from sugarcrm/SugarLambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
executable file
·192 lines (180 loc) · 6.61 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
# This is the SAM template that represents the architecture of your serverless application
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html
# The AWSTemplateFormatVersion identifies the capabilities of the template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html
AWSTemplateFormatVersion: 2010-09-09
Description: >-
SugarLambda
# Transform section specifies one or more macros that AWS CloudFormation uses to process your template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html
Transform:
- AWS::Serverless-2016-10-31
# Environment variables
Parameters:
SugarUsername:
Type: String
Default: ''
Description: Sugar Username for Authentication with Lambda
SugarPassword:
Type: String
Default: ''
Description: Sugar Password for Authentication with Lambda
SugarUrl:
Type: String
Default: ''
Description: URL of your Sugar Instance
AwsConnectInstance:
Type: String
Default: ''
Description: AWS Connect instance name
ContactFlowId:
Type: String
Description: The contact flow id that the customer will interact with while chatting
AllowedPattern: '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}'
InstanceId:
Type: String
Description: The instance id of the Amazon Connect instance that the customer will interact with while chatting
AllowedPattern: '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}'
# Resources declares the AWS resources that you want to include in the stack
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html
Resources:
# Each Lambda function is defined by properties:
# https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
# This is a Lambda function config associated with the source code: create-case.js
CreateCaseFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/create-case.createCaseHandler
Runtime: nodejs12.x
MemorySize: 128
Timeout: 100
Environment:
Variables:
sugarUsername: !Ref SugarUsername
sugarPass: !Ref SugarPassword
sugarUrl: !Ref SugarUrl
Description: A Lambda function that creates a case.
Policies:
# Give Lambda basic execution Permission to write CloudWatch logs
- AWSLambdaBasicExecutionRole
# This is a Lambda function config for source code: case-status.js
CaseStatusFunction:
Type: 'AWS::Serverless::Function'
Properties:
Description: AWS Lambda Function to get case status by case number
Handler: 'src/handlers/case-status.handler'
Runtime: 'nodejs12.x'
MemorySize: 128
Timeout: 60
Environment:
Variables:
sugarUsername: !Ref SugarUsername
sugarPass: !Ref SugarPassword
sugarUrl: !Ref SugarUrl
Policies:
# Give Lambda basic execution Permission to createCase
- AWSLambdaBasicExecutionRole
SaveCallTranscriptFunction:
Type: 'AWS::Serverless::Function'
Properties:
Description: AWS Lambda Function to save call transcripts based on S3 Trigger
Handler: 'src/handlers/save-transcript.handler'
Runtime: 'nodejs12.x'
MemorySize: 128
Role: !GetAtt s3CloudwatchLambdaExecutionRole.Arn
Timeout: 60
Environment:
Variables:
sugarUsername: !Ref SugarUsername
sugarPass: !Ref SugarPassword
sugarUrl: !Ref SugarUrl
CallRecordingFunction:
Type: 'AWS::Serverless::Function'
Properties:
Description: AWS Lambda Function to perform actions on the call recording
Handler: 'src/handlers/call-recording.handler'
Runtime: 'nodejs12.x'
MemorySize: 128
Role: !GetAtt s3CloudwatchLambdaExecutionRole.Arn
Timeout: 60
Environment:
Variables:
sugarUsername: !Ref SugarUsername
sugarPass: !Ref SugarPassword
sugarUrl: !Ref SugarUrl
awsConnectInstance: !Ref AwsConnectInstance
# Function to start connect Chat from API call
StartChatFunction:
Type: 'AWS::Serverless::Function'
Properties:
Description: AWS Lambda Function to start chat from incoming API call
Handler: 'src/handlers/start-chat.handler'
Runtime: 'nodejs12.x'
MemorySize: 128
Role: !GetAtt StartChatLambdaExecutionRole.Arn
Timeout: 60
Environment:
Variables:
instanceId: !Ref InstanceId
contactFlowId: !Ref ContactFlowId
Events:
GetRoot:
Type: Api
Properties:
RestApiId: !Ref StartChatApiGateway
Path: /
Method: post
# Role to combine S3, CloudWatch, and Basic Lambda permissions for saving
s3CloudwatchLambdaExecutionRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/AmazonS3FullAccess"
- "arn:aws:iam::aws:policy/CloudWatchLogsFullAccess"
- "arn:aws:iam::aws:policy/AWSLambdaExecute"
# Role to give StartChat lambda access to the client amazon connect instance
StartChatLambdaExecutionRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
Policies:
- PolicyName: start-chat-contact-execution-policy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource:
- !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
- Effect: "Allow"
Action:
- "connect:StartChatContact"
Resource:
- !Sub "arn:${AWS::Partition}:connect:${AWS::Region}:${AWS::AccountId}:instance/${InstanceId}"
- !Sub "arn:${AWS::Partition}:connect:${AWS::Region}:${AWS::AccountId}:instance/${InstanceId}/*"
StartChatApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: Prod