AWS CloudFormation
User Guide (API Version 2010-05-15)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

AWS::EC2::EIPAssociation

AWS::EC2::EIPAssociation 资源类型可将弹性 IP 地址与 Amazon EC2 实例关联。该弹性 IP 地址可以是现有弹性 IP 地址,也可以是通过 AWS::EC2::EIP 资源分配的弹性 IP 地址。

有关 EC2-Classic 和 EC2-VPC 的更多信息,请参阅 Amazon EC2 API Reference 中的 AssociateAddress

语法

要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:

JSON

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

YAML

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

属性

AllocationId

[EC2-VPC] 您希望与 VPC 中的 Amazon EC2 实例关联的 VPC 弹性 IP 地址的分配 ID。

必填:条件性。对于 EC2-VPC 为必填。

类型:字符串

更新要求替换 如果同时还更改 InstanceIdNetworkInterfaceId 属性。如果不更改,则更新要求无中断

EIP

您希望将其与 InstanceId 属性指定的 Amazon EC2 实例关联的弹性 IP 地址。您可以指定一个现有的弹性 IP 地址,也可以引用使用 AWS::EC2::EIP resource 资源分配的弹性 IP 地址。

必填:条件性。对于 EC2-Classic 为必填。

类型:字符串

更新要求替换 如果同时还更改 InstanceIdNetworkInterfaceId 属性。如果不更改,则更新要求无中断

InstanceId

您希望将其与 EIP 属性指定的弹性 IP 地址关联的 Amazon EC2 实例的实例 ID。如果实例有多个网络接口,您必须指定一个网络接口 ID。

必填:条件性。如果您指定了 EIP 属性,则必须指定该属性。如果指定 AllocationId 属性,则必须指定此属性或 NetworkInterfaceId 属性。

类型:字符串

更新要求替换 如果同时还更改 AllocationIdEIP 属性。如果不更改,则更新要求无中断

NetworkInterfaceId

[EC2-VPC] 要与弹性 IP 地址关联的网络接口的 ID。如果实例有多个网络接口,您必须指定一个网络接口 ID。

必填:条件性。如果指定 AllocationId 属性,则必须指定此属性或 InstanceId 属性。

类型:字符串

更新要求替换 如果同时还更改 AllocationIdEIP 属性。如果不更改,则更新要求无中断

PrivateIpAddress

[EC2-VPC] 要与弹性 IP 地址关联的私有 IP 地址。私有 IP 地址仅限与网络接口关联的主辅私有 IP 地址。默认情况下,与 EIP 关联的私有 IP 地址是网络接口的主要私有 IP 地址。

必需:否

类型:字符串

更新要求无需中断

返回值

Ref

当该资源的逻辑 ID 提供给 Ref内部函数时,Ref 将返回资源名称。

有关使用 Ref 功能的更多信息,请参阅参考

示例

以下示例创建一个带两个弹性网络接口 (ENI) 的实例。此示例假设您已有一个 VPC。

有关其他示例,请参阅 分配一个使用 AWS::EC2::EIP 代码段的 Amazon EC2 弹性 IP

JSON

