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
207 lines (200 loc) · 6.64 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
service: lag-buc
provider:
name: aws
runtime: nodejs6.10
region: ${opt:region}
stage: ${opt:stage}
iamRoleStatements:
- Effect: Allow
Action:
- sqs:SendMessage
- sqs:GetQueueUrl
- sqs:ReceiveMessage
- sqs:DeleteMessage
Resource:
- ${self:custom.QueueArns.${opt:stage}.usersQueue}
- ${self:custom.QueueArns.${opt:stage}.loansQueue}
- ${self:custom.QueueArns.${opt:stage}.requestsQueue}
- ${self:custom.QueueArns.${opt:stage}.feesQueue}
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:DeleteItem
- dynamodb:DescribeTable
Resource:
- ${self:custom.TableArns.${opt:stage}.usersCacheTable}
- ${self:custom.TableArns.${opt:stage}.loansCacheTable}
- ${self:custom.TableArns.${opt:stage}.requestsCacheTable}
- ${self:custom.TableArns.${opt:stage}.feesCacheTable}
- Effect: Allow
Action:
- ssm:GetParameter
Resource:
- arn:aws:ssm:${opt:region}:#{AWS::AccountId}:parameter${env:ALMA_API_KEY_NAME}
functions:
updateUser:
handler: src/update-user/handler.handle
events:
- sqs:
arn: ${self:custom.QueueArns.${opt:stage}.usersQueue}
environment:
LOANS_QUEUE_URL: ${self:custom.QueueUrls.${opt:stage}.loansQueue}
REQUESTS_QUEUE_URL: ${self:custom.QueueUrls.${opt:stage}.requestsQueue}
FEES_QUEUE_URL: ${self:custom.QueueUrls.${opt:stage}.feesQueue}
USER_CACHE_TABLE: ${self:custom.TableNames.${opt:stage}.usersCacheTable}
ALMA_API_KEY_NAME: ${env:ALMA_API_KEY_NAME}
updateLoan:
handler: src/update-loan/handler.handle
events:
- sqs:
arn: ${self:custom.QueueArns.${opt:stage}.loansQueue}
environment:
LOAN_CACHE_TABLE: ${self:custom.TableNames.${opt:stage}.loansCacheTable}
ALMA_API_KEY_NAME: ${env:ALMA_API_KEY_NAME}
updateRequest:
handler: src/update-request/handler.handle
events:
- sqs:
arn: ${self:custom.QueueArns.${opt:stage}.requestsQueue}
environment:
REQUEST_CACHE_TABLE: ${self:custom.TableNames.${opt:stage}.requestsCacheTable}
ALMA_API_KEY_NAME: ${env:ALMA_API_KEY_NAME}
updateFee:
handler: src/update-fee/handler.handle
events:
- sqs:
arn: ${self:custom.QueueArns.${opt:stage}.feesQueue}
environment:
FEE_CACHE_TABLE: ${self:custom.TableNames.${opt:stage}.feesCacheTable}
ALMA_API_KEY_NAME: ${env:ALMA_API_KEY_NAME}
resources:
Resources:
loansQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${opt:stage}-loansQueue
RedrivePolicy:
deadLetterTargetArn: ${self:custom.QueueArns.DLQs.loansDLQ}
maxReceiveCount: 3
requestsQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${opt:stage}-requestsQueue
RedrivePolicy:
deadLetterTargetArn: ${self:custom.QueueArns.DLQs.requestsDLQ}
maxReceiveCount: 3
feesQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${opt:stage}-feesQueue
RedrivePolicy:
deadLetterTargetArn: ${self:custom.QueueArns.DLQs.feesDLQ}
maxReceiveCount: 3
loansDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${opt:stage}-loansDLQ
MessageRetentionPeriod: 1209600
requestsDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${opt:stage}-requestsDLQ
MessageRetentionPeriod: 1209600
feesDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${opt:stage}-feesDLQ
MessageRetentionPeriod: 1209600
feeCacheTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
TimeToLiveSpecification:
AttributeName: expiry_date
Enabled: true
custom:
TableArns:
stg:
usersCacheTable: arn:aws:dynamodb:#{AWS::Region}:#{AWS::AccountId}:table/${env:USER_CACHE_TABLE_NAME_STG}
loansCacheTable: arn:aws:dynamodb:#{AWS::Region}:#{AWS::AccountId}:table/${env:LOAN_CACHE_TABLE_NAME_STG}
requestsCacheTable: arn:aws:dynamodb:#{AWS::Region}:#{AWS::AccountId}:table/${env:REQUEST_CACHE_TABLE_NAME_STG}
feesCacheTable:
"Fn::GetAtt": [feeCacheTable, Arn]
prod:
usersCacheTable: arn:aws:dynamodb:#{AWS::Region}:#{AWS::AccountId}:table/${env:USER_CACHE_TABLE_NAME_PROD}
loansCacheTable: arn:aws:dynamodb:#{AWS::Region}:#{AWS::AccountId}:table/${env:LOAN_CACHE_TABLE_NAME_PROD}
requestsCacheTable: arn:aws:dynamodb:#{AWS::Region}:#{AWS::AccountId}:table/${env:REQUEST_CACHE_TABLE_NAME_PROD}
feesCacheTable:
"Fn::GetAtt": [feeCacheTable, Arn]
TableNames:
stg:
usersCacheTable: ${env:USER_CACHE_TABLE_NAME_STG}
loansCacheTable: ${env:LOAN_CACHE_TABLE_NAME_STG}
requestsCacheTable: ${env:REQUEST_CACHE_TABLE_NAME_STG}
feesCacheTable:
Ref: feeCacheTable
prod:
usersCacheTable: ${env:USER_CACHE_TABLE_NAME_PROD}
loansCacheTable: ${env:LOAN_CACHE_TABLE_NAME_PROD}
requestsCacheTable: ${env:REQUEST_CACHE_TABLE_NAME_PROD}
feesCacheTable:
Ref: feeCacheTable
QueueArns:
stg:
usersQueue: ${env:USER_QUEUE_ARN_STG}
loansQueue:
"Fn::GetAtt": ["loansQueue", "Arn"]
requestsQueue:
"Fn::GetAtt": ["requestsQueue", "Arn"]
feesQueue:
"Fn::GetAtt": ["feesQueue", "Arn"]
prod:
usersQueue: ${env:USER_QUEUE_ARN_PROD}
loansQueue:
"Fn::GetAtt": ["loansQueue", "Arn"]
requestsQueue:
"Fn::GetAtt": ["requestsQueue", "Arn"]
feesQueue:
"Fn::GetAtt": ["feesQueue", "Arn"]
DLQs:
loansDLQ:
"Fn::GetAtt": ["loansDLQ", "Arn"]
requestsDLQ:
"Fn::GetAtt": ["requestsDLQ", "Arn"]
feesDLQ:
"Fn::GetAtt": ["feesDLQ", "Arn"]
QueueUrls:
stg:
usersQueue: ${env:USER_QUEUE_URL_STG}
loansQueue:
Ref: loansQueue
requestsQueue:
Ref: requestsQueue
feesQueue:
Ref: feesQueue
prod:
usersQueue: ${env:USER_QUEUE_URL_PROD}
loansQueue:
Ref: loansQueue
requestsQueue:
Ref: requestsQueue
feesQueue:
Ref: feesQueue
DLQs:
loansDLQ:
Ref: loansDLQ
requestsDLQ:
Ref: requestsDLQ
feesDLQ:
Ref: feesDLQ
plugins:
- serverless-pseudo-parameters