我正在尝试创建数据流 ->消防水带 ->使用 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 存储桶目标之外的所有内容。
因此,我的标题问题可以通过这两个问题中的任何一个的答案来回答:
- 您应该如何在
IDestination
中实现 bind
?
- 是否有使用非 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:
- How are you supposed to implement
bind
in IDestination
?
- 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.)
发布评论
评论(1)
L2 结构不支持除 S3 之外的其他目的地(目前)。 https://docs 对此进行了描述。 aws.amazon.com/cdk/api/v1/docs/aws-kinesisfirehose-readme.html
在这种情况下,我会转到源代码以查看可以做什么。请参阅 https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-kinesisfirehose/lib/destination.ts 。由于
DestinationConfig
不支持,因此没有简单的方法可以注入除 S3 之外的其他目标。您可以在 https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-kinesisfirehose-destinations/lib/s3-bucket.ts S3的配置是精心制作的。您可以在 CfnDeliveryStream href="https://github.com/aws/aws-cdk/blob/f82d96bfed427f8e49910ac7c77004765b2f5f6c/packages/%40aws-cdk/aws-kinesisfirehose/lib/delivery-stream.ts#L364" rel="nofollow noreferrer">https://github.com/aws/aws-cdk/blob/f82d96bfed427f8e49910ac7c77004765b2f5f6c/packages/%40aws-cdk/aws-kinesisfirehose/lib/delivery-stream.ts#L364可能是最简单的方法此刻是写下你的 L1 结构将目标定义为 OpenSearch。
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 constructCfnDeliveryStream
at https://github.com/aws/aws-cdk/blob/f82d96bfed427f8e49910ac7c77004765b2f5f6c/packages/%40aws-cdk/aws-kinesisfirehose/lib/delivery-stream.ts#L364Probably easiest way at the moment is to write down your L1 constructs to define destination as OpenSearch.