-
Notifications
You must be signed in to change notification settings - Fork 3
/
serverless.yml
85 lines (79 loc) · 2.33 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
service: upload-to-s3-with-signedUrl
frameworkVersion: "2"
# Specify your bucket name here
custom:
bucketName: ### define the unique bucket name to be created - just lowercase
stage: ${opt:stage, self:provider.stage}
region: ${opt:region, self:provider.region}
provider:
name: aws
runtime: nodejs14.x
stage: dev # change the stage if you want
region: us-east-1 # change the region if you want
lambdaHashingVersion: 20201221
stackName: ${self:custom.bucketName}
apiName: ${self:custom.bucketName}
endpointType: regional
memorySize: 128
iam: #permisions for lambda access the s3 actions
role:
statements:
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:PutObjectAcl
Resource:
- arn:aws:s3:::${self:custom.bucketName}/*
Sid: AllowPublic
package: #exclude frontend folder and files on deploy
patterns:
- '!frontend/**'
functions: # lambda function
upload:
handler: index.handler
name: ${self:custom.bucketName}
environment:
UploadBucket: ${self:custom.bucketName}
events:
- http: # create a api gateway to trigger de lambda function
path: /${self:custom.bucketName}
method: get
cors: true
resources:
Resources:
UploadBucket: # create a s3 bucket
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.bucketName}
AccessControl: PublicRead
CorsConfiguration: # define cors
CorsRules:
- AllowedHeaders:
- "*"
AllowedMethods:
- GET
- HEAD
- PUT
- POST
- DELETE
AllowedOrigins:
- "*"
UploadBucketPolicy: # define policy to bucket and objects
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: UploadBucket
PolicyDocument:
Statement:
- Effect: "Allow"
Action:
- s3:GetObject # defined public access only to get the objects on the bucket.
Principal: "*"
Sid: PublicGetObject
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::"
- "Ref": UploadBucket
- "/*"