-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
130 lines (116 loc) · 3.74 KB
/
serverless.yml
File metadata and controls
130 lines (116 loc) · 3.74 KB
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
service: ${self:custom.config.BASE_NAME}
provider:
name: aws
runtime: nodejs14.x # set Node.js runtime
stage: ${opt:stage}
stackName: ${self:service}
region: ${self:custom.config.REGION}
#memorySize: 128 # set the maximum memory of the Lambdas in Megabytes
#timeout: 10 # the timeout is 10 seconds (default is 6 seconds)
logRetentionInDays: 7 # log keep only 7 days
lambdaHashingVersion: 20201221 # for upcoming Serverless v3
stackTags:
stage: ${opt:stage}
application: ${self:custom.config.TAG}
service: "middleware"
custom:
config: ${file(config-${opt:stage}.yml)}
functions: # add 4 functions for CRUD
generalAuthorizer:
environment:
${file(config-${opt:stage}.yml)}
handler: api/login/verify_token.auth
resources:
Description: Test Root stack
Resources:
BucketUpload:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
CorsConfiguration:
CorsRules:
- AllowedMethods:
- GET
- PUT
- POST
- HEAD
AllowedOrigins:
- "*"
AllowedHeaders:
- "*"
BucketName: ${self:custom.config.S3_BUCKET_NAME}
ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
BinaryMediaTypes:
- 'image/gif'
- 'image/png'
- 'image/jpeg'
- 'image/jpg'
- 'multipart/form-data'
Name: ${self:custom.config.BASE_NAME}-${opt:stage}-api
GatewayResponseDefault4XX:
Type: "AWS::ApiGateway::GatewayResponse"
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId: {"Ref" : "ApiGatewayRestApi"}
GatewayResponseDefault5XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId:
Ref: 'ApiGatewayRestApi'
# Authorizer
ApiGatewayAuthorizerPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Fn::GetAtt: GeneralAuthorizerLambdaFunction.Arn
Action: lambda:InvokeFunction
Principal:
Fn::Join: ["",["apigateway.", { Ref: "AWS::URLSuffix"}]]
ApiGatewayAuthorizer:
DependsOn:
- ApiGatewayRestApi
Type: AWS::ApiGateway::Authorizer
Properties:
Name: ${self:custom.config.BASE_NAME}-${opt:stage}-Authorizer
RestApiId: { "Ref" : "ApiGatewayRestApi" }
Type: TOKEN
IdentitySource: method.request.header.Authorization
AuthorizerResultTtlInSeconds: 0
AuthorizerUri:
Fn::Join:
- ''
-
- 'arn:aws:apigateway:'
- Ref: "AWS::Region"
- ':lambda:path/2015-03-31/functions/'
- Fn::GetAtt: "GeneralAuthorizerLambdaFunction.Arn"
- "/invocations"
Outputs:
ApiGatewayAuthorizerId:
Value:
Ref: ApiGatewayAuthorizer
Export:
Name: ${self:custom.config.BASE_NAME}-${opt:stage}-ApiGatewayAuthorizerId
apiGatewayRestApiId:
Value:
Ref: ApiGatewayRestApi
Export:
Name: ${self:custom.config.BASE_NAME}-${opt:stage}-restApiId
apiGatewayRestApiRootResourceId:
Value:
Fn::GetAtt:
- ApiGatewayRestApi
- RootResourceId
Export:
Name: ${self:custom.config.BASE_NAME}-${opt:stage}-rootResourceId
plugins:
- serverless-offline # adding the plugin to be able to run the offline emulation