Godaddy - Python - AWS Lambda
Lambda Code to Add, Update, Get and Delete Records in Godaddy
import json
import boto3
#Get Godaddy API Keys
#https://developer.godaddy.com/keys/
#Python Godaddy Library
#https://pypi.org/project/GoDaddyPy/
from godaddypy import Client, Account
def lambda_handler(event, context):
print("event", event)
try:
response_body = {"isBase64Encoded": False,
"statusCode": 200,
"headers": {'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*',
'Accept': 'application/json'},
"body": json.dumps("An exception occured in the lambda interface.")
}
checkSource = event.get('httpMethod', False)
if (checkSource):
event_body = json.loads(event['body'])
else:
event_body = event
getAction = event_body['action']
if (getAction == 'updaterecord'):
getdomain = event_body['domain']
getname = event_body['name']
getvalue = event_body['value']
gettype = event_body['type']
userAccount = Account(api_key='access key ', api_secret='secret key ')
userClient = Client(userAccount)
value = getvalue
domain = getdomain
name = getname
type = gettype
updateResult = userClient.update_record_ip(value, domain, name, type)
print(updateResult)
if updateResult is True:
response_body['body'] = json.dumps({"status": "SUCCESS", "result": "Record Updated Successfully."})
else:
response_body['body'] = json.dumps({"status": "FAIL", "result": "Error occoured while Updating Record."})
if (getAction == 'addrecord'):
getdomain = event_body['domain']
getname = event_body['name']
getvalue = event_body['value']
gettype = event_body['type']
userAccount = Account(api_key='access key ', api_secret='secret key ')
userClient = Client(userAccount)
value = getvalue
domain = getdomain
name = getname
type = gettype
updateResult = userClient.add_record(domain, {'data':value,'name':name,'ttl':3600, 'type':type}) #update_record_ip(value, domain, name, type)
print(updateResult)
if updateResult is True:
response_body['body'] = json.dumps({"status": "SUCCESS", "result": "Record Added Successfully."})
else:
response_body['body'] = json.dumps({"status": "FAIL", "result": "Error occoured while Adding Record."})
if (getAction == 'deleterecord'):
getdomain = event_body['domain']
getname = event_body['name']
userAccount = Account(api_key='access key ', api_secret='secret key ')
userClient = Client(userAccount)
domain = getdomain
name = getname
updateResult = userClient.delete_records(domain, name)
print(updateResult)
if updateResult is True:
response_body['body'] = json.dumps({"status": "SUCCESS", "result": "Record Deleted Successfully."})
else:
response_body['body'] = json.dumps({"status": "FAIL", "result": "Error occoured while Deleting Record."})
if (getAction == 'getrecord'):
getdomain = event_body['domain']
userAccount = Account(api_key='access key ', api_secret='secret key ')
userClient = Client(userAccount)
domain = getdomain
updateResult = userClient.get_records(domain)
print(updateResult)
#if updateResult is True:
response_body['body'] = json.dumps(updateResult)
#else:
#response_body['body'] = json.dumps({"status": "FAIL", "result": "Error occoured while Listing Records."})
except Exception as e:
error_message = str(e)
print(error_message)
response_body['body'] = json.dumps({"status": "FAIL", "result": error_message})
return response_body
Input Parameters
ADD Record into Godaddy
{
"action": "addrecord",
"domain": "kishoreweb.com",
"name": "admin",
"value": "11.22.33.44",
"type": "A"
}
List Records from Godaddy
{
"action": "getrecord",
"domain": "kishoreweb.com"
}
DELETE Record on Godaddy
{
"action": "deleterecord",
"domain": "kishoreweb.com",
"name": "admin"
}
UPDATE Record on Godaddy
{
"action": "updaterecord",
"domain": "kishoreweb.com",
"name": "admin",
"value": "11.22.33.48",
"type": "A"
}