Search code examples
amazon-web-servicesaws-cdkamazon-kinesis-firehose

Get metrics for cloudwatch alarm from CfnDeliveryStream via CDK


I am trying to setup cloudwatch alarms using the auto-generated metrics via CDK on a CfnDeliveryStream which is a part of @aws-cdk/aws-kinesisfirehose. From the documentation here, https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStream.html it looks like there is no metric() that can be used for this. However the DeliveryStream class in the same library has that method, is it possible to leverage that?


Solution

  • There are basically two strategies:

    1. Use the DeliveryStream construct primarily (let mystream = new DeliveryStream(...)) and then modify the underlying CfnDeliverystream by accessing the underlying Cfn object ( let cfnstream = mystream.node.defaultChild) and then modify that construct.
    2. Create the Cfn stream first and then convert it to a DeliveryStream by using the DeliveryStream.fromDeliveryStreamAttributes(scope, id, attrs) or fromDeliveryStreamArn(scope, id, attrs) or fromDeliveryStreamName(scope, id, attrs). These methods have the downside that this way of using the construct often does limit the amount of properties and methods that can be used properly, since it does not import all info of the original stream. fromDeliveryStreamAttributes is the most complete one but it's quite verbose since you need to pass all attributes that you need to use.