-
Notifications
You must be signed in to change notification settings - Fork 4
/
serverless.yml
161 lines (152 loc) · 5.24 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
service:
name: uptime
custom:
uptime:
prefix: ${self:service}-${self:provider.stage}
privacy: ${opt:privacy, 'public'}
vpc: ${opt:vpc, ''}
permissionsBoundary: ${opt:permissionsBoundary, ''}
deletionPolicy:
dev: Delete
prod: Retain
storageBucket:
deletionPolicy: ${self:custom.uptime.deletionPolicy.${self:provider.stage}}
servicesTable:
name: ${self:custom.uptime.prefix}-services
throughput: 5
deletionPolicy: ${self:custom.uptime.deletionPolicy.${self:provider.stage}}
metricsTable:
name: ${self:custom.uptime.prefix}-metrics
throughput: 5
deletionPolicy: ${self:custom.uptime.deletionPolicy.${self:provider.stage}}
webpack:
webpackConfig: ./src/app/webpack.config.js
keepOutputDirectory: true
assets:
targets:
- bucket:
Ref: S3WebsiteBucket
acl: public-read
files:
- source: ./dist/
globs: '**/*.*'
empty: true
frameworkVersion: ">=1.47.0 <2.0.0"
plugins:
- serverless-webpack
- serverless-export-env
- serverless-s3-deploy
- serverless-attach-managed-policy
- serverless-offline
provider:
name: aws
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'us-east-1'}
runtime: nodejs10.x
environment:
SERVICES_TABLE: ${self:custom.uptime.servicesTable.name}
METRICS_TABLE: ${self:custom.uptime.metricsTable.name}
PINGER_LOG_GROUP: /aws/lambda/${self:custom.uptime.prefix}-pinger
STORAGE_BUCKET: { "Ref": "S3StorageBucket" }
API_URL: { "Fn::Join" : [ "", [ "https://", { "Ref" : "ApiGatewayRestApi" }, ".execute-api.${self:provider.region}.amazonaws.com/${self:provider.stage}" ] ] }
managedPolicyArns: ${self:custom.uptime.permissionsBoundary}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:BatchWriteItem
Resource:
- "Fn::GetAtt": [ ServicesTable, Arn ]
- "Fn::GetAtt": [ MetricsTable, Arn ]
- Effect: Allow
Action:
- logs:DescribeLogStreams
- logs:GetLogEvents
Resource:
- "arn:aws:logs:*:*:log-group:/aws/lambda/${self:custom.uptime.prefix}-pinger:log-stream:*"
- Effect: Allow
Action:
- s3:ListBucket
Resource:
- "Fn::GetAtt": [ S3StorageBucket, Arn ]
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
Resource:
- "Fn::Join": [ "", [ { "Fn::GetAtt": [ S3StorageBucket, Arn ] }, "/*" ] ]
functions:
api:
handler: src/app/api.handler
memorySize: 256
timeout: 6
events:
- http:
path: / # this matches the base path
method: ANY
cors: true
- http:
path: /{any+} # this matches any path, the token 'any' doesn't mean anything special
method: ANY
cors: true
pinger:
handler: src/app/pinger.handler
memorySize: 256
timeout: 45
events:
- schedule:
name: ${self:custom.uptime.prefix}-scheduled-pinger-1-minute
description: 'The uptime pinger, which runs checks on a schedule (1 minute)'
rate: cron(* * * * ? *)
inputTransformer:
inputPathsMap:
eventId: '$.id'
eventTime: '$.time'
inputTemplate: '{"id": <eventId>, "time": <eventTime>, "rate": "1 minute"}'
- schedule:
name: ${self:custom.uptime.prefix}-scheduled-pinger-5-minutes
description: 'The uptime pinger, which runs checks on a schedule (5 minutes)'
rate: cron(0/5 * * * ? *)
inputTransformer:
inputPathsMap:
eventId: '$.id'
eventTime: '$.time'
inputTemplate: '{"id": <eventId>, "time": <eventTime>, "rate": "5 minutes"}'
- schedule:
name: ${self:custom.uptime.prefix}-scheduled-pinger-15-minutes
description: 'The uptime pinger, which runs checks on a schedule (15 minutes)'
rate: cron(0/15 * * * ? *)
inputTransformer:
inputPathsMap:
eventId: '$.id'
eventTime: '$.time'
inputTemplate: '{"id": <eventId>, "time": <eventTime>, "rate": "15 minutes"}'
- schedule:
name: ${self:custom.uptime.prefix}-scheduled-pinger-30-minutes
description: 'The uptime pinger, which runs checks on a schedule (30 minutes)'
rate: cron(0/30 * * * ? *)
inputTransformer:
inputPathsMap:
eventId: '$.id'
eventTime: '$.time'
inputTemplate: '{"id": <eventId>, "time": <eventTime>, "rate": "30 minutes"}'
- schedule:
name: ${self:custom.uptime.prefix}-scheduled-pinger-1-hour
description: 'The uptime pinger, which runs checks on a schedule (1 hour)'
rate: cron(0 * * * ? *)
inputTransformer:
inputPathsMap:
eventId: '$.id'
eventTime: '$.time'
inputTemplate: '{"id": <eventId>, "time": <eventTime>, "rate": "1 hour"}'
package:
individually: true
resources:
- ${file(src/aws/s3-${self:custom.uptime.privacy}.yml)}
- ${file(src/aws/s3-storage.yml)}
- ${file(src/aws/dynamodb.yml)}