-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_function.py
39 lines (34 loc) · 993 Bytes
/
lambda_function.py
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
import re
def lambda_handler(event, context):
request = event['Records'][0]['cf']['request']
uri = request['uri']
if re.match('.+/$', uri):
request['uri'] = uri + "index.html"
return request
elif re.match('(.+)/index.html', uri):
prefix_path = re.search('(.+)/index.html', uri)
response = {
'status': '301',
'statusDescription': 'Found',
'headers': {
'location': [{
'key': 'Location',
'value': prefix_path[1] + '/'
}]
}
}
return response
elif re.search('\/[^\/\.]+$', uri):
response = {
'status': '301',
'statusDescription': 'Found',
'headers': {
'location': [{
'key': 'Location',
'value': uri + '/'
}]
}
}
return response
else:
return request