AWS::EC2::EIPAssociation - Amazon CloudFormation
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

AWS::EC2::EIPAssociation

Associates an Elastic IP address with an instance or a network interface. Before you can use an Elastic IP address, you must allocate it to your account. For more information about working with Elastic IP addresses, see Elastic IP address concepts and rules.

You must specify AllocationId and either InstanceId, NetworkInterfaceId, or PrivateIpAddress.

Syntax

To declare this entity in your Amazon CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::EC2::EIPAssociation", "Properties" : { "AllocationId" : String, "EIP" : String, "InstanceId" : String, "NetworkInterfaceId" : String, "PrivateIpAddress" : String } }

YAML

Type: AWS::EC2::EIPAssociation Properties: AllocationId: String EIP: String InstanceId: String NetworkInterfaceId: String PrivateIpAddress: String

Properties

AllocationId

The allocation ID. This is required.

Required: Conditional

Type: String

Update requires: Some interruptions

EIP

Deprecated.

Required: Conditional

Type: String

Update requires: Some interruptions

InstanceId

The ID of the instance. The instance must have exactly one attached network interface. You can specify either the instance ID or the network interface ID, but not both.

Required: Conditional

Type: String

Update requires: Some interruptions

NetworkInterfaceId

The ID of the network interface. If the instance has more than one network interface, you must specify a network interface ID.

You can specify either the instance ID or the network interface ID, but not both.

Required: Conditional

Type: String

Update requires: Some interruptions

PrivateIpAddress

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.

Required: No

Type: String

Update requires: No interruption

Return values

Ref

When you pass the logical ID of this resource to the intrinsic Reffunction, Refreturns the resource name.

For more information about using the Reffunction, see Ref.

Examples

Associate an Elastic IP address to an instance

The following example creates an Elastic IP address and a network interface, and associates the Elastic IP address with the network interface. The example uses the ID of an existing subnet and an example IP address from the subnet CIDR range.

JSON

"Resources" : { "myEIP" : { "Type" : "AWS::EC2::EIP", "Properties" : { "Domain" : "vpc" } }, "myENI" : { "Type" : "AWS::EC2::NetworkInterface", "Properties" : { "SubnetId" : "subnet-0231a7e21ca967d2c", "PrivateIpAddress": "10.0.0.16" } }, "eniAssociation" : { "Type" : "AWS::EC2::EIPAssociation", "Properties" : { "AllocationId" : { "Fn::GetAtt" : [ "myEIP", "AllocationId" ] }, "NetworkInterfaceId" : { "Ref" : "myENI" } } } }

YAML

Resources: myEIP: Type: AWS::EC2::EIP Properties: Domain: vpc myENI: Type: AWS::EC2::NetworkInterface Properties: SubnetId: subnet-0231a7e21ca967d2c PrivateIpAddress: 10.0.0.16 eniAssociation: Type: AWS::EC2::EIPAssociation Properties: AllocationId: !GetAtt myEIP.AllocationId NetworkInterfaceId: !Ref myENI