Skip to content

Commit

Permalink
leverage construct tree to store LogGroup and prevent creating it mul…
Browse files Browse the repository at this point in the history
…tiple times
  • Loading branch information
madeline-k committed Jul 17, 2021
1 parent 314c4ca commit 64131d1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/@aws-cdk/aws-kinesisfirehose/lib/destination.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as iam from '@aws-cdk/aws-iam';
import * as logs from '@aws-cdk/aws-logs';
import { Construct } from 'constructs';
import { Construct, Node } from 'constructs';
import { IDeliveryStream } from './delivery-stream';
import { CfnDeliveryStream } from './kinesisfirehose.generated';

Expand Down Expand Up @@ -66,7 +66,6 @@ export interface DestinationProps {
* Abstract base class that destination types can extend to benefit from methods that create generic configuration.
*/
export abstract class DestinationBase implements IDestination {
private logGroup?: logs.ILogGroup;

constructor(protected readonly props: DestinationProps = {}) { }

Expand All @@ -81,12 +80,12 @@ export abstract class DestinationBase implements IDestination {
throw new Error('logging cannot be set to false when logGroup is provided');
}
if (this.props.logging !== false || this.props.logGroup) {
this.logGroup = this.logGroup ?? this.props.logGroup ?? new logs.LogGroup(scope, 'LogGroup');
this.logGroup.grantWrite(deliveryStream);
const logGroup = Node.of(scope).tryFindChild('LogGroup') as logs.ILogGroup ?? this.props.logGroup ?? new logs.LogGroup(scope, 'LogGroup');
logGroup.grantWrite(deliveryStream);
return {
enabled: true,
logGroupName: this.logGroup.logGroupName,
logStreamName: this.logGroup.addStream(streamId).logStreamName,
logGroupName: logGroup.logGroupName,
logStreamName: logGroup.addStream(streamId).logStreamName,
};
}
return undefined;
Expand Down

0 comments on commit 64131d1

Please sign in to comment.