All Products
Search
Document Center

Virtual Private Cloud:AttachDhcpOptionsSetToVpc

Last Updated:Aug 17, 2026

Calls the AttachDhcpOptionsSetToVpc operation to attach a DHCP options set to a VPC.

Operation description

  • AttachDhcpOptionsSetToVpc is an asynchronous operation. After you send a request, the system returns a request ID, but the DHCP options set is not yet attached to the VPC. The attachment task is still running in the background. You can call DescribeVpcAttribute to query the attachment status of the DHCP options set:
    • If the DHCP options set is in the Pending state, the DHCP options set is being attached.

    • If the DHCP options set is in the InUse state, the DHCP options set is attached.

  • AttachDhcpOptionsSetToVpc does not support concurrent attachment of DHCP options sets to the same VPC.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

vpc:AttachDhcpOptionsSetToVpc

update

*DhcpOptionsSet

acs:vpc:{#regionId}:{#accountId}:dhcpoptionsset/{#DhcpOptionsSetId}

*VPC

acs:vpc:{#regionId}:{#accountId}:vpc/{#VpcId}

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

The region where the DHCP options set resides. You can call the DescribeRegions operation to query the region ID.

cn-hangzhou

DhcpOptionsSetId

string

Yes

The ID of the DHCP options set.

dopt-o6w0df4epg9zo8isy****

VpcId

string

Yes

The ID of the VPC to which you want to attach the DHCP options set.

vpc-sfdkfdjkdf****

ClientToken

string

No

The client token that is used to ensure the idempotence of the request.

You can use the client to generate the token, but you must make sure that the token is unique among different requests. The ClientToken value can contain only ASCII characters.

Note

If you do not specify this parameter, the system uses the RequestId as the ClientToken. The RequestId may differ for each API request.

0c593ea1-3bea-11e9-b96b-88e9fe637760

DryRun

boolean

No

Specifies whether to perform a dry run. Valid values:

true: performs a dry run without associating the DHCP options set with the associate VPC. The system checks the request for potential issues, including whether the AccessKey is valid, the authorization of the Resource Access Management (RAM) user, and whether required parameters are specified. If the check fails, the corresponding error is returned. If the check succeeds, the DryRunOperation error code is returned.

false (default): sends a normal request. If the check succeeds, a 2XX HTTP status code is returned and the DHCP options set is associated with the VPC.

false

Response elements

Element

Type

Description

Example

object

RequestId

string

The request ID.

0ED8D006-F706-4D23-88ED-E11ED28DCAC0

Examples

Success response

JSON format

{
  "RequestId": "0ED8D006-F706-4D23-88ED-E11ED28DCAC0"
}

Error codes

HTTP status code

Error code

Error message

Description

400 Forbidden.OperateShareResource You cannot operate shared resources. Shared resources do not support this operation.
400 InvalidDhcpOptionsSetId.NotFound The specified dhcpOptionsSetId does not exist. The DHCP options set does not exist. Check whether the parameter is set to a valid value.
400 IncorrectStatus.DhcpOptionsSet The DhcpOptionsSet status does not support this operation. The DHCP options set that is associated with the VPC is being configured. As a result, the DHCP options set does not support this operation. You can perform the operation after the status of the DHCP options set is stable.
400 InvalidVpcId.NotFound Specified value of VpcId is not found in our record.
400 IncorrectStatus.VpcDhcpOptionsSet The dhcpOptionsSet status of VPC does not support this operation. The DHCP options set that is associated with the VPC is being configured. As a result, the DHCP options set does not support this operation.
400 OperationFailed.AttachmentExist The current VPC is already attached to a DHCP options set. The VPC is associated with a DHCP options set. You can associate a VPC with only one DHCP options set.
400 QuotaExceeded.AttachVpcNumber The maximum number of VPCs that can be attached to a DHCP options set is exceeded. The number of VPCs that can be associated with a DHCP options set reaches the upper limit.
400 TaskConflict The operation is too frequent. Please wait a moment and try again. The system is unavailable. Try again later.
400 MissingParam.VpcId You must specify VpcId. You must specify VpcId.
400 MissingParam.DhcpOptionsSetId Missing parameter DhcpOptionsSetId. Missing parameter DhcpOptionsSetId
400 InvalidRegionId.NotFound The specified RegionId does not exist. The specified region does not exist.
400 IncorrectStatus.VpcDnsHostnameStatus The DnsHostname status of vpc does not support this operation. The private domain name status of the current VPC does not support this operation.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.