从CloudFormation脚本内部将现有的Elastic IP与Ec2实例相关联? [英] Associate an existing Elastic IP with an Ec2 Instance from inside a CloudFormation script?

查看:135
本文介绍了从CloudFormation脚本内部将现有的Elastic IP与Ec2实例相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CloudFormation堆栈,该堆栈用于创建环境的多个副本. 这些环境中的某些(但不是全部)将具有关联的弹性IP.

I have a CloudFormation stack that is used to create multiple copies of an environment. Some but not all of these environments will have elastic IPs associated.

现在我:

  1. 运行CF脚本

  1. Run the CF script

在需要的地方分配弹性IP

Assign the Elastic IP where approprite

在不涉及实例的堆栈更新中,Elastic IP被保留到拥有该实例的实例中.

On stack updates that don't touch the instance, Elastic IP is preserved to the instance which had it.

在更新实例本身时,关联将丢失.

On updates to the instance itself,the association is lost.

从CF堆栈本身进行更新时,当基础实例名称发生更改时,这是有道理的,这将导致IP未分配.因此,我想将弹性IP的ID作为参数传递给脚本并手动进行分配.

It kind of makes senses that when the underlying instance name is changed when updates are made from the CF stack itself, which causes the IP to become unassigned. So I would like to pass in the ID of the elastic IP as a parameter to the script and assign it manually.

似乎有两种方法,但我不明白其中的区别.什么是分配ID,什么时候需要使用?

It seems there are two ways to do this, but I don't understand the difference. What is an allocation Id, and when would you need to use it?

"IPAssoc" : {
     "Type" : "AWS::EC2::EIPAssociation",
     "Properties" : {
         "InstanceId" : { "Ref" : "logical name of an AWS::EC2::Instance resource" },
         "EIP" : "existing Elastic IP address"
     }
 }

vs

"VpcIPAssoc" : {
     "Type" : "AWS::EC2::EIPAssociation",
     "Properties" : {
         "InstanceId" : { "Ref" : "logical name of an AWS::EC2::Instance resource" },
         "AllocationId" : "existing VPC Elastic IP allocation ID"
     }
 }

推荐答案

差异是VPC使用率和EC2 Classic之间.

The difference is between VPC usage and EC2 Classic.

根据 http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip-association.html ,EIP用于EC2 Classic,而AllocationId用于VPC.

As per http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip-association.html, EIP is for use with EC2 Classic and AllocationId is for VPC's.

有关VPC和EC2 Classic之间的区别,请参见 http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-vpc.html#differences-ec2-classic-vpc .

For the difference between VPC and EC2 Classic, see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-vpc.html#differences-ec2-classic-vpc.

这篇关于从CloudFormation脚本内部将现有的Elastic IP与Ec2实例相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