aws cloudformation 弹性搜索堆栈

Posted

技术标签:

【中文标题】aws cloudformation 弹性搜索堆栈【英文标题】:aws cloudformation elasticsearch stack 【发布时间】:2019-10-03 05:13:12 【问题描述】:

我编写了以下模板来根据用户输入选择环境。但是我收到错误,因为“调用 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 的堆栈

【问题讨论】:

【参考方案1】:

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

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

【讨论】:

【参考方案2】:

类型标签应为“AWS::Elasticsearch::Domain”,并且根据 yaml 声明存在多个格式错误。属性应与类型处于同一级别。那么 VPCOptions 后面应该有两个属性。对于给定的示例,模板应如下所示

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:
  ElasticSearchCluster:
        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: 
                SubnetIds: !FindInMap [Environment, !Ref 'EnvironmentValue', Subnets]
                Securitygroups: !FindInMap [Environment, !Ref 'EnvironmentValue', Securitygroups]
            SnapshotOptions:
                AutomatedSnapshotStartHour: '0'

    IAMPolicyEntry:             
        Type: 'AWS::IAM::Policy'
        Properties: 
            PolicyDocument: YAML
            PolicyName: prodtest 

【讨论】:

点评来源: 嗨,这篇文章似乎没有为问题提供quality answer。请编辑您的答案并提供示例/更多详细信息,或者将其作为对问题的评论发布。

以上是关于aws cloudformation 弹性搜索堆栈的主要内容,如果未能解决你的问题,请参考以下文章

AWS Cloudformation:如何在 AWS 弹性 beanstalk 配置中引用多个安全组

在多个区域启动 AWS cloudformation 堆栈

AWS Amplify:如何重新创建手动删除的 CloudFormation 堆栈

AWS CLI 与控制台和 CloudFormation 堆栈

AWS cloudFormation LAMP 堆栈失败

如何修复漂移的 AWS CloudFormation 堆栈?