首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用云表单为ec2实例添加弹性IP

使用云表单为ec2实例添加弹性IP
EN

Stack Overflow用户
提问于 2019-09-12 14:48:57
回答 2查看 1.4K关注 0票数 0

我在哪里可以从我的cloudformation模板附加弹性ip?

代码语言:javascript
复制
{
"Description" : "Staging single instance",
"Outputs": {
    "InstanceID": {
        "Description": "The WWW instance id",
        "Value": { "Ref": "StageInstance" }
    }
},
"Parameters": {
    "AMI": {
        "Description": "The Amazon Ubuntu AMI",
        "Type": "String",
        "Default": "ami-009110a2bf8d7dd0a"
    },
    "EBSVolumeSize": {
        "Description": "The size of the EBS volume for the transcoder",
        "Type": "String",
        "Default": "20"
    },
    "InstanceType": {
        "AllowedValues": [
            "t2.micro",
            "t2.small",
            "t2.medium",
            "t2.large",
            "c4.large",
            "c4.xlarge",
            "c4.2xlarge",
            "c4.4xlarge",
            "c4.8xlarge",
            "t3.medium"
        ],
        "ConstraintDescription": "must be a valid EC2 instance type",
        "Default": "t2.micro",
        "Description": "EC2 instance type",
        "Type": "String"
    },
    "KeyName": {
        "Description" : "Name of an existing EC2 KeyPair to enable SSH access to NAT instances.",
                    "Type": "AWS::EC2::KeyPair::KeyName",
                    "ConstraintDescription" : "Must be the name of an existing EC2 KeyPair."        }

},
"Resources": {
     "InstanceProfile" : {
         "Type" : "AWS::IAM::InstanceProfile",
                "Properties" : {
                        "Path" : "/",
                                "Roles" : ["Ec2CloudDeploy"]
                                        }
                                            },
    "StageSecurityGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            "GroupDescription": "Allow SSH, HTTP, and HTTPS access",
            "SecurityGroupIngress": [
                {
                    "IpProtocol": "tcp",
                    "FromPort": "22",
                    "ToPort": "22",
                    "CidrIp": "0.0.0.0/0"
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": "80",
                    "ToPort": "80",
                    "CidrIp": "0.0.0.0/0"
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": "443",
                    "ToPort": "443",
                    "CidrIp": "0.0.0.0/0"
                }
            ]
        }
    },
 "StageInstance": {
        "Type" : "AWS::EC2::Instance",

        "Properties": {
            "SecurityGroupIds": [{"Ref": "StageSecurityGroup"}],
            "KeyName": {"Ref": "KeyName" },
            "ImageId": {"Ref": "AMI"},
            "InstanceType": {"Ref": "InstanceType"},
            "IamInstanceProfile" : {"Ref" : "InstanceProfile"},
            "Tags": [
                {"Key" : "Staging", "Value" : "Staging"}
            ]

 }
  }
 }
}

有没有什么配置可以给这个实例启动的实例附加弹性ip,我知道可以通过cli命令buT来附加,我想通过我的cloudformation模板来添加。

EN

回答 2

Stack Overflow用户

发布于 2019-09-12 19:17:18

您将使用AWS::EC2::EIPAssociation

代码语言:javascript
复制
{
  "Type" : "AWS::EC2::EIPAssociation",
  "Properties" : {
      "AllocationId" : String,
      "EIP" : String,
      "InstanceId" : String,
      "NetworkInterfaceId" : String,
      "PrivateIpAddress" : String
    }
}
票数 1
EN

Stack Overflow用户

发布于 2020-05-12 16:29:15

好的。如AWS::EC2::EIP中所述:

亚马逊指定弹性IP (

)地址,并可以选择将其与亚马逊EC2实例相关联。

通过设置InstanceId,您可以将弹性公网EIP关联到CloudFormation的EC2实例。

对于您的情况,下面的代码片段应该可以解决这个问题:

代码语言:javascript
复制
"Resources": {
    ...,
    "ElasticIP": {
        "Type": "AWS::EC2::EIP",
        "Properties": {
            "InstanceId": {"Ref" : "StageInstance"}
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57901148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档