Skip to content

Commit

Permalink
added loggingBucketProps to s3-stepfunctions and s3-step-function
Browse files Browse the repository at this point in the history
  • Loading branch information
mickychetta committed Oct 1, 2021
1 parent 1552e4e commit af321fe
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ _Parameters_
* id `string`
* props [`S3ToStepFunctionProps`](#pattern-construct-props)

## Pattern Construct Props
## Pattern Construct Props

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
Expand All @@ -66,6 +66,7 @@ _Parameters_
|deployCloudTrail?|`boolean`|Whether to deploy a Trail in AWS CloudTrail to log API events in Amazon S3. Defaults to `true`.|
|createCloudWatchAlarms|`boolean`|Whether to create recommended CloudWatch alarms|
|logGroupProps?|[`logs.LogGroupProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.LogGroupProps.html)|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.|

## Pattern Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export interface S3ToStepFunctionProps {
* @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
}

export class S3ToStepFunction extends Construct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ _Parameters_
| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|existingBucketObj?|[`s3.IBucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.IBucket.html)|Existing instance of S3 Bucket object. If this is provided, then also providing bucketProps is an error. |
|bucketProps?|[`s3.BucketProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.BucketProps.html)|User provided props to override the default props for the S3 Bucket.|
|bucketProps?|[`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 Bucket.|
|stateMachineProps|[`sfn.StateMachineProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-stepfunctions.StateMachineProps.html)|Optional user provided props to override the default props for sfn.StateMachine|
|eventRuleProps?|[`events.RuleProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.RuleProps.html)|Optional user provided eventRuleProps to override the defaults|
|deployCloudTrail?|`boolean`|Whether to deploy a Trail in AWS CloudTrail to log API events in Amazon S3. Defaults to `true`.|
|createCloudWatchAlarms|`boolean`|Whether to create recommended CloudWatch alarms|
|logGroupProps?|[`logs.LogGroupProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.LogGroupProps.html)|User provided props to override the default props for for the CloudWatchLogs LogGroup.|
|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.|

## Pattern Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ export interface S3ToStepfunctionsProps {
*/
readonly existingBucketObj?: s3.IBucket,
/**
* User provided props to override the default props for the S3 Bucket.
* Optional user provided props to override the default props for the S3 Bucket.
*
* @default - Default props are used
*/
readonly bucketProps?: s3.BucketProps,
/**
* User provided StateMachineProps to override the defaults
* Optional user provided StateMachineProps to override the defaults
*
* @default - None
*/
readonly stateMachineProps: sfn.StateMachineProps,
/**
* User provided eventRuleProps to override the defaults
* Optional user provided eventRuleProps to override the defaults
*
* @default - None
*/
Expand All @@ -63,11 +63,17 @@ export interface S3ToStepfunctionsProps {
*/
readonly createCloudWatchAlarms?: boolean,
/**
* User provided props to override the default props for the CloudWatchLogs LogGroup.
* Optional user provided props to override the default props for the CloudWatchLogs LogGroup.
*
* @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
}

export class S3ToStepfunctions extends Construct {
Expand Down Expand Up @@ -99,7 +105,8 @@ export class S3ToStepfunctions extends Construct {

if (!props.existingBucketObj) {
[this.s3Bucket, this.s3LoggingBucket] = defaults.buildS3Bucket(this, {
bucketProps: props.bucketProps
bucketProps: props.bucketProps,
loggingBucketProps: props.loggingBucketProps
});
bucket = this.s3Bucket;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,43 @@ test("Test bad call with existingBucket and bucketProps", () => {
};
// Assertion
expect(app).toThrowError();
});

// --------------------------------------------------------------
// s3 bucket with bucket, loggingBucket, and auto delete objects
// --------------------------------------------------------------
test('s3 bucket with bucket, loggingBucket, and auto delete objects', () => {
const stack = new cdk.Stack();
const startState = new sfn.Pass(stack, 'StartState');

const testProps: S3ToStepfunctionsProps = {
stateMachineProps: {
definition: startState
},
bucketProps: {
removalPolicy: cdk.RemovalPolicy.DESTROY
},
loggingBucketProps: {
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true
}
};

new S3ToStepfunctions(stack, 'test-s3-stepfunctions', testProps);

expect(stack).toHaveResource("AWS::S3::Bucket", {
AccessControl: "LogDeliveryWrite"
});

expect(stack).toHaveResource("Custom::S3AutoDeleteObjects", {
ServiceToken: {
"Fn::GetAtt": [
"CustomS3AutoDeleteObjectsCustomResourceProviderHandler9D90184F",
"Arn"
]
},
BucketName: {
Ref: "tests3stepfunctionsS3LoggingBucketF7586A92"
}
});
});

0 comments on commit af321fe

Please sign in to comment.