在验证时,使用“Fn :: Base64”和“Fn :: Join”解析YAML代码中的错误

时间:2016-09-05 09:11:12

标签: parsing amazon-web-services yaml

我在验证以下YAML代码时遇到问题,因为我无法解析Fn::Base64Fn::Join。我该如何解决这个问题?

AWSTemplateFormatVersion: "2010-09-09"
Description: "test e2 ebs in vpc"
Parameters: 
  KeyPairName: 
    Description: "Public/private key pairs allow you to securely connect to your instance after it launches"
    Type: "AWS::EC2::KeyPair::KeyName"
  VPC: 
    Description: "ID of the VPC (e.g., vpc-0343606e)"
    Type: AWS::EC2::VPC::Id"
  myWSFCNode1InstanceType: 
    ConstraintDescription: "Only EBS Optimized instance types r3.xlarge, r3.2xlarge, r3.4xlarge allowed"
    Default: t2.small
    Description: "Amazon EC2 instance type for the 1st WSFC Node"
    Type: String
Resources: 
  myWSFCNode1: 
    CreationPolicy: 
      ResourceSignal: 
        Count: "1"
        Timeout: PT15M
    Properties: 
      BlockDeviceMappings: 
      -  DeviceName: /dev/sda1
      Ebs: 
          VolumeSize: "100"
          VolumeType: gp2
      ImageId: ami-fd9cecc7
      InstanceType: 
        Ref: myWSFCNode1InstanceType
      KeyName: 
        Ref: KeyPairName
      SecurityGroupIds: 
        - 
          Ref: myWSFCSecurityGroup
      UserData: 
            ? "Fn::Base64"
            : 
            ? "Fn::Join"
            : 
            - ""
            - 
    Type: "AWS::EC2::Instance"
  myWSFCNode1Volume1: 
    Properties: 
      Size: 50
    Type: "AWS::EC2::Volume"
  myWSFCSecurityGroup: 
    Properties: 
      GroupDescription: "Enable the WSFC and SQL AlwaysOn Availability Group communications"
      SecurityGroupIngress: 
        - 
          CidrIp: 0.0.0.0/0
          FromPort: "22"
          IpProtocol: tcp
          ToPort: "22"
      VpcId: Ref: VPC
    Type: "AWS::EC2::SecurityGroup"
  mySystemGroup: "ec2SG"

3 个答案:

答案 0 :(得分:0)

此部分无效YAML:

UserData:
      ? "Fn::Base64"
      : 
      ? "Fn::Join"
      : 
      - ""
      - 

?:表示显式映射键和值。这使得UserData的值成为YAML映射。然后,有两个用-表示的序列项。 YAML映射中不能有任何序列项,因此解析器失败。

根据您的要求,以下是一些可能符合您要求的更改:

  1. 将序列作为映射中的值:
  2. ? "Fn::Base64"
    : 
    ? "Fn::Join"
    : 
      - ""
      - 
    
    1. 将两个序列项转换为另一个键值对:
    2. ? "Fn::Base64"
      : 
      ? "Fn::Join"
      : 
      ? ""
      :
      

      请注意,YAML允许在某些情况下省略空值,因此您可以将1.浓缩为:

      ? "Fn::Base64" 
      ? "Fn::Join"
      : 
        -
        -
      

      并且2.进入:

      ? "Fn::Base64"
      ? "Fn::Join"
      ?
      

答案 1 :(得分:0)

您的YAML文件只有一个错误,即行:

      VpcId: Ref: VPC

可能应该是:

      VpcId: "Ref: VPC"

因为您不能在非引用字符串中使用:,或者可能:

      VpcId: 
        Ref: VPC

如果在纠正上述内容后,您的解析器不接受Fn::Base64字符串,那么您应该升级解析器。

答案 2 :(得分:0)

感谢各位大家帮助我。我在代码中修改了以下更改。

  UserData: 
        ? "Fn::Base64":
        ? "Fn::Join":
        - ""
        -