-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserverless.yaml
180 lines (173 loc) · 4.47 KB
/
serverless.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
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
service: bargain
plugins:
- serverless-python-requirements
- serverless-wsgi
- serverless-dynamodb-local
custom:
bargainsTableName: bargains-table-${self:provider.stage}
productsTableName: bargains-products-table-${self:provider.stage}
subscriptionsTableName: bargain-subscriptions-table-${self:provider.stage}
queueName: bargains-queue-${self:provider.stage}
wsgi:
app: app.app
packRequirements: false
pythonRequirements:
dockerizePip: non-linux
dynamodb:
start:
migrate: true
stages:
- dev
provider:
name: aws
runtime: python3.8
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'ap-south-1'}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:Query
- dynamodb:Scan
Resource:
- Fn::GetAtt:
- BargainsDynamoDBTable
- Arn
- Fn::Join:
- ''
- - Fn::GetAtt:
- BargainsDynamoDBTable
- Arn
- '/index/*'
- Fn::GetAtt:
- SubscriptionsDynamoDBTable
- Arn
- Fn::GetAtt:
- ProductsDynamoDBTable
- Arn
- Effect: Allow
Action:
- sns:CreateTopic
- sns:Publish
- sns:Subscribe
Resource: '*'
- Effect: Allow
Action:
- sqs:SendMessage
- sqs:GetQueueUrl
Resource:
Fn::GetAtt:
- TasksQueue
- Arn
environment:
BARGAINS_TABLE: ${self:custom.bargainsTableName}
SUBSCRIPTIONS_TABLE: ${self:custom.subscriptionsTableName}
PRODUCTS_TABLE: ${self:custom.productsTableName}
QUEUE: ${self:custom.queueName}
functions:
app:
handler: wsgi_handler.handler
events:
- http:
path: /
method: ANY
cors: true
- http:
path: '{proxy+}'
method: ANY
cors: true
memorySize: 256
enqueue-tasks:
handler: app.enqueue_tasks
events:
- schedule: rate(30 minutes)
memorySize: 256
handle-task:
handler: app.handle_task
reservedConcurrency: 10
events:
- sqs:
batchSize: 1
arn:
Fn::GetAtt:
- TasksQueue
- Arn
memorySize: 256
resources:
Resources:
BargainsDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.bargainsTableName}
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
AttributeDefinitions:
- AttributeName: bargainId
AttributeType: S
- AttributeName: productUrl
AttributeType: S
- AttributeName: email
AttributeType: S
KeySchema:
- AttributeName: bargainId
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: emailIndex
KeySchema:
- AttributeName: email
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
Projection:
ProjectionType: ALL
- IndexName: productUrlIndex
KeySchema:
- AttributeName: productUrl
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
Projection:
ProjectionType: ALL
SubscriptionsDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.subscriptionsTableName}
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
AttributeDefinitions:
- AttributeName: email
AttributeType: S
KeySchema:
- AttributeName: email
KeyType: HASH
TasksQueue:
Type: 'AWS::SQS::Queue'
Properties:
QueueName: ${self:custom.queueName}
ProductsDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.productsTableName}
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
AttributeDefinitions:
- AttributeName: productUrl
AttributeType: S
KeySchema:
- AttributeName: productUrl
KeyType: HASH
package:
exclude:
- node_modules/**
- venv/**
- .idea/**
- __pycache__/**
- .dynamodb/**