-
Notifications
You must be signed in to change notification settings - Fork 1
/
serverless.yml
217 lines (204 loc) · 6.28 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
service: kapochamo-invest
package:
individually: true
provider:
name: aws
runtime: nodejs12.x
stage: ${opt:stage, 'dev'}
region: ap-northeast-1
environment:
SELLER_QUEUE_NAME: ${self:provider.stage}-trader-queue
TOPIC_EMAIL_NAME: EmailNotification
NEWS_TRIGGER_DB_NAME: ${self:provider.stage}-news-trigger-db
NEWS_TRIGGER_DB_PK: key
SYMBOL_DB_NAME: symbol-dynamo
SYMBOL_DB_PK: symbol
TRANSACTION_DB_NAME: transaction
TRANSACTION_DB_PK: orderId
TRANSACTION_DB_SK: transactTime
PUBLISHING_DB_NAME: publishing
PUBLISHING_DB_PK: url
PUBLISHING_DB_SK: timestamp
iamRoleStatements:
- Effect: 'Allow'
Action:
- lambda:InvokeFunction
Resource: '*'
- Effect: 'Allow'
Action:
- sns:CreateTopic
- sns:Publish
Resource: '*'
- Effect: 'Allow'
Action:
- sqs:GetQueueAttributes
- sqs:ReceiveMessage
- sqs:DeleteMessage
- sqs:SendMessage
- sqs:GetQueueUrl
Resource:
- !GetAtt TradingQueue.Arn
- !GetAtt TradingQueueDLQ.Arn
- Effect: 'Allow'
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:PutItem
- dynamodb:GetItem
- dynamodb:DeleteItem
Resource:
- !GetAtt NewsTrigger.Arn
- !GetAtt SymbolDb.Arn
- !GetAtt TransactionDb.Arn
- !GetAtt PublishingDb.Arn
- Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:PutObject"
Resource:
- !Sub "arn:aws:s3:::${self:provider.environment.SYMBOL_DB_NAME}/*"
- !Sub "arn:aws:s3:::${self:provider.environment.SYMBOL_DB_NAME}"
custom:
logRetentionInDays: 3
# apiGatewayCaching:
# enabled: true
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
packager: 'npm' # Packager that will be used to package your external modules
prune:
automatic: true
number: 5 # Number of versions to keep
functions:
ApiView:
handler: src/api/view/handler.default
events:
- http:
path: view
method: get
ApiDashboard:
handler: src/api/dashboard/handler.default
events:
- http:
path: dashboard
method: get
# caching:
# enabled: true
# ttlInSeconds: 120
PopulateSymbols:
handler: src/functions/populateSymbols.default
description: Populate symbols in dynamo database
events:
- schedule: rate(1 day)
WatcherBinance:
handler: src/functions/watcher/handler.default
description: Watch Binance news and trigger trader if needed
events:
- http: GET watcher
Seller:
handler: src/functions/seller/handler.default
description: Buy and sell a symbol on Binance
timeout: 900 # 15 minutes
events:
- sqs:
arn: !GetAtt TradingQueue.Arn
batchSize: 1
resources:
Resources:
# SNS
EmailNotification:
Type: AWS::SNS::Topic
Properties:
DisplayName: Email Notification
TopicName: ${self:provider.environment.TOPIC_EMAIL_NAME}
Subscription:
- Protocol: email
Endpoint: rulliere.francois+kapochamo@gmail.com
- Protocol: email
Endpoint: paul_gaymard+kapochamo@hotmail.fr
# Queues
TradingQueue:
Type: AWS::SQS::Queue
Properties:
DelaySeconds: 0
MessageRetentionPeriod: 345600 # 4 days
QueueName: ${self:provider.environment.SELLER_QUEUE_NAME}
ReceiveMessageWaitTimeSeconds: 0
VisibilityTimeout: 900
RedrivePolicy:
deadLetterTargetArn: !GetAtt TradingQueueDLQ.Arn
maxReceiveCount: 1
DependsOn:
- TradingQueueDLQ
TradingQueueDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:provider.environment.SELLER_QUEUE_NAME}-DLQ
MessageRetentionPeriod: 1209600 # 14 days
# Databases
NewsTrigger:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.NEWS_TRIGGER_DB_NAME}
AttributeDefinitions:
- AttributeName: ${self:provider.environment.NEWS_TRIGGER_DB_PK}
AttributeType: S
KeySchema:
- AttributeName: ${self:provider.environment.NEWS_TRIGGER_DB_PK}
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
SymbolDb:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.SYMBOL_DB_NAME}
AttributeDefinitions:
- AttributeName: ${self:provider.environment.SYMBOL_DB_PK}
AttributeType: S
KeySchema:
- AttributeName: ${self:provider.environment.SYMBOL_DB_PK}
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
TransactionDb:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.TRANSACTION_DB_NAME}
AttributeDefinitions:
- AttributeName: ${self:provider.environment.TRANSACTION_DB_PK}
AttributeType: S
- AttributeName: ${self:provider.environment.TRANSACTION_DB_SK}
AttributeType: N
KeySchema:
- AttributeName: ${self:provider.environment.TRANSACTION_DB_PK}
KeyType: HASH
- AttributeName: ${self:provider.environment.TRANSACTION_DB_SK}
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
PublishingDb:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.PUBLISHING_DB_NAME}
AttributeDefinitions:
- AttributeName: ${self:provider.environment.PUBLISHING_DB_PK}
AttributeType: S
- AttributeName: ${self:provider.environment.PUBLISHING_DB_SK}
AttributeType: N
KeySchema:
- AttributeName: ${self:provider.environment.PUBLISHING_DB_PK}
KeyType: HASH
- AttributeName: ${self:provider.environment.PUBLISHING_DB_SK}
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
plugins:
- serverless-dotenv-plugin
- serverless-webpack
- serverless-prune-plugin
# - serverless-api-gateway-caching
- serverless-plugin-log-retention