微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我们不能使用 CloudFormation 中的参数将 AllowedValues 用于密钥对作为字符串?

如何解决为什么我们不能使用 CloudFormation 中的参数将 AllowedValues 用于密钥对作为字符串?

最近我开始使用 YAML 学习 Cloud Formation。我的密钥对为 CFNkey、Newkey1、Newkey2Here 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。