Skip to content

associate_dhcp_options

associate_dhcp_options(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dhcp_options_id: Optional[DefaultingDhcpOptionsId] = None,
    vpc_id: Optional[VpcId] = None,
    dry_run: Optional[Boolean] = None,
) -> None

Associates a set of DHCP options (that you've previously created) with the specified VPC, or associates no DHCP options with the VPC.

After you associate the options with the VPC, any existing instances and all new instances that you launch in that VPC use the options. You don't need to restart or relaunch the instances. They automatically pick up the changes within a few hours, depending on how frequently the instance renews its DHCP lease. You can explicitly renew the lease using the operating system on the instance.

For more information, see DHCP option sets in the Amazon VPC User Guide.

Parameters:

  • dhcp_options_id (Optional[DefaultingDhcpOptionsId], default: None ) –

    The ID of the DHCP options set, or default to associate no DHCP options with the VPC.

  • vpc_id (Optional[VpcId], default: None ) –

    The ID of the VPC.

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Raises:

Examples:

To associate a DHCP options set with a VPC This example associates the specified DHCP options set with the specified VPC.

>>> client.associate_dhcp_options(dhcp_options_id='dopt-d9070ebb', vpc_id='vpc-a01106c2')
To associate the default DHCP options set with a VPC
This example associates the default DHCP options set with the specified VPC.
>>> client.associate_dhcp_options(dhcp_options_id='default', vpc_id='vpc-a01106c2')
Source code in docs_src/capo_ec2/_services/ec2.py
def associate_dhcp_options(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dhcp_options_id: Optional[
        "capo_ec2.types.defaulting_dhcp_options_id.DefaultingDhcpOptionsId"
    ] = None,
    vpc_id: Optional["capo_ec2.types.vpc_id.VpcId"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> None:
    """<p>Associates a set of DHCP options (that you've previously created) with the specified VPC, or associates no DHCP options with the VPC.</p> <p>After you associate the options with the VPC, any existing instances and all new instances that you launch in that VPC use the options. You don't need to restart or relaunch the instances. They automatically pick up the changes within a few hours, depending on how frequently the instance renews its DHCP lease. You can explicitly renew the lease using the operating system on the instance.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_DHCP_Options.html">DHCP option sets</a> in the <i>Amazon VPC User Guide</i>.</p>

    Args:
        dhcp_options_id: <p>The ID of the DHCP options set, or <code>default</code> to associate no DHCP options with the VPC.</p>
        vpc_id: <p>The ID of the VPC.</p>
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To associate a DHCP options set with a VPC
        This example associates the specified DHCP options set with the specified VPC.

        >>> client.associate_dhcp_options(dhcp_options_id='dopt-d9070ebb', vpc_id='vpc-a01106c2')
        To associate the default DHCP options set with a VPC
        This example associates the default DHCP options set with the specified VPC.

        >>> client.associate_dhcp_options(dhcp_options_id='default', vpc_id='vpc-a01106c2')
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.associate_dhcp_options_request.AssociateDhcpOptionsRequest]",
    ) -> OperationResponse[None]:
        import capo_ec2._operations.amazon_ec2.associate_dhcp_options

        output, http_response = (
            capo_ec2._operations.amazon_ec2.associate_dhcp_options.associate_dhcp_options(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AssociateDhcpOptions")
    )
    input_: capo_ec2.types.associate_dhcp_options_request.AssociateDhcpOptionsRequest = {}
    if dhcp_options_id is not None:
        input_["dhcp_options_id"] = dhcp_options_id
    if vpc_id is not None:
        input_["vpc_id"] = vpc_id
    if dry_run is not None:
        input_["dry_run"] = dry_run

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output