This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
237 lines (227 loc) · 8.01 KB
/
serverless.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
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
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: lag-suc # NOTE: update this with your service name
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
provider:
name: aws
runtime: nodejs6.10
region: ${opt:region}
stage: ${opt:stage}
iamRoleStatements:
- Effect: Allow
Action:
- sqs:SendMessage
- sqs:GetQueueURL
Resource: ${self:custom.UsersQueueData.Arn}
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:DeleteItem
- dynamodb:DescribeTable
Resource:
- ${self:custom.TableArns.userCacheTable}
- ${self:custom.TableArns.loanCacheTable}
- ${self:custom.TableArns.requestCacheTable}
functions:
LoanUpdated: # Handles SNS events of type LOAN_CREATED, LOAN_DUE_DATE and LOAN_RETURNED
handler: src/loan-updated/handler.handle
events:
- sns:
arn: ${self:custom.TopicArns.${opt:stage}.LoanCreated}
- sns:
arn: ${self:custom.TopicArns.${opt:stage}.LoanDueDate}
- sns:
arn: ${self:custom.TopicArns.${opt:stage}.LoanRenewed}
environment:
UserCacheTableName: ${self:custom.TableNames.userCacheTable}
LoanCacheTableName: ${self:custom.TableNames.loanCacheTable}
UsersQueueName: ${self:custom.UsersQueueData.Name}
UsersQueueOwner: ${self:custom.UsersQueueData.Owner}
UsersQueueURL: ${self:custom.UsersQueueData.URL}
LoanReturned: # Handles SNS events of type LOAN_RETURNED
handler: src/loan-returned/handler.handle
events:
- sns:
arn: ${self:custom.TopicArns.${opt:stage}.LoanReturned}
environment:
UserCacheTableName: ${self:custom.TableNames.userCacheTable}
LoanCacheTableName: ${self:custom.TableNames.loanCacheTable}
UsersQueueName: ${self:custom.UsersQueueData.Name}
UsersQueueOwner: ${self:custom.UsersQueueData.Owner}
UsersQueueURL: ${self:custom.UsersQueueData.URL}
RequestUpdated: # Handles SNS events of type REQUEST_CREATED, REQUEST_PLACED_ON_SHELF
handler: src/request-updated/handler.handle
events:
- sns:
arn: ${self:custom.TopicArns.${opt:stage}.RequestCreated}
- sns:
arn: ${self:custom.TopicArns.${opt:stage}.RequestPlacedOnShelf}
environment:
UserCacheTableName: ${self:custom.TableNames.userCacheTable}
RequestCacheTableName: ${self:custom.TableNames.requestCacheTable}
UsersQueueName: ${self:custom.UsersQueueData.Name}
UsersQueueOwner: ${self:custom.UsersQueueData.Owner}
UsersQueueURL: ${self:custom.UsersQueueData.URL}
RequestClosed: # Handles SNS events of type REQUEST_CLOSED and REQUEST_CANCELED
handler: src/request-closed/handler.handle
events:
- sns:
arn: ${self:custom.TopicArns.${opt:stage}.RequestClosed}
- sns:
arn: ${self:custom.TopicArns.${opt:stage}.RequestCanceled}
environment:
UserCacheTableName: ${self:custom.TableNames.userCacheTable}
RequestCacheTableName: ${self:custom.TableNames.requestCacheTable}
UsersQueueName: ${self:custom.UsersQueueData.Name}
UsersQueueOwner: ${self:custom.UsersQueueData.Owner}
UsersQueueURL: ${self:custom.UsersQueueData.URL}
resources:
Resources:
userCacheTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: primary_id
AttributeType: S
KeySchema:
- AttributeName: primary_id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
TimeToLiveSpecification:
AttributeName: expiry_date
Enabled: true
loanCacheTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: loan_id
AttributeType: S
KeySchema:
- AttributeName: loan_id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
TimeToLiveSpecification:
AttributeName: expiry_date
Enabled: true
requestCacheTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: request_id
AttributeType: S
KeySchema:
- AttributeName: request_id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
TimeToLiveSpecification:
AttributeName: record_expiry_date
Enabled: true
usersQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${opt:stage}-usersQueue
RedrivePolicy:
deadLetterTargetArn: ${self:custom.UsersDLQ.Arn}
maxReceiveCount: 3
usersDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${opt:stage}-usersDLQ
MessageRetentionPeriod: 1209600
Outputs:
UserCacheTableArn:
Description: Arn of User Cache Table
Value: ${self:custom.TableArns.userCacheTable}
Export:
Name: ${self:service}:${opt:stage}:UserCacheTableArn
LoanCacheTableArn:
Description: Arn of Loan Cache Table
Value: ${self:custom.TableArns.loanCacheTable}
Export:
Name: ${self:service}:${opt:stage}:LoanCacheTableArn
RequestCacheTableArn:
Description: Arn of Request Cache Table
Value: ${self:custom.TableArns.requestCacheTable}
Export:
Name: ${self:service}:${opt:stage}:RequestCacheTableArn
UsersQueueName:
Description: Name of Users Queue
Value: ${self:custom.UsersQueueData.Name}
Export:
Name: ${self:service}:${opt:stage}:UsersQueueName
UsersQueueOwner:
Description: AWS Account ID of owner of Users Queue
Value: '#{AWS::AccountId}'
Export:
Name: ${self:service}:${opt:stage}:UsersQueueOwner
UsersQueueArn:
Description: Arn of Users Queue
Value: ${self:custom.UsersQueueData.Arn}
Export:
Name: ${self:service}:${opt:stage}:UsersQueueArn
custom:
TopicArns:
stg:
LoanCreated: ${env:LOAN_CREATED_TOPIC_ARN_STG}
LoanDueDate: ${env:LOAN_DUE_DATE_TOPIC_ARN_STG}
LoanReturned: ${env:LOAN_RETURNED_TOPIC_ARN_STG}
LoanRenewed: ${env:LOAN_RENEWED_TOPIC_ARN_STG}
RequestCreated: ${env:REQUEST_CREATED_TOPIC_ARN_STG}
RequestPlacedOnShelf: ${env:REQUEST_PLACED_ON_SHELF_TOPIC_ARN_STG}
RequestClosed: ${env:REQUEST_CLOSED_TOPIC_ARN_STG}
RequestCanceled: ${env:REQUEST_CANCELED_TOPIC_ARN_STG}
prod:
LoanCreated: ${env:LOAN_CREATED_TOPIC_ARN_PROD}
LoanDueDate: ${env:LOAN_DUE_DATE_TOPIC_ARN_PROD}
LoanReturned: ${env:LOAN_RETURNED_TOPIC_ARN_PROD}
LoanRenewed: ${env:LOAN_RENEWED_TOPIC_ARN_PROD}
RequestCreated: ${env:REQUEST_CREATED_TOPIC_ARN_PROD}
RequestPlacedOnShelf: ${env:REQUEST_PLACED_ON_SHELF_TOPIC_ARN_PROD}
RequestClosed: ${env:REQUEST_CLOSED_TOPIC_ARN_PROD}
RequestCanceled: ${env:REQUEST_CANCELED_TOPIC_ARN_PROD}
TableArns:
userCacheTable:
"Fn::GetAtt": [userCacheTable, Arn]
loanCacheTable:
"Fn::GetAtt": [loanCacheTable, Arn]
requestCacheTable:
"Fn::GetAtt": [requestCacheTable, Arn]
TableNames:
userCacheTable:
Ref: userCacheTable
loanCacheTable:
Ref: loanCacheTable
requestCacheTable:
Ref: requestCacheTable
UsersQueueData:
Name:
"Fn::GetAtt": ["usersQueue", "QueueName"]
Arn:
"Fn::GetAtt": ["usersQueue", "Arn"]
Owner: '#{AWS::AccountId}'
URL:
Ref: usersQueue
UsersDLQ:
Arn:
"Fn::GetAtt": ["usersDLQ", "Arn"]
plugins:
- serverless-pseudo-parameters