-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yaml
115 lines (102 loc) · 2.59 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
service: image-resizer
plugins:
- serverless-plugin-aws-alerts
- serverless-apigw-binary
- serverless-prune-plugin
- serverless-offline
- serverless-plugin-existing-s3
custom:
prune:
automatic: true
number: 5
bucket: medias.serverless-resizer.com
dynamoTable: serverlessImages
mimeTypes:
- 'image/jpeg'
- 'image/png'
- 'image/webp'
# Supported mime types for responses
apigwBinary:
types: ${self:custom.mimeTypes}
# CloudWatch alerts.
# ⚠️ You need to subscribe manually to the SNS topic in order to be notified
alerts:
stages:
- production
dashboards: false
topics:
alarm: serverless-resizer-alerts-alarm
alarms:
- functionErrors
- functionDuration
definitions:
functionErrors:
period: 300
treatMissingData: notBreaching
functionDuration:
period: 300
threshold: 30000 # 30 seconds
treatMissingData: notBreaching
package:
include:
- src/**
- node_modules/**
provider:
name: aws
endpointType: REGIONAL # This prevents the API Gateway to be deployed with a predefined CloudFront distro
runtime: nodejs8.10
profile: serverless-resizer
memorySize: 512
timeout: 30
logRetentionInDays: 7
environment:
STAGE: ${opt:stage, 'production'}
NODE_ENV: ${opt:stage, 'production'}
BUCKET: ${self:custom.bucket}
MIME_TYPES: ${file(./mime-types.js):mimeTypes}
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:ListBucket"
Resource:
- "arn:aws:s3:::${self:custom.bucket}"
- Effect: "Allow"
Action:
- "s3:ListObjects"
- "s3:Get*"
- "s3:PutObject*"
Resource:
- "arn:aws:s3:::${self:custom.bucket}/*"
- Effect: "Allow"
Action:
- "dynamodb:Scan"
- "dynamodb:PutItem"
Resource:
- "arn:aws:dynamodb:${opt:region, 'eu-west-1'}:805382315593:table/${self:custom.dynamoTable}"
- "arn:aws:dynamodb:${opt:region, 'eu-west-1'}:805382315593:table/${self:custom.dynamoTable}/*"
functions:
worker:
handler: src/worker.handler
events:
- existingS3:
bucket: ${self:custom.bucket}
events:
- s3:ObjectCreated:*
rules:
- prefix: images/
api:
handler: src/server.handler
events:
- http:
path: /
method: GET
- http:
path: /{any+}
method: ANY
request:
parameters:
querystrings:
width: true
height: true
toWebp: true
thumbnail: true