【问题标题】:Serverless/Cloudformation resource that depends on the existence of another resourceServerless/Cloudformation 资源依赖于另一个资源的存在
【发布时间】:2018-04-24 09:52:45
【问题描述】:

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

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

发生错误:MyFirehoseStream - 域 arn:aws:es:us-east-1:1234567890:domain/my-elastic-search 仍然是 正在创建中。

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


以防万一,这里是我的serverless.yml 文件的相关部分:

仅供参考,我正在使用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 实际上是正确的。

【问题讨论】:

  • 请将您的答案作为实际答案发布,而不是作为问题编辑; Stack Overflow 明确支持自答问题。

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


【解决方案1】:

Cloudformation 资源支持DependsOn 属性。

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

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

【讨论】:

  • 谢谢,这似乎是正确的,但我想指出,就我而言,我实际上并不需要DependsOn。在您链接到的文档中,它解释了“隐式依赖项”,最终对我有用。我只需要引用其他资源的 ARN。
猜你喜欢
  • 2017-10-10
  • 1970-01-01
  • 2018-03-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-26
  • 2020-01-17
  • 2021-04-16
  • 2020-01-10
相关资源
最近更新 更多