Copy
"Resources" : { "ControlPortAddress" : { "Type" : "AWS::EC2::EIP", "Properties" : { "Domain" : "vpc" } }, "AssociateControlPort" : { "Type" : "AWS::EC2::EIPAssociation", "Properties" : { "AllocationId" : { "Fn::GetAtt" : [ "ControlPortAddress", "AllocationId" ]}, "NetworkInterfaceId" : { "Ref" : "controlXface" } } }, "WebPortAddress" : { "Type" : "AWS::EC2::EIP", "Properties" : { "Domain" : "vpc" } }, "AssociateWebPort" : { "Type" : "AWS::EC2::EIPAssociation", "Properties" : { "AllocationId" : { "Fn::GetAtt" : [ "WebPortAddress", "AllocationId" ]}, "NetworkInterfaceId" : { "Ref" : "webXface" } } }, "SSHSecurityGroup" : { "Type" : "AWS::EC2::SecurityGroup", "Properties" : { "VpcId" : { "Ref" : "VpcId" }, "GroupDescription" : "Enable SSH access via port 22", "SecurityGroupIngress" : [ { "IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0" } ] } }, "WebSecurityGroup" : { "Type" : "AWS::EC2::SecurityGroup", "Properties" : { "VpcId" : { "Ref" : "VpcId" }, "GroupDescription" : "Enable HTTP access via user defined port", "SecurityGroupIngress" : [ { "IpProtocol" : "tcp", "FromPort" : 80, "ToPort" : 80, "CidrIp" : "0.0.0.0/0" } ] } }, "controlXface" : { "Type" : "AWS::EC2::NetworkInterface", "Properties" : { "SubnetId" : { "Ref" : "SubnetId" }, "Description" :"Interface for control traffic such as SSH", "GroupSet" : [ {"Ref" : "SSHSecurityGroup"} ], "SourceDestCheck" : "true", "Tags" : [ {"Key" : "Network", "Value" : "Control"}] } }, "webXface" : { "Type" : "AWS::EC2::NetworkInterface", "Properties" : { "SubnetId" : { "Ref" : "SubnetId" }, "Description" :"Interface for web traffic", "GroupSet" : [ {"Ref" : "WebSecurityGroup"} ], "SourceDestCheck" : "true", "Tags" : [ {"Key" : "Network", "Value" : "Web"}] } }, "Ec2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]}, "KeyName" : { "Ref" : "KeyName" }, "NetworkInterfaces" : [ { "NetworkInterfaceId" : {"Ref" : "controlXface"}, "DeviceIndex" : "0" }, { "NetworkInterfaceId" : {"Ref" : "webXface"}, "DeviceIndex" : "1" }], "Tags" : [ {"Key" : "Role", "Value" : "Test Instance"}], "UserData" : {"Fn::Base64" : { "Fn::Join" : ["",[ "#!/bin/bash -ex","\n", "\n","yum install ec2-net-utils -y","\n", "ec2ifup eth1","\n", "service httpd start"]]} } } } }

YAML

Copy
Resources: ControlPortAddress: Type: AWS::EC2::EIP Properties: Domain: vpc AssociateControlPort: Type: AWS::EC2::EIPAssociation Properties: AllocationId: !GetAtt ControlPortAddress.AllocationId NetworkInterfaceId: !Ref controlXface WebPortAddress: Type: AWS::EC2::EIP Properties: Domain: vpc AssociateWebPort: Type: AWS::EC2::EIPAssociation Properties: AllocationId: !GetAtt WebPortAddress.AllocationId NetworkInterfaceId: !Ref webXface SSHSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: VpcId: !Ref VpcId GroupDescription: Enable SSH access via port 22 SecurityGroupIngress: - CidrIp: 0.0.0.0/0 FromPort: 22 IpProtocol: tcp ToPort: 22 WebSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: VpcId: !Ref VpcId GroupDescription: Enable HTTP access via user defined port SecurityGroupIngress: - CidrIp: 0.0.0.0/0 FromPort: 80 IpProtocol: tcp ToPort: 80 controlXface: Type: AWS::EC2::NetworkInterface Properties: SubnetId: !Ref SubnetId Description: Interface for controlling traffic such as SSH GroupSet: - !Ref SSHSecurityGroup SourceDestCheck: true Tags: - Key: Network Value: Control webXface: Type: AWS::EC2::NetworkInterface Properties: SubnetId: !Ref SubnetId Description: Interface for controlling traffic such as SSH GroupSet: - !Ref WebSecurityGroup SourceDestCheck: true Tags: - Key: Network Value: Web Ec2Instance: Type: AWS::EC2::Instance Properties: ImageId: !FindInMap [ RegionMap, !Ref 'AWS::Region', AMI ] KeyName: !Ref KeyName NetworkInterfaces: - NetworkInterfaceId: !Ref controlXface DeviceIndex: 0 - NetworkInterfaceId: !Ref webXface DeviceIndex: 1 Tags: - Key: Role Value: Test Instance UserData: Fn::Base64: !Sub | #!/bin/bash -xe yum install ec2-net-utils -y ec2ifup eth1 service httpd start

本页内容: