Amazon Elastic Compute Cloud
API Reference (API Version 2014-10-01)
Did this page help you?  Yes | No |  Tell us about it...
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.

AssociateAddress

Associates an Elastic IP address with an instance or a network interface.

An Elastic IP address is for use in either the EC2-Classic platform or in a VPC. For more information, see Elastic IP Addresses in the Amazon Elastic Compute Cloud User Guide.

[EC2-Classic, VPC in an EC2-VPC-only account] If the Elastic IP address is already associated with a different instance, it is disassociated from that instance and associated with the specified instance.

[VPC in an EC2-Classic account] If you don't specify a private IP address, the Elastic IP address is associated with the primary IP address. If the Elastic IP address is already associated with a different instance or a network interface, you get an error unless you allow reassociation.

This is an idempotent operation. If you perform the operation more than once, Amazon EC2 doesn't return an error.

Request Parameters

For information about the common parameters that all actions use, see Common Query Parameters.

AllocationId

[EC2-VPC] The allocation ID. This is required for EC2-VPC.

Type: String

Required: No

InstanceId

The ID of the instance. This is required for EC2-Classic. For EC2-VPC, you can specify either the instance ID or the network interface ID, but not both. The operation fails if you specify an instance ID unless exactly one network interface is attached.

Type: String

Required: Yes

PublicIp

The Elastic IP address. This is required for EC2-Classic.

Type: String

Required: Yes

AllowReassociation

[EC2-VPC] Allows an Elastic IP address that is already associated with an instance or network interface to be re-associated with the specified instance or network interface. Otherwise, the operation fails.

Default: false

Type: Boolean

Required: No

DryRun

Type: Boolean

Required: No

NetworkInterfaceId

[EC2-VPC] The ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID.

Type: String

Required: No

PrivateIpAddress

[EC2-VPC] The primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address.

Type: String

Required: No

Response Elements

The following elements are returned.

associationId

[EC2-VPC] The ID that represents the association of the Elastic IP address with an instance.

Type: String

requestId

The ID of the request.

Type: String

Errors

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

Examples

Example for EC2-Classic

This example request associates an Elastic IP address with an instance in EC2-Classic.

Sample Request

https://ec2.amazonaws.com/?Action=AssociateAddress
&InstanceId=i-2ea64347
&PublicIp=192.0.2.1
&AUTHPARAMS

Sample Response

<AssociateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2014-10-01/">
  <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
  <return>true</return>
</AssociateAddressResponse>

Example for EC2-VPC

This example request associates a Elastic IP address with an instance in a VPC. The AllowReassignment parameter allows the Elastic IP address to be associated with the specified instance even if it's already associated with a different instance or a network interface.

Sample Request

https://ec2.amazonaws.com/?Action=AssociateAddress
&InstanceId=i-4fd2431a
&AllocationId=eipalloc-5723d13e
&AllowReassignment=true
&AUTHPARAMS

Sample Response

<AssociateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2014-10-01/">
   <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
   <return>true</return>
   <associationId>eipassoc-fc5ca095</associationId>
</AssociateAddressResponse>