-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
114 lines (100 loc) · 2.7 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
service: capstone-image-storage
plugins:
- serverless-iam-roles-per-function
- serverless-plugin-tracing
provider:
name: aws
runtime: go1.x
lambdaHashingVersion: 20201221
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'us-east-1'}
tracing:
lambda: true
apiGateway: true
environment:
IMAGE_S3_BUCKET: capstone-image-storage-981561515630-${self:provider.stage}
SIGNED_URL_EXPIRATION: 300
AUTH_API_ID: https://udacity.luoma.dev
AUTH_API_DOMAIN: dev-sz67ap41.us.auth0.com
logs:
# Enable API Gateway logs
restApi: true
httpApi:
authorizers:
auth:
type: request
functionName: auth
iam:
role:
statements:
- Effect: Allow
Action:
- xray:PutTelemetryRecords
- xray:PutTraceSegments
Resource: "*"
package:
exclude:
- ./**
include:
- ./gobin/**
functions:
auth:
handler: gobin/auth
create-image-url:
handler: gobin/image
events:
- http:
path: /images/{id}
method: post
cors: true
authorizer:
name: auth
iamRoleStatements:
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
Resource: arn:aws:s3:::${self:provider.environment.IMAGE_S3_BUCKET}/*
resources:
Resources:
GatewayResponseDefault4XX:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
gatewayresponse.header.Access-Control-Allow-Methods: "'GET,OPTIONS,POST'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: ApiGatewayRestApi
ImageBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:provider.environment.IMAGE_S3_BUCKET}
CorsConfiguration:
CorsRules:
-
AllowedOrigins:
- '*'
AllowedHeaders:
- '*'
AllowedMethods:
- GET
- PUT
- POST
- DELETE
- HEAD
MaxAge: 3000
BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
PolicyDocument:
Id: ImageBucketPolicy
Version: "2012-10-17"
Statement:
- Sid: PublicReadForGetBucketObjects
Effect: Allow
Principal: '*'
Action: 's3:GetObject'
Resource: 'arn:aws:s3:::${self:provider.environment.IMAGE_S3_BUCKET}/*'
Bucket: !Ref ImageBucket