首页 > 解决方案 > aws cloudformation 弹性搜索堆栈

问题描述

我编写了以下模板来根据用户输入选择环境。但是我收到错误,因为“调用 CreateStack 操作时发生错误(ValidationError):模板格式错误:[/Resources/Type] 资源定义格式错误”。请指导我需要更改的内容以及语法是否格式正确.

    AWSTemplateFormatVersion: 2010-09-09
      Parameters:
          EnvironmentValue:
             AllowedValues:
               - PROD
               - TEST
             Description: 'Please select an Environment'
             Type: String
      Mappings:
          Environment:
             PROD:
                VPC: vpc-xxxxxxxx
                Subnets: 'subnet-xxxxx,subnet-xxxxx,subnet-xxxx'
                Securitygroups: 'sg-xxxx,sg-xxxx'

             TEST:
                VPC: vpc-xxxxx
                Subnets: 'subnet-xxxx,subnet-xxxxx'
                Securitygroups: 'sg-xxxx,sg-xxxxx'
       #Conditions:
       #    CreatePRODStack: !Equals [!Ref EnvironmentValue, PROD]
       #    CreateTESTStack: !Equals [!Ref EnvironmentValue, TEST]
       Resources:
          Type: 'AWS::Es:Domain'
             Properties:
               DomainName: EPD34
               ElasticsearchVersion: 6.5
               ElasticsearchClusterConfig:
                   DedicatedMasterEnabled: 'true'
                   InstanceCount: '2'
                   ZoneAwarenessEnabled: 'true'
                   InstanceType: r4.xlarge.elasticsearch
                   DedicatedMasterType: r4.xlarge.elasticsearch
                   DedicatedMasterCount: '2'
               EBSOptions:
                   EBSEnabled: true
                   Iops: 0
                   VolumeSize: 100
                   VolumeType: gp2
               VPCOptions: !FindInMap [Environment, !Ref 'EnvironmentValue', VPC]
               SubnetIds: !FindInMap [Environment, !Ref 'EnvironmentValue', Subnets]
               Securitygroups: !FindInMap [Environment, !Ref 'EnvironmentValue', Securitygroups]
               SnapshotOptions:
                      AutomatedSnapshotStartHour: '0'
          Type: 'AWS::IAM::Policy'
              Properties: 
                  PolicyDocument: YAML
                  PolicyName: prodtest

当用户以 Prod 形式提供输入时,应在 Cloudformation 中创建 Prod 的堆栈

标签: amazon-web-serviceselasticsearchyamlamazon-cloudformation

解决方案


我在这里看到了一些问题:

1 - 您尚未命名您的资源。2 - 您的缩进看起来不正确,这对 yaml 3 很重要 - 我相信您的 Elasticsearch 域的类型不正确。你有

Type: 'AWS::Es:Domain'

但我认为应该是

Type: AWS::Elasticsearch::Domain

以您的域为例,我认为它应该更符合以下方面:

ElasticsearchDomain:
    Type: AWS::Elasticsearch::Domain
    Properties:
        DomainName: EPD34
        ElasticsearchVersion: 6.5
        ElasticsearchClusterConfig:
            DedicatedMasterEnabled: 'true'
            InstanceCount: '2'
            ZoneAwarenessEnabled: 'true'
            InstanceType: r4.xlarge.elasticsearch
            DedicatedMasterType: r4.xlarge.elasticsearch
            DedicatedMasterCount: '2'
        EBSOptions:
            EBSEnabled: true
            Iops: 0
            VolumeSize: 100
            VolumeType: gp2
        VPCOptions: !FindInMap [Environment, !Ref 'EnvironmentValue', VPC]
        SubnetIds: !FindInMap [Environment, !Ref 'EnvironmentValue', Subnets]
        Securitygroups: !FindInMap [Environment, !Ref 'EnvironmentValue', Securitygroups]
        SnapshotOptions:
            AutomatedSnapshotStartHour: '0'

我可能在这里遗漏了其他问题,但这里肯定有语法错误

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticsearch-domain.html


推荐阅读