Route 53
Amazon Route 53 is a highly available and scalable domain name system (DNS) web service. Here is an example of how to create a Route 53 hosted zone and a DNS record using the AWS SDK for Python (boto3):
python
import boto3
route53_client = boto3.client('route53')
domain_name = 'example.com'
response = route53_client.create_hosted_zone(
Name=domain_name,
CallerReference='my-reference',
HostedZoneConfig={
'Comment': 'An example hosted zone',
'PrivateZone': False
}
)
hosted_zone_id = response['HostedZone']['Id']
dns_name = 'www.example.com'
response = route53_client.change_resource_record_sets(
HostedZoneId=hosted_zone_id,
ChangeBatch={
'Comment': 'An example DNS record',
'Changes': [
{
'Action': 'CREATE',
'ResourceRecordSet': {
'Name': dns_name,
'Type': 'A',
'TTL': 300,
'ResourceRecords': [
{
'Value': '10.0.0.1'
}
]
}
}
]
}
)
change_id = response['ChangeInfo']['Id']
print(f"Route 53 hosted zone created with ID {hosted_zone_id}")
print(f"DNS record created for {dns_name} with change ID {change_id}")
This code creates a Route 53 hosted zone with the specified name and configuration, and adds a DNS record for the specified DNS name that points to a specified IP address. The hosted zone ID and change ID are printed to the console.
No comments:
Post a Comment