Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws-kinesisfirehose-s3): added custom logging bucket props to kinesisfirehose-s3 #478

Merged
merged 16 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ _Parameters_
|existingLoggingBucketObj?|[`s3.IBucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.IBucket.html)|Optional existing instance of logging S3 Bucket for the S3 Bucket created by the pattern.|
|kinesisFirehoseProps?|[`kinesisfirehose.CfnDeliveryStreamProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kinesisfirehose.CfnDeliveryStreamProps.html)\|`any`|Optional user provided props to override the default props for Kinesis Firehose Delivery Stream.|
|logGroupProps?|[`logs.LogGroupProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.LogGroupProps.html)|Optional user provided props to override the default props for for the CloudWatchLogs LogGroup.|
|loggingBucketProps?|[`s3.BucketProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.BucketProps.html)|Optional user provided props to override the default props for the S3 Logging Bucket.|
|logS3AccessLogs?| boolean|Whether to turn on Access Logging for the S3 bucket. Creates an S3 bucket with associated storage costs for the logs. Enabling Access Logging is a best practice. default - true|

## Pattern Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ export interface KinesisFirehoseToS3Props {
* @default - Default props are used
*/
readonly logGroupProps?: logs.LogGroupProps;
/**
* Optional user provided props to override the default props for the S3 Logging Bucket.
*
* @default - Default props are used
*/
readonly loggingBucketProps?: s3.BucketProps;
/**
* Whether to turn on Access Logs for the S3 bucket with the associated storage costs.
* Enabling Access Logging is a best practice.
*
* @default - true
*/
readonly logS3AccessLogs?: boolean;
}

export class KinesisFirehoseToS3 extends Construct {
Expand All @@ -64,6 +77,7 @@ export class KinesisFirehoseToS3 extends Construct {
public readonly kinesisFirehoseRole: iam.Role;
public readonly s3Bucket?: s3.Bucket;
public readonly s3LoggingBucket?: s3.Bucket;
public readonly s3BucketInterface: s3.IBucket;

/**
* Constructs a new instance of the KinesisFirehoseToS3 class.
Expand All @@ -79,34 +93,27 @@ export class KinesisFirehoseToS3 extends Construct {

let bucket: s3.IBucket;

if (props.existingBucketObj && props.bucketProps) {
throw new Error('Cannot specify both bucket properties and an existing bucket');
}

mickychetta marked this conversation as resolved.
Show resolved Hide resolved
// Setup S3 Bucket
if (!props.existingBucketObj) {
let { bucketProps } = props;
let bucketProps = props.bucketProps ?? {};
bucketProps = props.existingLoggingBucketObj ?
overrideProps(bucketProps, { serverAccessLogsBucket: props.existingLoggingBucketObj }) :
bucketProps;

// Setup logging S3 Bucket
if (props.existingLoggingBucketObj) {
if (!bucketProps) {
bucketProps = {};
}

bucketProps = overrideProps(bucketProps, {
serverAccessLogsBucket: props.existingLoggingBucketObj
});
}

[this.s3Bucket, this.s3LoggingBucket] = defaults.buildS3Bucket(this, {
bucketProps
bucketProps,
loggingBucketProps: props.loggingBucketProps,
logS3AccessLogs: props.logS3AccessLogs,
});

bucket = this.s3Bucket;
mickychetta marked this conversation as resolved.
Show resolved Hide resolved
} else {
bucket = props.existingBucketObj;
}

this.s3BucketInterface = bucket;

// Setup Cloudwatch Log group & stream for Kinesis Firehose
this.kinesisFirehoseLogGroup = defaults.buildLogGroup(
this,
Expand Down Expand Up @@ -166,8 +173,8 @@ export class KinesisFirehoseToS3 extends Construct {
printWarning(`kinesisFirehoseProps: ${JSON.stringify(props.kinesisFirehoseProps, null, 2)}`);
// if the client didn't explicity say it was a Kinesis client, then turn on encryption
if (!props.kinesisFirehoseProps ||
!props.kinesisFirehoseProps.deliveryStreamType ||
props.kinesisFirehoseProps.deliveryStreamType !== 'KinesisStreamAsSource'
!props.kinesisFirehoseProps.deliveryStreamType ||
props.kinesisFirehoseProps.deliveryStreamType !== 'KinesisStreamAsSource'
) {
defaultKinesisFirehoseProps = defaults.overrideProps(
defaultKinesisFirehoseProps,
Expand Down
Loading