Search code examples
python-3.xboto3amazon-route53

boto3 change_resource_record_sets with multiple ipadresses


How do I add an A record for a lb where I'm able to add more then one ipaddress to the same record. I the console it is possible, but I'm not sure how to do it in Python. Below is my try which only add the last Value to the record.

#!/usr/bin/env python3
import boto3

#TODO #use env variables for names, Values and zonename

def lambda_handler(event, context):
    client = boto3.client('route53')
    response = client.change_resource_record_sets(
        HostedZoneId='Z03115902SB93XHRQS9LT',
        ChangeBatch={
            'Changes': [
                {
                    'Action': 'UPSERT',
                    'ResourceRecordSet': {
                        'Name': 'web-staging-lb.ggnp3ggdjcvwpfpqhsuwda.soemdomain.com',
                        'Type': 'A',
                        'TTL': 60,
                        'ResourceRecords': [
                            {
                                'Value': '10.201.11.246',
                                'Value': '10.201.10.12',
                            },
                        ],
                    },
                },
            ],
            'Comment': 'Record to acces private ips of alb',
        },
    )


Solution

  • ResourceRecords is a list that can contain multiple elements.

                            'ResourceRecords': [
                                {
                                    'Value': '10.201.10.12',
                                },
                                {
                                    'Value': '10.201.11.246',
                                },
    

    Managing an A record with multiple IPs in Route53 with python boto3