-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_lambda.py
40 lines (32 loc) · 863 Bytes
/
aws_lambda.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
40
"""Interface for AWS Lambda endpoints.
Handles HTTP request parameter parsing and creation of responses.
"""
import json
from dns_verify import valid_cname
def validate_cname(event, context):
"""Handle the Lambda call and check the CNAME validity."""
data = json.loads(event['body'])
try:
fqdn = data['fqdn']
valid_domains = data['valid-domains']
except KeyError:
return KEY_ERROR_RESULT
is_valid, cnames = valid_cname(fqdn, valid_domains)
body = json.dumps({
'success': {
'is-valid': is_valid,
'cnames': cnames,
}
})
return {
"statusCode": 200,
"body": body,
}
KEY_ERROR_RESULT = {
"statusCode": 400,
"body": json.dumps({
'error': {
'message': 'must post `fqdn` and `valid-domains` params'
}
}),
}