route53 dns in python

To manage Route53 DNS in Python, you can use the AWS SDK for Python, also known as Boto3. Here's an example code snippet that demonstrates how to use Boto3 to create a DNS record in Route53:

main.py
import boto3

# Set up the client
client = boto3.client('route53')

# Define the hosted zone ID
hosted_zone_id = 'ABCDEFGHIJKLMN'

# Define the DNS record
record_name = 'example.com'
record_value = '1.2.3.4'

# Create the DNS record in Route53
response = client.change_resource_record_sets(
    HostedZoneId=hosted_zone_id,
    ChangeBatch={
        'Changes': [
            {
                'Action': 'CREATE',
                'ResourceRecordSet': {
                    'Name': record_name,
                    'Type': 'A',
                    'TTL': 300,
                    'ResourceRecords': [{'Value': record_value}]
                }
            }
        ]
    }
)
673 chars
30 lines

This example creates an A record with the name "example.com" and the IP address "1.2.3.4" in the hosted zone with the specified ID. You can modify this code to create other types of records or to update existing records.

related categories

gistlibby LogSnag