-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
287 lines (287 loc) · 7.82 KB
/
template.yaml
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: SURL - ShortURL
Globals:
Function:
Timeout: 25
Environment:
Variables:
TABLE_NAME_LINKS: surl_links
ROOT_REDIRECT: 'https://example.com/'
404_REDIRECT: 'https://example.com/'
BASE_DOMAIN: 'https://example.com/'
CACHE_SECONDS: 300
Resources:
LinksTable:
Type: 'AWS::DynamoDB::Table'
TableName: surl_links
AttributeDefintions:
- AttributeName: niceName
AttributeType: S
PrimaryKey:
- Name: niceName
Type: String
KeySchema:
- AttributeName: niceName
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
SSESpecification:
SSEEnabled: false
Metadata:
'AWS::CloudFormation::Designer':
id: 20f3d16e-6d1a-4179-9ff4-35c574c0e7ac
RedirectFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: redirect/target/aws-redirect-lambda-package.zip
Handler: 'com.blakekhan.surl.aws.redirect.App::handleRequest'
Runtime: java11
MemorySize: 512
FunctionName: surl-redirect
Description: Handles redirection of clients.
Events:
SurlAPI:
Type: Api
Properties:
Path: '/{niceName}'
Method: get
RequestModel:
Model: RedirectRequest
Required: true
RequestParameters:
- method.request.path.niceName:
Required: true
EndpointConfiguration: EDGE
Policies:
- Version: 1012-10-17
Statement:
- Effect: Allow
Action:
- 'dynamodb:DeleteItem'
- 'dynamodb:GetItem'
- 'dynamodb:PutItem'
- 'dynamodb:UpdateItem'
Resource: !Join
- ''
- - 'arn:aws:dynamodb:'
- !Ref 'AWS::Region'
- ':'
- !Ref 'AWS::AccountId'
- ':table/surl_links'
Metadata:
'AWS::CloudFormation::Designer':
id: 73563d77-2c0e-4879-8b7c-d4fa88dc3f25
DependsOn:
- LinksTable
DeleteLinkFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: delete-link/target/aws-deletelink-lambda-package.zip
Handler: 'com.blakekhan.surl.aws.delete.App::handleRequest'
Runtime: java11
MemorySize: 512
FunctionName: surl-redirect
Description: Handles deletion of short link.
Events:
SurlAPI:
Type: Api
Properties:
Path: '/{niceName}'
Method: delete
RequestModel:
Model: DeleteRequest
Required: true
RequestParameters:
- method.request.path.niceName:
Required: true
EndpointConfiguration: EDGE
Policies:
- Version: 1012-10-17
Statement:
- Effect: Allow
Action:
- 'dynamodb:DeleteItem'
- 'dynamodb:GetItem'
- 'dynamodb:PutItem'
Resource: !Join
- ''
- - 'arn:aws:dynamodb:'
- !Ref 'AWS::Region'
- ':'
- !Ref 'AWS::AccountId'
- ':table/surl_links'
DependsOn:
- LinksTable
Metadata:
'AWS::CloudFormation::Designer':
id: fffc4832-172c-4816-8162-83cb25840dc6
CreateLinkFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: create-link/target/aws-createlink-lambda-package.zip
Handler: 'com.blakekhan.surl.aws.create.App::handleRequest'
Runtime: java11
MemorySize: 512
FunctionName: surl-createlink
Description: Handles creation of new short links.
Events:
SurlAPI:
Type: Api
Properties:
Path: /create
Method: put
RequestParameters:
- method.request.header.niceName:
Required: true
- method.request.header.destination:
Required: true
- method.request.header.expireAt:
Required: false
RequestModel:
Model: CreateLinkRequest
Required: true
EndpointConfiguration: EDGE
Policies:
- Version: 1012-10-17
Statement:
- Effect: Allow
Action:
- 'dynamodb:DeleteItem'
- 'dynamodb:GetItem'
- 'dynamodb:PutItem'
- 'dynamodb:UpdateItem'
Resource: !Join
- ''
- - 'arn:aws:dynamodb:'
- !Ref 'AWS::Region'
- ':'
- !Ref 'AWS::AccountId'
- ':table/surl_links'
Metadata:
'AWS::CloudFormation::Designer':
id: 591d1a78-526e-424a-a3d1-d4ce558c1389
DependsOn:
- LinksTable
SurlAPI:
Type: 'AWS::ApiGateway::Model'
Properties:
RestApiId: !Ref SurlAPI
ContentType: application/json
Description: Schema for redirect request
Name: CreateLinkRequest
Schema:
$schema: 'http://json-schema.org/draft-04/schema#'
title: CreateLinkRequest
type: array
items:
type: object
properties:
niceName:
type: string
destination:
type: string
expireAt:
type: string
Metadata:
'AWS::CloudFormation::Designer':
id: 229057c4-ee71-425b-8507-4be7b548762e
DependsOn:
- RedirectFunction
- CreateLinkFunction
- DeleteLinkFunction
Outputs:
RedirectFunction:
Description: Redirect Lambda Function ARN
Value: !GetAtt
- RedirectFunction
- Arn
RedirectFunctionIamRole:
Description: Implicit IAM Role created for Redirect function
Value: !GetAtt
- RedirectFunctionRole
- Arn
CreateLinkFunction:
Description: CreateLink Lambda Function ARN
Value: !GetAtt
- CreateLinkFunction
- Arn
CreateLinkFunctionIamRole:
Description: Implicit IAM Role created for CreateLink function
Value: !GetAtt
- CreateLinkFunctionRole
- Arn
DeleteLinkFunction:
Description: DeleteLink Lambda Function ARN
Value: !GetAtt
- DeleteLinkFunction
- Arn
DeleteLinkFunctionIamRole:
Description: Implicit IAM Role created for DeleteLink function
Value: !GetAtt
- DeleteLinkFunctionRole
- Arn
Metadata:
'AWS::CloudFormation::Designer':
229057c4-ee71-425b-8507-4be7b548762e:
size:
width: 60
height: 60
position:
x: -10
'y': 100
z: 1
embeds: []
dependson:
- 73563d77-2c0e-4879-8b7c-d4fa88dc3f25
- 591d1a78-526e-424a-a3d1-d4ce558c1389
- fffc4832-172c-4816-8162-83cb25840dc6
591d1a78-526e-424a-a3d1-d4ce558c1389:
size:
width: 60
height: 60
position:
x: -150
'y': 20
z: 1
embeds: []
dependson:
- 20f3d16e-6d1a-4179-9ff4-35c574c0e7ac
73563d77-2c0e-4879-8b7c-d4fa88dc3f25:
size:
width: 60
height: 60
position:
x: -150
'y': 100
z: 1
embeds: []
dependson:
- 20f3d16e-6d1a-4179-9ff4-35c574c0e7ac
20f3d16e-6d1a-4179-9ff4-35c574c0e7ac:
size:
width: 60
height: 60
position:
x: -280
'y': 100
z: 1
embeds: []
fffc4832-172c-4816-8162-83cb25840dc6:
size:
width: 60
height: 60
position:
x: -150
'y': 180
z: 1
embeds: []
dependson:
- 20f3d16e-6d1a-4179-9ff4-35c574c0e7ac
8a7dd852-2cb5-4675-9609-52699a4b94cc:
source:
id: 229057c4-ee71-425b-8507-4be7b548762e
target:
id: fffc4832-172c-4816-8162-83cb25840dc6
z: 2