Using Instance Addressing
Topics
This section describes how to perform common instance addressing tasks.
API Overview
This section provides a brief overview of each elastic IP address operation.
-
AllocateAddress—Acquires an elastic IP address for use with your account.
-
DescribeAddresses—Lists elastic IP addresses assigned to your account.
-
ReleaseAddress—Releases an elastic IP address associated with your account.
After releasing an elastic IP address, it is released to the IP address pool and might no longer be available to your account.
-
AssociateAddress—Associates an elastic IP address with an instance.
-
DisassociateAddress—Disassociates the specified elastic IP address from the instance to which it is assigned.
Determining Your IP Addresses
This section describes how to determine your internal and external IP addresses.
How To
To determine your private and public IP addresses
-
If you are using SOAP, construct the following request:
<DescribeInstances xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <instancesSet> <item> <instanceId>
instance-id
</instanceId> </item> </instancesSet> </DescribeInstances> -
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=DescribeInstances &InstanceId.1=
instance-id
&...auth parameters... -
View output similar to the following:
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <reservationSet> <item> <reservationId>r-44a5402d</reservationId> <ownerId>UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM</ownerId> <groupSet> <item> <groupId>default</groupId> </item> </groupSet> <instancesSet> <item> <instanceId>i-28a64341</instanceId> <imageId>ami-6ea54007</imageId> <instanceState> <code>0</code> <name>running</name> </instanceState> <privateDnsName>10-251-50-132.ec2.internal</privateDnsName> <dnsName>ec2-72-44-33-4.compute-1.amazonaws.com</dnsName> <keyName>example-key-name</keyName> <amiLaunchIndex>23</amiLaunchIndex> <productCodesSet> <item><productCode>774F4FF8</productCode></item> </productCodesSet> <instanceType>m1.large</instanceType> <launchTime>2007-08-07T11:54:42.000Z</launchTime> <placement> <availabilityZone>us-east-1b</availabilityZone> </placement> <kernelId>aki-ba3adfd3</kernelId> <ramdiskId>ari-badbad00</ramdiskId> </item> </instancesSet> </item> </reservationSet> </DescribeInstancesResponse>
-
To determine the public IP address, use the IP address specified within
dnsName
. -
To determine the private IP address, use the IP address specified within
privateDnsName
.
Using Elastic IP Addresses
Elastic IP addresses are static IP addresses designed for dynamic cloud computing. An elastic IP address is associated with your account, not a particular instance. You control addresses associated with your account until you choose to explicitly release them.
This section describes how to perform common elastic IP address tasks.
Allocating Elastic IP Addresses
This section describes how to assign an Amazon EC2 elastic IP address to your account and verify it.
How To
To allocate a new IP address for use with your account
-
If you are using SOAP, construct the following request:
<AllocateAddress xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"/>
-
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=AllocateAddress &...auth parameters...
-
View output similar to the following:
<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31//"> <publicIp>67.202.55.255</publicIp> </AllocateAddressResponse>
Describing Elastic IP Addresses
This section describes how to view the elastic IP addresses allocated to your account.
How To
To view elastic IP addresses assigned to your account
-
If you are using SOAP, construct the following request:
<DescribeAddresses xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"/>
-
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=DescribeAddresses &...auth parameters...
-
View output similar to the following:
<DescribeAddressesResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <addressesSet> <item> <instanceId>i-28a64341</instanceId> <publicIp>67.202.55.255</publicIp> </item> </addressesSet> </DescribeAddressesResponse>
Associating an Elastic IP Address with a Running Instance
Once an elastic IP address is allocated, you can map it to a running instance.
How To
To associate an elastic IP address with an instance
-
Describe running instances and write down the instance ID of the instance that you will associate with the elastic IP address. For more information, see How To.
-
Describe elastic IP addresses assigned to the account and write down the elastic IP address that you will associate with the instance. For more information, see How To.
-
Associate the instance and elastic IP address.
If you are using SOAP, construct the following request:
<AssociateAddress xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <instanceId>
instance-id
</instanceId> <publicIp>elastic-ip-address
</publicIp> </AssociateAddress>If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=AssociateAddress &InstanceId=
instance-id
&PublicIp=elastic-ip-address
&...auth parameters...Amazon EC2 returns output similar to the following:
<AssociateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <return>true</return> </AssociateAddressResponse>
-
Associations take a few minutes to complete. You can verify the association using
DescribeAddresses
orDescribeInstances
.
Associating an Elastic IP Address with a Different Running Instance
Once an Elastic IP Address is allocated, you can map it to a different running instance.
Note | |
---|---|
It is highly unlikely that an instance will be configured with its original public IP address that it used prior to being mapped. |
How To
To remap an IP address
-
Describe running instances and write down the instance ID of the instance that you will associate with the elastic IP address.
-
Describe elastic IP addresses assigned to the account and write down the elastic IP address to remap.
-
Associate the instance and elastic IP address.
If you are using SOAP, construct the following request:
<AssociateAddress xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <instanceId>
instance-id
</instanceId> <publicIp>elastic-ip-address
</publicIp> </AssociateAddress>If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=AssociateAddress &InstanceId=
instance-id
&PublicIp=elastic-ip-address
&...auth parameters...Amazon EC2 returns output similar to the following:
<AssociateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <return>true</return> </AssociateAddressResponse>
Associations take a few minutes to complete.
-
Verify the association using
DescribeAddresses
orDescribeInstances
.
Example
In the following example, web servers are connected to the Internet through elastic IP addresses and to database servers through their private IP addresses.
The administrator decides to replace a web server with a larger instance type. To do this, the administrator starts a new instance using a larger instance type (1), disassociates an elastic IP address from a running instance (2), associates the elastic IP address with the new instance (3), and terminates the old instance (4).
Process
The following demonstrates how to set up these tasks using the API.
-
The user runs a new larger instance type using
RunInstances
. -
The user disassociates the elastic IP address from the old instance using
DisassociateAddress
.Note This step is optional as
AssociateAddress
automatically disassociates the elastic IP address if it is assigned to another instance. -
The user associates the elastic IP address with the new instance using
AssociateAddress
. -
The user verifies the association using
DescribeInstances
. -
The user terminates the old instance using
TerminateInstances
.