Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 使用cloudformation向ec2实例添加弹性IP_Amazon Web Services_Amazon Cloudformation - Fatal编程技术网

Amazon web services 使用cloudformation向ec2实例添加弹性IP

Amazon web services 使用cloudformation向ec2实例添加弹性IP,amazon-web-services,amazon-cloudformation,Amazon Web Services,Amazon Cloudformation,在哪里我可以从我的cloudformation模板附加弹性ip { "Description" : "Staging single instance", "Outputs": { "InstanceID": { "Description": "The WWW instance id", "Value": { "Ref": "StageInstance" } } }, "Parameters": { "AMI": { "Des

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

{
"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命令连接它,但我希望通过我的cloudformation模板添加它。

您将使用:

当然。如以下文件所述:

指定弹性IP EIP地址,并可以(可选)将其与Amazon EC2实例关联

通过设置InstanceId,可以将EIP与CloudFormation的EC2实例相关联

对于您的情况,此代码段应该起到以下作用:

"Resources": {
    ...,
    "ElasticIP": {
        "Type": "AWS::EC2::EIP",
        "Properties": {
            "InstanceId": {"Ref" : "StageInstance"}
        }
    }
}
可能重复的
"Resources": {
    ...,
    "ElasticIP": {
        "Type": "AWS::EC2::EIP",
        "Properties": {
            "InstanceId": {"Ref" : "StageInstance"}
        }
    }
}