amazon-web-services - Cloudformation AWS:使用参数将 IP 地址分配给 CustomerGateway
问题描述
我正在设计一个cloudformation模板,但我需要将源IP定义为参数
我试图将参数定义为字符串,但它会产生以下错误:
Value (${MyCustomerGateway}) for parameter ipAddress is invalid. Invalid Format. (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterValue; Request ID: 4de02112-fb1f-47a1-931c-97727568df99)
这是模板的片段:
Parameters:
MyCustomerGateway:
Description: IpAddress.
Default: 0.0.0.0
Type: String
Resources:
CustomerGateway_1:
Type: 'AWS::EC2::CustomerGateway'
Properties:
Type: ipsec.1
BgpAsn: 3352
IpAddress: ${MyCustomerGateway}
Tags:
- Key: Name
Value: CustomerGateway_1
IP翻译有什么特殊数据吗?
我不确定哪个是正确的方法
解决方案
更改IpAddress: ${MyCustomerGateway}
为IpAddress: !Ref myCustomerGateway
更多关于参考:
内部函数 Ref 返回指定参数或资源的值。
> 当您指定参数的逻辑名称时,它会返回参数的值。
当您指定资源的逻辑名称时,它会返回一个值,您通常可以使用该值来引用该资源,例如物理 ID。
奖金:
如果要验证参数输入,可以使用该AllowedPattern
属性。
用法:
PrimaryIPAddress:
Type: String
Description: This must be a valid IP address.
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})
ConstraintDescription: must be a valid IP address of the form x.x.x.x.
输入无效IP时出错:
推荐阅读
- python - 根据 3 个变量的颜色 - 麦克斯韦三角形
- c - 从文件读取时联合导致分段错误
- javascript - 在 Javascript 中使用循环创建 HTML 列表
- reactjs - fetch 包无法从 API 中获取任何数据
- python-3.x - 为什么程序给我错误的答案或“RecursionError:比较超出最大递归深度”?我能做些什么?
- javascript - 使用 Indesign 脚本重新排序/移动页面
- azure-data-factory - Azure 数据工厂活动“dependsOn”中的多个失败依赖项
- android - android谷歌地图json中的标记
- webdriver - 启动测试时如何将浏览器作为命令行参数传递
- javascript - 堆叠地图样式(谷歌地图 API)