amazon-web-services - 如何仅将私有(private)IP分配给EC2实例?

标签 amazon-web-services amazon-ec2 aws-cloudformation

下面是在公共(public)子网中创建EC2实例的cloudformation代码,取自here :

"EC2Instance":{ "Type": "AWS::EC2::Instance", "Properties":{ "ImageId": "ami-05958d7635caa4d04", "InstanceType": "t2.micro", "SubnetId": { "Ref": "SubnetId"}, "KeyName": { "Ref": "KeyName"}, "SecurityGroupIds": [ { "Ref": "EC2InstanceSecurityGroup"} ], "IamInstanceProfile": { "Ref" : "EC2InstanceProfile"}, "UserData":{ "Fn::Base64": { "Fn::Join": ["", [ "#!/bin/bash\n", "echo ECS_CLUSTER=", { "Ref": "EcsCluster" }, " >> /etc/ecs/ecs.config\n", "groupadd -g 1000 jenkins\n", "useradd -u 1000 -g jenkins jenkins\n", "mkdir -p /ecs/jenkins_home\n", "chown -R jenkins:jenkins /ecs/jenkins_home\n" ] ] } }, "Tags": [ { "Key": "Name", "Value": { "Fn::Join": ["", [ { "Ref": "AWS::StackName"}, "-instance" ] ]} }] } },

默认情况下,公共(public) IP 被分配给 EC2 实例:

如何让EC2实例只分配私有(private)IP?

最佳答案

这个很简单。

AssociatePublicIpAddress设置为false

"Ec2Instance" : {
  "Type" : "AWS::EC2::Instance",
  "Properties" : {
    "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
    "KeyName" : { "Ref" : "KeyName" },
    "NetworkInterfaces": [ {
      "AssociatePublicIpAddress": false,
      "DeviceIndex": "0",
      "GroupSet": [{ "Ref" : "myVPCEC2SecurityGroup" }],
      "SubnetId": { "Ref" : "PublicSubnet" }
    } ]
  }
}

引用: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html

关于amazon-web-services - 如何仅将私有(private)IP分配给EC2实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59573313/

相关文章:

amazon-web-services - CloudFormation cfn-init 表示用户数据脚本成功/失败

amazon-web-services - 无法使用 AWS CloudFormation 模板在 Amazon EC2 上通过 Gremlin Server 启动 DynamoDB Storage Backend for Titan

authentication - 我可以以编程方式创建 AWS Cognito 用户登录吗?

amazon-web-services - 无法在 EC2 实例上挂载 EFS; 'connection timed out' 错误

internet-explorer - 为什么 MTurk 沙盒仅在 Internet Explorer 中显示我的 HIT?

amazon-web-services - AWS Cloudformation 如何将日志从 CloudWatch Logs 发送到 S3

python - 带有 Lambda 自定义资源的 Cloudformation 错误 - Python

django - 如何设置运行Django的AWS Elastic Beanstalk Docker平台?

linux - 安装 JBoss AS7 时出现错误 "initializing endpoint: java.net.BindException: Address already in use/127.0.0.1:8080"

java - 如果部署在 N 个实例上,如何只在一个实例上运行夜间作业?