如何将 VPC 的 ID 作为参数传递给 Cluster.template 以设置为默认值?
How to pass a VPC's ID as a parameter to the Cluster.template to set as a default value?
我正在尝试找到一种在 Cluster.template JSON 文件中设置默认 VPC、子网和安全组的方法。
有没有办法使用 "Ref" 内置函数将现有 VPC(或 Subnet/Security 组)作为参数传递给模板?
这显然行不通:
"Parameters": {
"VpcId": {
"Type": "AWS::EC2::VPC::Id",
"Default": { "Ref" : "vpc-123456789" },
....
}
要将 VPC id 注入您的模板,我将执行以下操作。首先删除您的默认值。
"Parameters": {
"VpcId": {
"Type": "AWS::EC2::VPC::Id"
....
}
接下来将要设置 VpcId 的值放入 parameters.json 文件中,当您使用 cloudformation 执行创建堆栈或更新堆栈时,使用参数文件作为输入。
parameters.json
[
{
"ParameterKey": "VpcId",
"ParameterValue": "vpc-123456789"
}
]
多值参数
如果您有一个接受值列表的参数,您可以如下表示它
"PrivateEC2Subnets": {
"Type": "CommaDelimitedList",
"Description": "List of private subnets to run your EC2 instances inside. Note that they must be in the same availability zone that your ELB is configured for. May require you to manually create a private subnet with a specific AZ if your VPC isnt auto-configured."
},
然后在你的外部参数文件中传递一个逗号分隔的列表,就像这样
{
"ParameterKey": "PrivateEC2Subnets",
"ParameterValue": "subnet-9934670a544,subnet-d74ea349f"
},
有关不同参数类型的更多信息,请参阅 AWS 文档 http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html 但请注意,人们在尝试在外部参数文件中表示复杂数据类型列表时报告了问题。据我所知,如果您想从 cloudformation 模板之外的另一个 json 文件传入值,则只有 CommaDelimitedList 有效。
我发现它真的比我想象的要简单得多...这有效:
"Parameters": {
"VpcId": {
"Type": "List<AWS::EC2::VPC::Id>",
"Default": "vpc-123456789,vpc-987654123" ,
....
}
我正在尝试找到一种在 Cluster.template JSON 文件中设置默认 VPC、子网和安全组的方法。
有没有办法使用 "Ref" 内置函数将现有 VPC(或 Subnet/Security 组)作为参数传递给模板?
这显然行不通:
"Parameters": {
"VpcId": {
"Type": "AWS::EC2::VPC::Id",
"Default": { "Ref" : "vpc-123456789" },
....
}
要将 VPC id 注入您的模板,我将执行以下操作。首先删除您的默认值。
"Parameters": {
"VpcId": {
"Type": "AWS::EC2::VPC::Id"
....
}
接下来将要设置 VpcId 的值放入 parameters.json 文件中,当您使用 cloudformation 执行创建堆栈或更新堆栈时,使用参数文件作为输入。
parameters.json
[
{
"ParameterKey": "VpcId",
"ParameterValue": "vpc-123456789"
}
]
多值参数
如果您有一个接受值列表的参数,您可以如下表示它
"PrivateEC2Subnets": {
"Type": "CommaDelimitedList",
"Description": "List of private subnets to run your EC2 instances inside. Note that they must be in the same availability zone that your ELB is configured for. May require you to manually create a private subnet with a specific AZ if your VPC isnt auto-configured."
},
然后在你的外部参数文件中传递一个逗号分隔的列表,就像这样
{
"ParameterKey": "PrivateEC2Subnets",
"ParameterValue": "subnet-9934670a544,subnet-d74ea349f"
},
有关不同参数类型的更多信息,请参阅 AWS 文档 http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html 但请注意,人们在尝试在外部参数文件中表示复杂数据类型列表时报告了问题。据我所知,如果您想从 cloudformation 模板之外的另一个 json 文件传入值,则只有 CommaDelimitedList 有效。
我发现它真的比我想象的要简单得多...这有效:
"Parameters": {
"VpcId": {
"Type": "List<AWS::EC2::VPC::Id>",
"Default": "vpc-123456789,vpc-987654123" ,
....
}