如何将 OpenSearch/Elasticsearch 设置为 Kinesis Firehose 的目的地?

发布于 2025-01-19 14:29:40 字数 2751 浏览 4 评论 0 原文

我正在尝试创建数据流 ->消防水带 ->使用 AWS CDK v2 的 OpenSearch 基础设施。我惊讶地发现,尽管 OpenSearch 是受支持的 Firehose 目标,但 CDK 中没有任何内容支持此用例。

在我的 CDK 堆栈中,我创建了一个 OpenSearch ,并且正在尝试创建 Kinesis Firehose DeliveryStream 以该域作为目的地。但是,kinesisfirehose-destinations 包似乎只有一个随时可用的 S3 存储桶的目标,因此没有明显的方法可以轻松使用仅使用 aws-cdk 提供的构造,甚至不使用 alpha 包。

我认为我应该能够通过实现 IDestination.我尝试了以下简单的实现:

import {Construct} from "constructs"
import * as firehose from "@aws-cdk/aws-kinesisfirehose-alpha"
import {aws_opensearchservice as opensearch} from "aws-cdk-lib"

export class OpenSearchDomainDestination implements firehose.IDestination {
  private readonly dest: opensearch.Domain

  constructor(dest: opensearch.Domain) {
    this.dest = dest
  }

  bind(scope: Construct, options: firehose.DestinationBindOptions): firehose.DestinationConfig {
    return {dependables: [this.dest]}
  }
}

然后我可以像这样使用它,

export class MyStack extends Stack {
  ...
  private createFirehose(input: kinesis.Stream, output: opensearch.Domain) {

    const destination = new OpenSearchDomainDestination(output)
    const deliveryStream = new firehose.DeliveryStream(this, "FirehoseDeliveryStream", {
      destinations:       [destination],
      sourceStream:       input,
    })

    input.grantRead(deliveryStream)
    output.grantWrite(deliveryStream)
  }
}

这将编译并且 cdk Synth 运行得很好。但是,在运行 cdk deploy 时出现以下错误:

CREATE_FAILED | AWS::KinesisFirehose::DeliveryStream | ... Resource handler returned message: "Exactly one destination configuration is supported for a Firehose

我不确定我是否理解此消息,但它似乎暗示它将完全拒绝除提供的 S3 存储桶目标之外的所有内容。


因此,我的标题问题可以通过这两个问题中的任何一个的答案来回答:

  1. 您应该如何在 IDestination 中实现 bind
  2. 是否有使用非 alpha L1 构造创建 Firehose 到 OpenSearch 的完整工作示例?

(仅供参考,我还有 在 AWS 论坛上提出了此问题,但尚未收到答复。)

I am trying to create Data Stream -> Firehose -> OpenSearch infrastructure using the AWS CDK v2. I was surprised to find that, although OpenSearch is a supported Firehose destination, there is nothing in the CDK to support this use case.

In my CDK Stack I have created an OpenSearch Domain, and am trying to create a Kinesis Firehose DeliveryStream with that domain as the destination. However, kinesisfirehose-destinations package seems to only have a ready-to-use destination for S3 buckets, so there is no obvious way to do this easily using only the constructs supplied by the aws-cdk, not even using the alpha packages.

I think I should be able to write an OpenSearch destination construct by implementing IDestination. I have tried the following simplistic implementation:

import {Construct} from "constructs"
import * as firehose from "@aws-cdk/aws-kinesisfirehose-alpha"
import {aws_opensearchservice as opensearch} from "aws-cdk-lib"

export class OpenSearchDomainDestination implements firehose.IDestination {
  private readonly dest: opensearch.Domain

  constructor(dest: opensearch.Domain) {
    this.dest = dest
  }

  bind(scope: Construct, options: firehose.DestinationBindOptions): firehose.DestinationConfig {
    return {dependables: [this.dest]}
  }
}

then I can use it like so,

export class MyStack extends Stack {
  ...
  private createFirehose(input: kinesis.Stream, output: opensearch.Domain) {

    const destination = new OpenSearchDomainDestination(output)
    const deliveryStream = new firehose.DeliveryStream(this, "FirehoseDeliveryStream", {
      destinations:       [destination],
      sourceStream:       input,
    })

    input.grantRead(deliveryStream)
    output.grantWrite(deliveryStream)
  }
}

This will compile and cdk synth runs just fine. However, I get the following error when running cdk deploy:

CREATE_FAILED | AWS::KinesisFirehose::DeliveryStream | ... Resource handler returned message: "Exactly one destination configuration is supported for a Firehose

I'm not sure I understand this message but it seems to imply that it will reject outright everything except the one provided S3 bucket destination.


So, my titular question could be answered by the answer to either of these two questions:

  1. How are you supposed to implement bind in IDestination?
  2. Are there any complete working examples of creating a Firehose to OpenSearch using the non-alpha L1 constructs?

(FYI I have also asked this question on the AWS forum but have not yet received an answer.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

向地狱狂奔 2025-01-26 14:29:40

Other destinations (at the moment) than S3 are not supported by the L2 constructs. This is described at https://docs.aws.amazon.com/cdk/api/v1/docs/aws-kinesisfirehose-readme.html

In such cases, I go to the source code to see what can be done. See https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-kinesisfirehose/lib/destination.ts . There is no easy way how to inject other destination than S3 since the DestinationConfig does not support it. You can see at https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-kinesisfirehose-destinations/lib/s3-bucket.ts how the config for S3 is crafted. And you can see how that config is used to translate to L1 construct CfnDeliveryStream at https://github.com/aws/aws-cdk/blob/f82d96bfed427f8e49910ac7c77004765b2f5f6c/packages/%40aws-cdk/aws-kinesisfirehose/lib/delivery-stream.ts#L364

Probably easiest way at the moment is to write down your L1 constructs to define destination as OpenSearch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文