@@ -11,12 +11,9 @@ import {
11
11
aws_iam as iam ,
12
12
aws_glue as glue ,
13
13
aws_athena as athena ,
14
- aws_logs as logs ,
15
14
StackProps ,
16
15
} from 'aws-cdk-lib'
17
16
18
- import { LambdaFunctionProcessor as LambdaFunctionProcessorAlpha , DeliveryStream as DeliveryStreamAlpha } from '@aws-cdk/aws-kinesisfirehose-alpha'
19
- import * as destinationsAlpha from '@aws-cdk/aws-kinesisfirehose-destinations-alpha'
20
17
import * as glueAlpha from '@aws-cdk/aws-glue-alpha'
21
18
import { CfnDeliveryStream } from 'aws-cdk-lib/aws-kinesisfirehose'
22
19
import { SavedQueries } from './saved-queries/saved-queries'
@@ -25,6 +22,9 @@ import { QuicksightRole } from './quicksight/quicksight-role'
25
22
import { DdbExport } from './ddb-export/ddb-export'
26
23
import { DdbExportStepFunction } from './ddb-export/ddb-export-step-function'
27
24
import { Config } from '../bin/config'
25
+ import { FirehoseJson } from './firehose/firehose-json'
26
+ import { FirehoseParquet } from './firehose/firehose-parquet'
27
+ import { th } from '@faker-js/faker'
28
28
29
29
30
30
export interface CdkStackProps extends StackProps {
@@ -79,31 +79,48 @@ export class CdkStack extends Stack {
79
79
autoDeleteObjects : true ,
80
80
} )
81
81
82
- const processor = new lambda . NodejsFunction ( this , 'lambda-function-processor ' , {
83
- functionName : `${ name } -firehose-converter ` ,
84
- timeout : Duration . minutes ( 2 ) ,
85
- bundling : {
86
- sourceMap : true ,
82
+ const glueSecurityConfiguration = new glueAlpha . SecurityConfiguration ( this , 'glue security options ' , {
83
+ securityConfigurationName : `${ name } -security-options ` ,
84
+ s3Encryption : {
85
+ mode : glueAlpha . S3EncryptionMode . KMS ,
86
+ kmsKey : kmsKey ,
87
87
} ,
88
88
} )
89
89
90
- const lambdaProcessor = new LambdaFunctionProcessorAlpha ( processor , {
91
- retries : 5 ,
90
+ const glueDb = new glueAlpha . Database ( this , 'glue db' , {
91
+ databaseName : ` ${ name } -db` ,
92
92
} )
93
93
94
- const ddbChangesPrefix = 'ddb-changes' ;
94
+ let ddbChangesPrefix ;
95
+
96
+ switch ( props ?. config . kinesisFormat ) {
97
+ case 'JSON' :
98
+ ddbChangesPrefix = 'ddb-changes-json' ;
99
+ new FirehoseJson ( this , 'firehoseJson' , {
100
+ name : name ,
101
+ kmsKey : kmsKey ,
102
+ firehoseBucket : firehoseBucket ,
103
+ ddbChangesPrefix : ddbChangesPrefix ,
104
+ stream : stream ,
105
+ } )
106
+ break ;
107
+ case 'PARQUET' :
108
+ ddbChangesPrefix = 'ddb-changes-parquet' ;
109
+ new FirehoseParquet ( this , 'firehoseJson' , {
110
+ name : name ,
111
+ kmsKey : kmsKey ,
112
+ firehoseBucket : firehoseBucket ,
113
+ ddbChangesPrefix : ddbChangesPrefix ,
114
+ stream : stream ,
115
+ glueSecurityConfiguration : glueSecurityConfiguration ,
116
+ glueDb : glueDb ,
117
+ table : table ,
118
+ } )
119
+ break ;
120
+ default : throw new Error ( 'kinesisFormat not supported' ) ;
121
+ }
122
+
95
123
96
- // json format
97
- const s3Destination = new destinationsAlpha . S3Bucket ( firehoseBucket , {
98
- encryptionKey : kmsKey ,
99
- bufferingInterval : Duration . seconds ( 60 ) ,
100
- processor : lambdaProcessor ,
101
- dataOutputPrefix : `${ ddbChangesPrefix } /` ,
102
- logGroup : new logs . LogGroup ( this , 'firehose-s3-log-group' , {
103
- logGroupName : `${ name } -firehose-s3-log-group` ,
104
- removalPolicy : RemovalPolicy . DESTROY ,
105
- } ) ,
106
- } )
107
124
108
125
// parquet format
109
126
// const s3Destination = new destinationsAlpha.S3Bucket(firehoseBucket, {
@@ -113,11 +130,7 @@ export class CdkStack extends Stack {
113
130
// bufferingSize: Size.mebibytes(64),
114
131
// });
115
132
116
- const firehoseDeliveryStream = new DeliveryStreamAlpha ( this , 'Delivery Stream' , {
117
- deliveryStreamName : `${ name } -firehose` ,
118
- sourceStream : stream ,
119
- destinations : [ s3Destination ] ,
120
- } )
133
+
121
134
122
135
// // https://5k-team.trilogy.com/hc/en-us/articles/360015651640-Configuring-Firehose-with-CDK
123
136
// // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-kinesisfirehose-deliverystream.html
@@ -161,19 +174,6 @@ export class CdkStack extends Stack {
161
174
assumedBy : new iam . ServicePrincipal ( 'glue.amazonaws.com' ) ,
162
175
} )
163
176
164
-
165
- const glueDb = new glueAlpha . Database ( this , 'glue db' , {
166
- databaseName : `${ name } -db` ,
167
- } )
168
-
169
- const glueSecurityOptions = new glueAlpha . SecurityConfiguration ( this , 'glue security options' , {
170
- securityConfigurationName : `${ name } -security-options` ,
171
- s3Encryption : {
172
- mode : glueAlpha . S3EncryptionMode . KMS ,
173
- kmsKey : kmsKey ,
174
- } ,
175
- } )
176
-
177
177
const crawler = new glue . CfnCrawler ( this , 'crawler' , {
178
178
name : `${ name } -crawler` ,
179
179
role : roleCrawler . roleArn ,
@@ -185,7 +185,7 @@ export class CdkStack extends Stack {
185
185
] ,
186
186
} ,
187
187
databaseName : glueDb . databaseName ,
188
- crawlerSecurityConfiguration : glueSecurityOptions . securityConfigurationName ,
188
+ crawlerSecurityConfiguration : glueSecurityConfiguration . securityConfigurationName ,
189
189
configuration : JSON . stringify ( {
190
190
Version : 1.0 ,
191
191
Grouping : { TableGroupingPolicy : 'CombineCompatibleSchemas' } ,
@@ -225,7 +225,7 @@ export class CdkStack extends Stack {
225
225
actions : [ 'glue:GetSecurityConfiguration' ] ,
226
226
} )
227
227
)
228
- glueSecurityOptions . node . addDependency ( roleCrawler )
228
+ glueSecurityConfiguration . node . addDependency ( roleCrawler )
229
229
// crawler.node.addDependency(roleCrawler)
230
230
231
231
const athenaWorkgroup = new athena . CfnWorkGroup ( this , 'analytics-athena-workgroup' , {
@@ -251,11 +251,18 @@ export class CdkStack extends Stack {
251
251
savedQueries . node . addDependency ( athenaWorkgroup )
252
252
253
253
if ( props ?. config . isQuicksight ) {
254
+ let quicksightUsername ;
255
+ if ( process . env . QUICKSIGHT_USERNAME ) {
256
+ quicksightUsername = process . env . QUICKSIGHT_USERNAME ;
257
+ } else {
258
+ throw new Error ( 'QUICKSIGHT_USERNAME environment variable is required' ) ;
259
+ }
254
260
255
261
new Quicksight ( this , 'quicksight' , {
256
262
bucket : firehoseBucket ,
257
263
name : name ,
258
264
prefix : ddbChangesPrefix ,
265
+ quicksightUsername : quicksightUsername ,
259
266
} )
260
267
261
268
new QuicksightRole ( this , 'quicksight-role' , {
0 commit comments