-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
229 lines (223 loc) · 5.92 KB
/
serverless.yml
File metadata and controls
229 lines (223 loc) · 5.92 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: serverless-blog-api
plugins:
- serverless-reqvalidator-plugin
- serverless-aws-documentation
provider:
name: aws
runtime: python3.7
region: ap-northeast-1
iamRoleStatements:
- Effect: "Allow"
Action:
- "dynamodb:*"
Resource:
- 'Fn::Join':
- ':'
-
- 'arn:aws:dynamodb'
- ${self:provider.region}
- Ref: 'AWS::AccountId'
- 'table/*'
custom:
documentation:
api:
info:
version: '1.0.0'
title: My API
description: This is my API
tags:
-
name: User
description: User Management
models:
- name: articleModel
contentType: "application/json"
schema: ${file(model/article.json)}
functions:
getArticle:
handler: handlers/article.get_article_handler
name: getArticle
memorySize: 1024
timeout: 300
events:
- http:
path: /article/{title}
method: get
integration: lambda-proxy
cors:
origin: '*'
headers:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- Pragma
- Cache-Control
- If-Modified-Since
allowCredentials: true
request:
parameters:
paths:
title: true
postArticle:
handler: handlers/article.put_article_handler
name: postArticle
memorySize: 1024
timeout: 300
events:
- http:
path: /article/{title}
method: post
integration: lambda-proxy
reqValidatorName: 'onlyBody'
cors:
origin: '*'
headers:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- Pragma
- Cache-Control
- If-Modified-Since
allowCredentials: true
request:
parameters:
paths:
title: true
documentation:
summary: "Post a article"
description: "Post a article"
requestModels:
"application/json": "articleModel"
deleteArticle:
handler: handlers/article.delete_article_handler
name: deleteArticle
memorySize: 1024
timeout: 300
events:
- http:
path: /article/{title}
method: delete
integration: lambda-proxy
cors:
origin: '*'
headers:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- Pragma
- Cache-Control
- If-Modified-Since
allowCredentials: true
request:
parameters:
paths:
title: true
latestArticle:
handler: handlers/article.get_latest_article_handler
name: getLatestArticle
memorySize: 1024
timeout: 300
events:
- http:
path: /latestArticle
method: get
integration: lambda-proxy
cors:
origin: '*'
headers:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- Pragma
- Cache-Control
- If-Modified-Since
allowCredentials: true
request:
parameters:
paths:
title: true
# you can add CloudFormation resource templates here
resources:
Resources:
# APIG
ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: ${self:service}-api-${self:provider.stage}
# APIG Request Validation
onlyBody:
Type: "AWS::ApiGateway::RequestValidator"
Properties:
Name: 'only-body'
RestApiId:
Ref: ApiGatewayRestApi
ValidateRequestBody: true
ValidateRequestParameters: false
bothParams:
Type: "AWS::ApiGateway::RequestValidator"
Properties:
Name: 'both-params'
RestApiId:
Ref: ApiGatewayRestApi
ValidateRequestBody: true
ValidateRequestParameters: true
onlyReqParams:
Type: "AWS::ApiGateway::RequestValidator"
Properties:
Name: 'only-req-params'
RestApiId:
Ref: ApiGatewayRestApi
ValidateRequestBody: false
ValidateRequestParameters: true
PostTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: postObject
AttributeDefinitions:
- AttributeName: postCategory
AttributeType: S
- AttributeName: uri
AttributeType: S
- AttributeName: createdAt
AttributeType: N
KeySchema:
- AttributeName: postCategory
KeyType: HASH
- AttributeName: uri
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
LocalSecondaryIndexes:
- IndexName: postCategory-createdAt-index
KeySchema:
- AttributeName: postCategory
KeyType: HASH
- AttributeName: createdAt
KeyType: RANGE
Projection:
ProjectionType: ALL