Home > Enterprise >  Filter DHCP Options Sets Boto3
Filter DHCP Options Sets Boto3

Time:02-25

I want to filter DHCP Options sets by domain-name and domain-name-servers using Boto3. The documentation states I can use several filters. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#dhcpoptions

It looks like I should be able to use a "key" filter somehow to filter on domain-name.

"key - The key for one of the options (for example, domain-name )."

The following code produces an error.

def query_dhcp_options_set():

    ec2_client = boto3.client('ec2', region_name='us-west-1')

    filters = [
        {'Name':'domain-name', 'Values':['example.com']},
    ]

    return ec2_client.describe_dhcp_options(Filters=filters)

botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the DescribeDhcpOptions operation: The filter 'domain-name' is invalid

I have also tried the following code

def query_dhcp_options_set():

    ec2_client = boto3.client('ec2', region_name='us-west-1')

    filters = [
        {'Name':'key:domain-name', 'Values':['example.com']},
    ]

    return ec2_client.describe_dhcp_options(Filters=filters)

botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the DescribeDhcpOptions operation: The filter 'key:domain-name' is invalid

Can an example be provided of querying DHCP Options sets by the domain-name and domain-name-servers property?

CodePudding user response:

try [ { "Name":"key", "Values":[ "domain-name" ] }, { "Name":"value", "Values":[ "example.com" ] } ]

  • Related