我正在尝试创建一个接受可选 SSH 密钥对作为参数的 CloudFormation 模板。我想使用该AWS::EC2::KeyPair::KeyName类型,以便 CloudFormation 界面为用户提供可用键的列表,如图所示。
我遇到的问题是可选部分。如果用户将选择留空,则将使用默认值,但不被视为有效。我得到:
Parameter validation failed: parameter value for parameter name SSHKey does not exist. Rollback requested by user.
Run Code Online (Sandbox Code Playgroud)
有没有办法定义一个可以留空但具有非泛型类型的参数?
这是显示问题的示例模板:
{
"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": [ …Run Code Online (Sandbox Code Playgroud)