无服务器/ Cloudformation资源依赖于另一个资源的存在

时间:2018-04-23 23:35:27

标签: amazon-web-services amazon-cloudformation serverless-framework

我尝试使用无服务器框架部署输出到 ElasticSearch 域的 Kinesis Firehose

由于Firehose在创建之前需要ES域已经存在,所以我遇到了这个错误:

  

发生错误:MyFirehoseStream - Domain   arn:aws:es:us-east-1:1234567890:domain / my-elastic-search仍然是   被创造。

有没有办法让Firehose创建等到ES域创建完成之后?

以防万一有用,以下是我的serverless.yml文件的相关部分:

fyi,我使用serverless-pseudo-parameters插件来使用#{AWS::Region}#{AWS::AccountId}

resources:
  Resources:
    MyFirehoseStream:
      Type: "AWS::KinesisFirehose::DeliveryStream"
      Properties:
        DeliveryStreamName: "MyFirehoseStream"
        DeliveryStreamType: "DirectPut"
        ElasticsearchDestinationConfiguration:
          BufferingHints:
            IntervalInSeconds: 300
            SizeInMBs: 5
          DomainARN:  "arn:aws:es:#{AWS::Region}:#{AWS::AccountId}:domain/my-elastic-search"
          IndexName: "myindex"
          IndexRotationPeriod: "NoRotation"
          RetryOptions:
            DurationInSeconds: 300
          RoleARN: { "Fn::GetAtt": ["FirehoseBackupBucketRole", "Arn" ] }
          S3BackupMode: "FailedDocumentsOnly"
          S3Configuration:
            BucketARN: { "Fn::GetAtt": ["FirehoseBackupBucket", "Arn" ] }
            BufferingHints:
              IntervalInSeconds: 300
              SizeInMBs: 5
            CompressionFormat: "GZIP"
            RoleARN: { "Fn::GetAtt": ["FirehoseBackupBucketRole", "Arn" ] }
          TypeName: "mytype"

    MyElasticSearch:
      Type: "AWS::Elasticsearch::Domain"
      Properties:
        AccessPolicies: ${file(./iam_policies/elastic-search.json)}
        DomainName: "my-elastic-search"
        ElasticsearchVersion: 6.2
        ElasticsearchClusterConfig:
          InstanceCount: "1"
          InstanceType: "t2.small.elasticsearch"
        EBSOptions:
          EBSEnabled: true
          Iops: 0
          VolumeSize: 10
          VolumeType: "gp2"

更新

我现在已修复此问题,以防具体情况对任何人都有帮助:

我将DomainARN属性更改为{ "Fn::GetAtt": ["MyElasticSearch", "DomainArn" ] }

我最初动态生成ARN的原因是因为"Fn::GetAtt"我最初只尝试使用Arn代替DomainArn,但这并不起作用。巧合的是,DomainArn已在最新版本中弃用,因此如果您使用的是最新版本,Arn实际上是正确的。

1 个答案:

答案 0 :(得分:2)

Cloudformation资源支持DependsOn属性。

resources: Resources: MyFirehoseStream: Type: "AWS::KinesisFirehose::DeliveryStream" DependsOn: MyElasticSearch

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html