-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhandler.py
More file actions
44 lines (35 loc) · 1.36 KB
/
handler.py
File metadata and controls
44 lines (35 loc) · 1.36 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
import sys
import os
sys.path.append(f"{os.environ['LAMBDA_TASK_ROOT']}/lib")
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
import cr_response
from logic import WafRateLimit
import json
def lambda_handler(event, context):
print(f"Received event:{json.dumps(event)}")
lambda_response = cr_response.CustomResourceResponse(event)
cr_params = event['ResourceProperties']
waf_logic = WafRateLimit(cr_params)
try:
# if create request, generate physical id, both for create/update copy files
if event['RequestType'] == 'Create':
event['PhysicalResourceId'] = waf_logic._create_rate_based_rule()
data = {
"RuleID" : event['PhysicalResourceId']
}
lambda_response.respond(data)
elif event['RequestType'] == 'Update':
waf_logic._update_rate_based_rule(event['PhysicalResourceId'])
data = {
"RuleID" : event['PhysicalResourceId']
}
lambda_response.respond(data)
elif event['RequestType'] == 'Delete':
print(event['PhysicalResourceId'])
waf_logic._delete_rate_based_rule(event['PhysicalResourceId'])
data = { }
lambda_response.respond(data)
except Exception as e:
message = str(e)
lambda_response.respond_error(message)
return 'OK'