Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit a4ecdfd

Browse files
vgkowskiAutomation
and
Automation
authored
fix: change BatchReplayer props to solve JSII conversion issue in Python with IS3Sink (#654)
* fix: fix JSII conversion issue in Python with IS3Sink --------- Co-authored-by: Automation <[email protected]>
1 parent d4d75b0 commit a4ecdfd

File tree

9 files changed

+96
-93
lines changed

9 files changed

+96
-93
lines changed

core/API.md

+67-63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/data-generator/batch-replayer-helpers.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ITable } from 'aws-cdk-lib/aws-dynamodb';
33
import { Bucket } from 'aws-cdk-lib/aws-s3';
44

55

6-
export interface IS3Sink {
6+
export interface S3Sink {
77
/**
88
* The S3 Bucket sink where the BatchReplayer writes data.
99
* :warning: **If the Bucket is encrypted with KMS, the Key must be managed by this stack.
@@ -13,12 +13,12 @@ export interface IS3Sink {
1313
* The S3 object key sink where the BatchReplayer writes data.
1414
* @default - No object key is used and the BatchReplayer writes the dataset in s3://<BUCKET_NAME>/<TABLE_NAME>
1515
*/
16-
sinkObjectKey?: string;
16+
readonly sinkObjectKey?: string;
1717
/**
1818
* The maximum file size in Bytes written by the BatchReplayer
1919
* @default - The BatchReplayer writes 100MB files maximum
2020
*/
21-
outputFileMaxSizeInBytes?: number;
21+
readonly outputFileMaxSizeInBytes?: number;
2222
}
2323

2424
export interface DbSink {
@@ -54,7 +54,7 @@ export interface DynamoDbSink {
5454
* @param dataBucketName
5555
* @param dataObjectKey
5656
*/
57-
export function prepareS3Target(S3Props: IS3Sink, dataBucketName: string, dataObjectKey: string)
57+
export function prepareS3Target(S3Props: S3Sink, dataBucketName: string, dataObjectKey: string)
5858
: {policy:PolicyStatement; taskInputParams:Object} {
5959
// Add policy to allow access to bucket
6060
const policy = new PolicyStatement({

core/src/data-generator/batch-replayer.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
prepareRdsTarget,
2121
prepareRedshiftTarget,
2222
prepareS3Target,
23-
IS3Sink,
23+
S3Sink,
2424
DbSink,
2525
DynamoDbSink,
2626
} from './batch-replayer-helpers';
@@ -42,7 +42,7 @@ export interface BatchReplayerProps {
4242
/**
4343
* Parameters to write to S3 target
4444
*/
45-
readonly s3Props?: IS3Sink;
45+
readonly s3Props?: S3Sink;
4646
/**
4747
* Parameters to write to DynamoDB target
4848
*/
@@ -115,7 +115,7 @@ export interface BatchReplayerProps {
115115
*
116116
* const myBucket = new Bucket(stack, "MyBucket")
117117
*
118-
* let myProps: IS3Sink = {
118+
* let myProps: S3Sink = {
119119
* sinkBucket: myBucket,
120120
* sinkObjectKey: 'some-prefix',
121121
* outputFileMaxSizeInBytes: 10000000,
@@ -145,7 +145,7 @@ export class BatchReplayer extends Construct {
145145
/**
146146
* Parameters to write to S3 target
147147
*/
148-
public readonly s3Props?: IS3Sink;
148+
public readonly s3Props?: S3Sink;
149149
/**
150150
* Parameters to write to DynamoDB target
151151
*/
@@ -191,13 +191,6 @@ export class BatchReplayer extends Construct {
191191
this.frequency = props.frequency?.toSeconds() || 60;
192192
this.additionalStepFunctionTasks = props.additionalStepFunctionTasks;
193193

194-
// Properties for S3 target
195-
if (props.s3Props) {
196-
this.s3Props = props.s3Props;
197-
if (!this.s3Props.outputFileMaxSizeInBytes) {
198-
this.s3Props.outputFileMaxSizeInBytes = 100 * 1024 * 1024; //Default to 100 MB
199-
}
200-
}
201194
const manifestBucketName = this.dataset.manifestLocation.bucketName;
202195
const manifestObjectKey = this.dataset.manifestLocation.objectKey;
203196
const dataBucketName = this.dataset.location.bucketName;
@@ -274,12 +267,18 @@ export class BatchReplayer extends Construct {
274267
};
275268

276269
// S3 target is selected
277-
if (this.s3Props) {
270+
if (props.s3Props) {
278271
// Used to force S3 bucket auto cleaning after deletion of this
279-
this.node.addDependency(this.s3Props.sinkBucket);
272+
this.node.addDependency(props.s3Props.sinkBucket);
273+
var modS3Props = { ...props.s3Props };
274+
if (!props.s3Props.outputFileMaxSizeInBytes) {
275+
modS3Props.outputFileMaxSizeInBytes = 100 * 1024 * 1024; //Default to 100 MB
276+
}
280277

281-
this.s3Props.sinkObjectKey = this.s3Props.sinkObjectKey ?
282-
`${this.s3Props.sinkObjectKey}/${this.dataset.tableName}` : this.dataset.tableName;
278+
modS3Props.sinkObjectKey = props.s3Props.sinkObjectKey ?
279+
`${props.s3Props.sinkObjectKey}/${this.dataset.tableName}` : this.dataset.tableName;
280+
281+
this.s3Props = modS3Props;
283282

284283
const { policy, taskInputParams } = prepareS3Target(this.s3Props, dataBucketName, dataObjectKey);
285284
writeInBatchFnPolicy.push(policy);

core/src/data-generator/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { BatchReplayerProps, BatchReplayer } from './batch-replayer';
2-
export { IS3Sink, DbSink, DynamoDbSink } from './batch-replayer-helpers';
2+
export { S3Sink, DbSink, DynamoDbSink } from './batch-replayer-helpers';
33
export { PreparedDataset, PreparedDatasetProps } from './prepared-dataset';
44
export { CustomDataset, CustomDatasetProps, CustomDatasetInputFormat } from './custom-dataset';

core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
export { DataLakeStorageProps, DataLakeStorage } from './data-lake-storage';
55
export { SynchronousCrawlerProps, SynchronousCrawler } from './synchronous-crawler';
6-
export { BatchReplayerProps, BatchReplayer, PreparedDatasetProps, PreparedDataset, CustomDataset, CustomDatasetProps, CustomDatasetInputFormat, IS3Sink, DbSink, DynamoDbSink } from './data-generator';
6+
export { BatchReplayerProps, BatchReplayer, PreparedDatasetProps, PreparedDataset, CustomDataset, CustomDatasetProps, CustomDatasetInputFormat, S3Sink, DbSink, DynamoDbSink } from './data-generator';
77
export { SynchronousAthenaQueryProps, SynchronousAthenaQuery } from './synchronous-athena-query';
88
export { AraBucket, AraBucketProps } from './ara-bucket';
99
export { Ec2SsmRole } from './ec2-ssm-role';

core/test/e2e/batch-replayer.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Cluster } from '@aws-cdk/aws-redshift-alpha';
1414
import { deployStack, destroyStack } from './utils';
1515

1616
import { BatchReplayer } from '../../src/data-generator/batch-replayer';
17-
import { IS3Sink, DynamoDbSink, DbSink } from '../../src/data-generator/batch-replayer-helpers';
17+
import { S3Sink, DynamoDbSink, DbSink } from '../../src/data-generator/batch-replayer-helpers';
1818
import { PreparedDataset } from '../../src/data-generator/prepared-dataset';
1919
import { PreBundledFunction } from '../../src/common/pre-bundled-function';
2020
import { Runtime } from 'aws-cdk-lib/aws-lambda';
@@ -31,7 +31,7 @@ const sinkBucket = new Bucket(stack, 'SinkBucket', {
3131
removalPolicy: RemovalPolicy.DESTROY,
3232
autoDeleteObjects: true,
3333
});
34-
let s3Props: IS3Sink = { sinkBucket: sinkBucket };
34+
let s3Props: S3Sink = { sinkBucket: sinkBucket };
3535

3636
const vpc = new aws_ec2.Vpc(stack, 'Vpc');
3737

core/test/unit/cdk-nag/nag-batch-replayer.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import { App, Aspects, Duration, Stack } from 'aws-cdk-lib';
1313
// eslint-disable-next-line import/no-extraneous-dependencies
1414
import { AwsSolutionsChecks, NagSuppressions } from 'cdk-nag';
1515
import { BatchReplayer, PreparedDataset } from '../../../src';
16-
import { IS3Sink } from '../../../lib';
16+
import { S3Sink } from '../../../lib';
1717

1818
const mockApp = new App();
1919

2020
const batchReplayerStack = new Stack(mockApp, 'BatchReplayer');
2121
const sinkBucket = new Bucket(batchReplayerStack, 'SinkBucket');
2222
// Instantiate a DataGenerator
23-
const s3Props: IS3Sink = { sinkBucket: sinkBucket, sinkObjectKey: 'test' };
23+
const s3Props: S3Sink = { sinkBucket: sinkBucket, sinkObjectKey: 'test' };
2424
const batchReplayer = new BatchReplayer(batchReplayerStack, 'TestBatchReplayer', {
2525
dataset: PreparedDataset.RETAIL_1_GB_WEB_SALE,
2626
frequency: Duration.seconds(120),

core/test/unit/data-generator/batch-replayer.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import {
1818

1919
import { Template } from 'aws-cdk-lib/assertions';
2020
import { Bucket } from 'aws-cdk-lib/aws-s3';
21-
import { BatchReplayer, DbSink, DynamoDbSink, IS3Sink, PreparedDataset } from '../../../src';
21+
import { BatchReplayer, DbSink, DynamoDbSink, S3Sink, PreparedDataset } from '../../../src';
2222
import { IVpc, SecurityGroup } from 'aws-cdk-lib/aws-ec2';
2323
import { PreBundledFunction } from '../../../src/common/pre-bundled-function';
2424
import { Runtime } from 'aws-cdk-lib/aws-lambda';
2525
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
2626

2727
let testStack: Stack;
28-
let s3Props: IS3Sink;
28+
let s3Props: S3Sink;
2929
let batchReplayer: BatchReplayer;
3030
let template: Template;
3131
let ddbProps: DynamoDbSink;
@@ -105,7 +105,7 @@ test("BatchReplayer should use default frequency", () => {
105105
});
106106

107107
test("BatchReplayer should use given max output file size", () => {
108-
const s3MaxOutputFileSizeSet: IS3Sink = {
108+
const s3MaxOutputFileSizeSet: S3Sink = {
109109
sinkBucket: new Bucket(testStack, 'filesizeBucket'),
110110
outputFileMaxSizeInBytes: 20480,
111111
};
@@ -119,7 +119,7 @@ test("BatchReplayer should use given max output file size", () => {
119119
});
120120

121121
test("BatchReplayer should use default max output file size 100MB", () => {
122-
const s3MaxOutputFileSizeDefault: IS3Sink = {
122+
const s3MaxOutputFileSizeDefault: S3Sink = {
123123
sinkBucket: new Bucket(testStack, 'noFilesizeBucket'),
124124
};
125125
const batchReplayerWithNoFilesizeProp = new BatchReplayer(testStack, "TestBatchReplayerWithNoFreqProp", {

core/yarn.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)