cloudformation错误-属性SubnetIds的值必须为字符串列表类型

时间:2019-11-30 21:45:02

标签: amazon-cloudformation

当我运行create-stack时,由于创建弹性搜索域而失败,并出现以下错误-“属性SubnetIds的值必须为字符串列表类型” 这是CF模板的代码段...

Parameters:
  SubnetIds:
    Type: 'List<AWS::EC2::Subnet::Id>'
    Description: Select a VPC subnet to place the instance. Select Multiple Subnets for multi-AZ deployments

Resources:
  ElasticsearchDomain:
    Type: 'AWS::Elasticsearch::Domain'
    Properties:
      AccessPolicies:
        Version: '2012-10-17'
        Statement:
        - Effect: Allow
          Principal:
            AWS: '*'
          Action:
          - 'es:ESHttp*'
          Resource: !Sub 'arn:aws:es:${AWS::Region}:${AWS::AccountId}:domain/${DomainName}/*'
      DomainName: !Ref 'DomainName'
      EBSOptions:
        EBSEnabled: !Ref EBSEnabled
        VolumeSize: !Ref EBSVolumeSize
        VolumeType: gp2
      ElasticsearchClusterConfig:
        DedicatedMasterCount: !If [HasDedicatedMasterNodes, !Ref DedicatedMasterCount, !Ref 'AWS::NoValue']
        DedicatedMasterEnabled: !If [HasDedicatedMasterNodes, true, false]
        DedicatedMasterType: !If [HasDedicatedMasterNodes, !Ref DedicatedMasterType, !Ref 'AWS::NoValue']
        InstanceCount: !Ref ClusterInstanceCount
        InstanceType: !Ref ClusterInstanceType
        ZoneAwarenessEnabled: !If [HasSingleClusterInstance, false, true]
      ElasticsearchVersion: !Ref ElasticsearchVersion
      EncryptionAtRestOptions: !If [HasKmsKey, {Enabled: true, KmsKeyId: !Ref KMSEncryptionKey}, !Ref 'AWS::NoValue']
      SnapshotOptions:
        AutomatedSnapshotStartHour: 0
      VPCOptions:
        SecurityGroupIds:
        - !Ref SecurityGroup
        SubnetIds:
        - !Ref SubnetIds

也尝试过这种方法,但是不起作用-

        SubnetIds:
        - [!Ref SubnetIds]

2 个答案:

答案 0 :(得分:0)

尝试使用以下代码段:

  VPCOptions:
    SubnetIds: !Ref ESSubnetsID
    SecurityGroupIds: !Ref ESSecurityGroup

并使用以下命令更新参数部分:

  ESSubnetsID:
    Description: Choose which subnets the Elasticsearch should use
    Type: 'List<AWS::EC2::Subnet::Id>'
    Default: 'subnet-1,'subnet-2'
  ESSecurityGroup:
    Description: Select the Security Group to use for the Elasticsearch cluster
    Type: 'List<AWS::EC2::SecurityGroup::Id>'
    Default: 'sg-1,sg-2'

确保您传递列表子网ID。

答案 1 :(得分:0)

就像错误消息所述,SubnetIds应该是字符串列表,而不是您在params部分中定义的List<AWS::EC2::Subnet::Id>。正确地将其重新定义为List<String>,它将起作用。

Parameters:
  SubnetIds:
    Type: 'List<String>'