问题描述
最近我开始使用 YAML 学习 Cloud Formation。我的密钥对为 CFNkey、Newkey1、Newkey2。 Here is an image。所以我的疑问是,如果我尝试使用 Type as String 作为密钥对,我会得到 this error message。我使用的YAML代码如下:-
AWstemplateFormatVersion: 2010-09-09
Description: Parameter using the Dynamic KeyName
Parameters:
MyKeyName:
Description: Select the key Name from the below
Type: String
Default: Newkey1
AllowedValues:
- CFNkey
- Newkey2
Resources:
DevEC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-04aa88aebb9fefd83
KeyName: !Ref MyKeyName
SecurityGroup:
- !Ref SSHSecurityGroup
SSHSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: My Sg
SecurityIngress:
IpProtocol: tcp
ToPort: 22
FromPort: 22
Cidr: 0.0.0.0/0
SecurityEgress:
IpProtocol: tcp
ToPort: 8080
FromPort: 8080
Cidr: 0.0.0.0/0
解决方法
您的 Newkey1
必须列在 AllowedValues
中:
MyKeyName:
Description: Select the key Name from the below
Type: String
Default: Newkey1
AllowedValues:
- Newkey1
- CFNkey
- Newkey2