Menu
Amazon Elastic Compute Cloud
API Reference (API Version 2016-11-15)

AttachClassicLinkVpc

Links an EC2-Classic instance to a ClassicLink-enabled VPC through one or more of the VPC's security groups. You cannot link an EC2-Classic instance to more than one VPC at a time. You can only link an instance that's in the running state. An instance is automatically unlinked from a VPC when it's stopped - you can link it to the VPC again when you restart it.

After you've linked an instance, you cannot change the VPC security groups that are associated with it. To change the security groups, you must first unlink the instance, and then link it again.

Linking your instance to a VPC is sometimes referred to as attaching your instance.

Request Parameters

The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see Common Query Parameters.

DryRun

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.

Type: Boolean

Required: No

InstanceId

The ID of an EC2-Classic instance to link to the ClassicLink-enabled VPC.

Type: String

Required: Yes

SecurityGroupId.N

The ID of one or more of the VPC's security groups. You cannot specify security groups from a different VPC.

Type: Array of strings

Required: Yes

VpcId

The ID of a ClassicLink-enabled VPC.

Type: String

Required: Yes

Response Elements

The following elements are returned by the service.

requestId

The ID of the request.

Type: String

return

Returns true if the request succeeds; otherwise, it returns an error.

Type: Boolean

Errors

For information about the errors that are common to all actions, see Common Client Errors.

Examples

Example

This example links instance i-1234567890abcdef0 to VPC vpc-88888888 through the VPC's security group sg-12312312.

Sample Request

https://ec2.amazonaws.com/?Action=AttachClassicLinkVpc &VpcId=vpc-88888888 &InstanceId=i-1234567890abcdef0 &GroupId.1=sg-12312312 &AUTHPARAMS

Sample Response

<AttachClassicLinkVpcResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> <return>true</return> </AttachClassicLinkVpcResponse>

Example

This example links instance i-1234567890abcdef0 to VPC vpc-88888888 through the VPC's security groups sg-12312312 and sg-44455566.

Sample Request

https://ec2.amazonaws.com/?Action=AttachClassicLinkVpc &VpcId=vpc-88888888 &InstanceId=i-1234567890abcdef0 &GroupId.1=sg-12312312 &GroupId.2=sg-44455566 &AUTHPARAMS

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: