Views: 12065
The following script looks just up my alley, as I am working on a python script to automate setting up servers around the world so that clients get served from a local server.
import
boto3
client = boto3.client(
'route53'
, aws_access_key_id=
"AWS_KEY"
, aws_secret_access_key=
"AWS_SEC_KEY"
)
hostedZoneId =
'HOSTED_ZONE_ID'
ip=
'123.123.123.123'
if
aws_region ==
"US"
:
#US is my default region. So cont_code is blank
cont_code = {}
elif
aws_region ==
"EU"
:
cont_code = {
'ContinentCode'
:
'EU'
}
elif
aws_region ==
"AP"
:
cont_code = {
'ContinentCode'
:
'AS'
}
response = client.change_resource_record_sets(
HostedZoneId = hostedZoneId,
ChangeBatch={
'Comment'
:
'comment'
,
'Changes'
: [
{
'Action'
:
'CREATE'
,
'ResourceRecordSet'
: {
'Name'
: domain,
'Type'
:
'A'
,
'SetIdentifier'
:
'my_a_record'
,
'GeoLocation'
: cont_code,
'TTL'
: 60,
'ResourceRecords'
: [
{
'Value'
: ip
},
],
}
},
]
}
)
print(
"DNS record status %s "
% response[
'ChangeInfo'
][
'Status'
])
print(
"DNS record response code %s "
% response[
'ResponseMetadata'
][
'HTTPStatusCode'
])
Source: Amazon route53 add geo based A record using python boto3 library | {Fetch,Decode,Execute & Share}