Skip to content

Commit 6fab3e5

Browse files
authored
feat(aws-kinesisfirehose-s3): added custom logging bucket props to kinesisfirehose-s3 (#478)
* added custom logging bucket props to kinesisfirehose-s3 * added log bucket condition in input validation * Added logS3AccessLogs for enabling/disabling s3 logs * added cfn suppress rule for no logging * fix lint issue * redeploy stack for cfn nag suppress changes * added logS3AccessLogs property * refactored s3 bucket helper and improved tests * readded test for s3-bucket * moved test to s3 bucket helper test file
1 parent 4100d58 commit 6fab3e5

13 files changed

+1066
-62
lines changed

source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ _Parameters_
5050
|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.|
5151
|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.|
5252
|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.|
53+
|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.|
54+
|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|
5355

5456
## Pattern Properties
5557

source/patterns/@aws-solutions-constructs/aws-kinesisfirehose-s3/lib/index.ts

+25-18
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ export interface KinesisFirehoseToS3Props {
5656
* @default - Default props are used
5757
*/
5858
readonly logGroupProps?: logs.LogGroupProps;
59+
/**
60+
* Optional user provided props to override the default props for the S3 Logging Bucket.
61+
*
62+
* @default - Default props are used
63+
*/
64+
readonly loggingBucketProps?: s3.BucketProps;
65+
/**
66+
* Whether to turn on Access Logs for the S3 bucket with the associated storage costs.
67+
* Enabling Access Logging is a best practice.
68+
*
69+
* @default - true
70+
*/
71+
readonly logS3AccessLogs?: boolean;
5972
}
6073

6174
export class KinesisFirehoseToS3 extends Construct {
@@ -64,6 +77,7 @@ export class KinesisFirehoseToS3 extends Construct {
6477
public readonly kinesisFirehoseRole: iam.Role;
6578
public readonly s3Bucket?: s3.Bucket;
6679
public readonly s3LoggingBucket?: s3.Bucket;
80+
public readonly s3BucketInterface: s3.IBucket;
6781

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

8094
let bucket: s3.IBucket;
8195

82-
if (props.existingBucketObj && props.bucketProps) {
83-
throw new Error('Cannot specify both bucket properties and an existing bucket');
84-
}
85-
8696
// Setup S3 Bucket
8797
if (!props.existingBucketObj) {
88-
let { bucketProps } = props;
98+
let bucketProps = props.bucketProps ?? {};
99+
bucketProps = props.existingLoggingBucketObj ?
100+
overrideProps(bucketProps, { serverAccessLogsBucket: props.existingLoggingBucketObj }) :
101+
bucketProps;
89102

90103
// Setup logging S3 Bucket
91-
if (props.existingLoggingBucketObj) {
92-
if (!bucketProps) {
93-
bucketProps = {};
94-
}
95-
96-
bucketProps = overrideProps(bucketProps, {
97-
serverAccessLogsBucket: props.existingLoggingBucketObj
98-
});
99-
}
100-
101104
[this.s3Bucket, this.s3LoggingBucket] = defaults.buildS3Bucket(this, {
102-
bucketProps
105+
bucketProps,
106+
loggingBucketProps: props.loggingBucketProps,
107+
logS3AccessLogs: props.logS3AccessLogs,
103108
});
104109

105110
bucket = this.s3Bucket;
106111
} else {
107112
bucket = props.existingBucketObj;
108113
}
109114

115+
this.s3BucketInterface = bucket;
116+
110117
// Setup Cloudwatch Log group & stream for Kinesis Firehose
111118
this.kinesisFirehoseLogGroup = defaults.buildLogGroup(
112119
this,
@@ -166,8 +173,8 @@ export class KinesisFirehoseToS3 extends Construct {
166173
printWarning(`kinesisFirehoseProps: ${JSON.stringify(props.kinesisFirehoseProps, null, 2)}`);
167174
// if the client didn't explicity say it was a Kinesis client, then turn on encryption
168175
if (!props.kinesisFirehoseProps ||
169-
!props.kinesisFirehoseProps.deliveryStreamType ||
170-
props.kinesisFirehoseProps.deliveryStreamType !== 'KinesisStreamAsSource'
176+
!props.kinesisFirehoseProps.deliveryStreamType ||
177+
props.kinesisFirehoseProps.deliveryStreamType !== 'KinesisStreamAsSource'
171178
) {
172179
defaultKinesisFirehoseProps = defaults.overrideProps(
173180
defaultKinesisFirehoseProps,

0 commit comments

Comments
 (0)