amazon-web-services - 使用 Cloudformation 脚本创建 ec2 时如何分配特定的私有 ip(基于我的 CIDR 和子网的预先确定的 ip)
问题描述
这是我使用的代码,仍然无法正常工作。我正在尝试使用 CloudFormation 模板创建即时,并使用特定的私有 IP 地址启动。请帮助我缺少什么:我会在哪里提到我需要将其分配给 CloudFormation 模板中的即时的私有 ip?
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"KeyName" : { "Ref" : "KeyName" },
"NetworkInterfaces": [ {
"DeviceIndex": "0",
"PrivateIpAddress" : String,
} ]
}
}```
解决方案
PrivateIpAddress
是您指定私有IP的地方。最好还指定SubnetId
您的 IP 必须与您放置实例的子网的 CIDR 范围相匹配。
例子:
InstanceWithFixedPirivateIp:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-07ebfd5b3428b6f4d
InstanceType: t2.micro
Monitoring: false
NetworkInterfaces:
- DeviceIndex: 0
PrivateIpAddress: 172.31.80.12
SubnetId: subnet-a9e16487 # CIDR 172.31.80.0/20
推荐阅读
- typescript - 将 Axios 与 TypeScript 一起使用的正确方法
- java - 无法从 URL Java 获取特定图像
- javascript - 从内容脚本注入表单提交数据(chrome 扩展)
- laravel - 在 RESTful API 中创建依赖资源
- php - PHP 对象数组,里面有数组。合并这些
- protractor - 我们可以使用量角器工具自动化非英语网站吗
- regex - 使用正则表达式捕获多值
- python - 如何单击按钮以播放与条目小部件中的文本输入相关的不同声音?
- ssl - 如何在使用 openssl 的专用网络上的服务器上启用 SSL?
- elasticsearch - 用于类似于拆分的带状疱疹的 Elasticsearch 处理器?