CloudFormation:属性SsmAssociations的值必须为列表类型

时间:2018-11-19 19:48:17

标签: amazon-web-services amazon-ec2 yaml amazon-cloudformation

我正在为EC2实例创建CloudFormation模板,该模板将用于管理已经在VPC中部署的Active Directory服务器。定义AWS::EC2::Instance资源时遇到问题。可能是YAML语法问题,但我无法看到问题。

创建堆栈时,它将回滚,并显示错误“属性SsmAssociations的值必须为List类型”。就示例而言,文档有些稀疏。 Amazon EC2 Instance SsmAssociations

以下是有问题的YAML代码段:

Resources: 
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      IamInstanceProfile: !Ref InstanceProfile
      SsmAssociations:
        DocumentName: !Ref InstanceProfile
        AssociationParameters:
          -
            Key: "directoryId"
            Value: 
              - 
                Fn::ImportValue:
                  Fn::Join:
                  - ''
                  - - !Ref ADStackName
                    - '-'
                    - 'DirectoryId'
          - 
            Key: "directoryName"
            Value: 
              - 
                Fn::ImportValue:
                  Fn::Join:
                  - ''
                  - - !Ref ADStackName
                    - '-'
                    - 'DirectoryName'
          - 
            Key: "dnsIpAddresses"
            Value:
              - 
                Fn::ImportValue:
                  Fn::Join:
                  - ''
                  - - !Ref ADStackName
                    - '-'
                    - 'ADServer1PrivateIP'
              - 
                Fn::ImportValue:
                  Fn::Join:
                  - ''
                  - - !Ref ADStackName
                    - '-'
                    - 'ADServer2PrivateIP'
      KeyName: !Ref EC2KeyPair 

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

根据AWS::EC2::Instance的文档,指出SsmAssociations具有

  

类型:Amazon EC2实例SsmAssociations的列表。

(这也是您的错误消息指出的内容)。但是,在YAML声明中,您提供了一个SsmAssociations。尝试将其更改为以下内容:

Resources: 
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      IamInstanceProfile: !Ref InstanceProfile
      SsmAssociations:
        # Notice the addition of the "-" on the line below to declare a yaml list
        - 
          DocumentName: !Ref InstanceProfile
          AssociationParameters:
          # add the rest of the declaration