【发布时间】:2017-09-19 00:11:47
【问题描述】:
我正在尝试创建一个接受可选 SSH 密钥对作为参数的 CloudFormation 模板。我想使用 AWS::EC2::KeyPair::KeyName 类型,因此 CloudFormation 界面为用户提供了可用键的列表,如图所示。
我遇到的问题是可选部分。如果用户将选择留空,则使用默认值但不认为是有效的。我明白了:
Parameter validation failed: parameter value for parameter name SSHKey does not exist. Rollback requested by user.
有没有办法定义一个可以留空但具有非泛型类型的参数?
这是一个显示问题的示例模板:
{
"Parameters": {
"SSHKey": {
"Type": "AWS::EC2::KeyPair::KeyName",
"Description": "Leave empty to disable SSH",
"Default": ""
}
},
"Conditions": {
"EnableSSH": {
"Fn::Not": [
{
"Fn::Equals": [
"",
{
"Ref": "SSHKey"
}
]
}
]
}
},
"Resources": {
"LaunchConfig": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"ImageId": "ami-9eb4b1e5",
"InstanceType": "t2.micro",
"KeyName": {
"Fn::If": [
"EnableSSH",
{
"Ref": "SSHKey"
},
{
"Ref": "AWS::NoValue"
}
]
},
"BlockDeviceMappings": [
{
"DeviceName": "/dev/xvda",
"Ebs": {
"VolumeSize": "8"
}
}
]
}
}
}
}
【问题讨论】:
标签: amazon-web-services amazon-cloudformation