import boto3 import requests def update_route53_record(): # Get the current dynamic IP address ip_address = requests.get('https://ifconfig.co/ip').text # Update Route 53 record with the new IP address route53_client = boto3.client('route53') # Specify the domain name for the hosted zone domain_name = 'delphizon.com' # parent domain record_name = 'fdcs.delphizon.com' # child record # Retrieve the list of hosted zones response = route53_client.list_hosted_zones_by_name(DNSName=domain_name) hosted_zone_id = response['HostedZones'][0]['Id'].split('/')[-1] # Retrieve the Hosted Zone record sets response = route53_client.list_resource_record_sets( HostedZoneId=hosted_zone_id, StartRecordName=record_name, StartRecordType='A', MaxItems='1' ) # Change ths Hosted Zone records sets response = route53_client.change_resource_record_sets( HostedZoneId=hosted_zone_id, ChangeBatch={ 'Changes': [ { 'Action': 'UPSERT', 'ResourceRecordSet': { 'Name': record_name, 'Type': 'A', 'TTL': 300, 'ResourceRecords': [{'Value': ip_address}] } } ] } ) print(f"Route 53 record updated with IP: {ip_address}") def lambda_handler(event, context): update_route53_record() return { 'statusCode': 200, 'body': 'Route 53 record updated successfully' } update_route53_record()
Subscribe
Login
0 Comments
Oldest