-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserverless.yml
102 lines (102 loc) · 3.53 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
service: serverless-documentation
variablesResolutionMode: 20210326
provider:
name: aws
runtime: nodejs14.x
lambdaHashingVersion: 20201221
memorySize: 256
stage: ${opt:stage, 'develop'}
region: ${opt:region, 'eu-west-1'}
# these will be environment variables in your lambda handlers
environment:
BUCKET_NAME: ${self:custom.imagesBucket}
STAGE: ${opt:stage, self:provider.stage}
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
apiGateway:
shouldStartNameWithService: true
# this iam role will be applied to all lambdas. best practice is to have a role specific to
# each lamda for least privilage security
iam:
role:
statements:
- Effect: "Allow"
Action:
- "s3:ListObjects"
- "s3:GetObject"
- "s3:PutObject"
Resource:
- "arn:aws:s3:::${self:custom.imagesBucket}"
- "arn:aws:s3:::${self:custom.imagesBucket}/*"
# serverless plugins
plugins:
- serverless-webpack
- serverless-s3-sync
- serverless-openapi-documentation-v2
package:
individually: true
functions:
# function to get an image using a pre-signed download url
get-image:
handler: src/functions/images/get-image/get-image.handler
timeout: 10
events:
- http:
path: images/{id} # for this demo it only works with png images for simplicity
method: get
documentation: ${file(serverless.doc.yml):documentation.endpoints.getImage}
# function to upload an image
upload-image:
handler: src/functions/images/upload-image/upload-image.handler
timeout: 10
events:
- http:
path: images/{id} # for this demo it only works with png images for simplicity
method: put
documentation: ${file(serverless.doc.yml):documentation.endpoints.uploadImage}
custom:
imagesBucket: s3-images-${self:provider.stage}
docsBucket: s3-documentation-${self:provider.stage}
openapiBucket: s3-openapi-${self:provider.stage}
openapiTitle: serverless-documentation-${self:provider.stage}
# serverless documentation plugin configuration stored in a separate file
documentation: ${file(serverless.doc.yml):documentation}
# this is the config for the s3sync plugin which will move all assets from src/assets into the s3 bucket
s3Sync:
- bucketName: ${self:custom.docsBucket} # sync the code documentation to s3
localDir: docs/documentation
acl: public-read
- bucketName: ${self:custom.openapiBucket} # sync the openapi documentation to s3
localDir: docs/openapi
acl: public-read
- bucketName: ${self:custom.imagesBucket} # push the example 1.png file to the images s3 bucket
localDir: src/assets
acl: private
# this is the webpack config for the build
webpack:
webpackConfig: "webpack.config.js"
includeModules:
forceExclude:
- aws-sdk
resources:
Resources:
# this is the private images s3 bucket
AssetsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.imagesBucket}
# this is the documentation s3 bucket which is publicly accessible
DocsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.docsBucket}
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
# this is the openapi s3 bucket which is publicly accessible
OpenAPIBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.openapiBucket}
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html