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

Commit 0a20f59

Browse files
authored
fix: add parameter to customize athena workgroup setup (#507)
1 parent d3e5659 commit 0a20f59

File tree

7 files changed

+147
-37
lines changed

7 files changed

+147
-37
lines changed

core/API.md

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/athena-demo-setup.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import { Bucket } from 'aws-cdk-lib/aws-s3';
66
import { Construct } from 'constructs';
77
import { AraBucket } from './ara-bucket';
88

9+
export interface AthenaDemoSetupProps {
10+
11+
/**
12+
* The Amazon Athena workgroup name. The name is also used
13+
* @default - `demo` is used
14+
*/
15+
readonly workgroupName?: string;
16+
}
17+
918
/**
1019
* AthenaDemoSetup Construct to automatically setup a new Amazon Athena Workgroup with proper configuration for out-of-the-box demo
1120
*/
@@ -22,17 +31,18 @@ export class AthenaDemoSetup extends Construct {
2231
* @access public
2332
*/
2433

25-
constructor(scope: Construct, id: string) {
34+
constructor(scope: Construct, id: string, props: AthenaDemoSetupProps) {
2635
super(scope, id);
2736

37+
const workgroupName = props.workgroupName || 'demo';
2838
// Singleton Amazon S3 bucket for Amazon Athena Query logs
2939
this.resultBucket = AraBucket.getOrCreate(this, {
30-
bucketName: 'athena-logs',
31-
serverAccessLogsPrefix: 'athena-logs-bucket',
40+
bucketName: `${workgroupName}-athena-logs`,
41+
serverAccessLogsPrefix: `${workgroupName}-athena-logs-bucket`,
3242
});
3343

3444
this.athenaWorkgroup = new CfnWorkGroup(this, 'athenaDemoWorkgroup', {
35-
name: 'demo',
45+
name: workgroupName,
3646
recursiveDeleteOption: true,
3747
workGroupConfiguration: {
3848
requesterPaysEnabled: true,

core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export { AraBucket, AraBucketProps } from './ara-bucket';
99
export { Ec2SsmRole } from './ec2-ssm-role';
1010
export { DataLakeCatalog } from './data-lake-catalog';
1111
export { DataLakeExporter, DataLakeExporterProps } from './data-lake-exporter';
12-
export { AthenaDemoSetup } from './athena-demo-setup';
12+
export { AthenaDemoSetup, AthenaDemoSetupProps } from './athena-demo-setup';
1313
export { GlueDemoRole } from './glue-demo-role';
1414
export { EmrEksClusterProps, EmrEksCluster, EmrEksNodegroupOptions, EmrEksNodegroup, EmrVirtualClusterOptions, EmrManagedEndpointOptions } from './emr-eks-platform';
1515
export { FlywayRunner, FlywayRunnerProps } from './db-schema-manager';

core/test/e2e/athena-demo-setup.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ jest.setTimeout(100000);
1717
const integTestApp = new cdk.App();
1818
const stack = new cdk.Stack(integTestApp, 'AthenaDemoSetupE2eTest');
1919

20-
const athenaSetup = new AthenaDemoSetup(stack, 'AthenaSetup');
20+
const athenaSetup = new AthenaDemoSetup(stack, 'AthenaSetup', {});
21+
const athenaSetup2 = new AthenaDemoSetup(stack, 'AthenaSetup2', {workgroupName: 'custom'});
2122

2223
new cdk.CfnOutput(stack, 'ResultsBucketName', {
2324
value: athenaSetup.resultBucket.bucketName,
@@ -29,14 +30,26 @@ new cdk.CfnOutput(stack, 'AthenaWorkgroupName', {
2930
exportName: 'AthenaWorkgroupName',
3031
});
3132

33+
new cdk.CfnOutput(stack, 'AthenaWorkgroupName2', {
34+
value: athenaSetup2.athenaWorkgroup.name,
35+
exportName: 'AthenaWorkgroupName2',
36+
});
37+
38+
new cdk.CfnOutput(stack, 'ResultsBucketName2', {
39+
value: athenaSetup2.resultBucket.bucketName,
40+
exportName: 'ResultsBucketName2',
41+
});
42+
3243
describe('deploy succeed', () => {
3344
it('can be deploy succcessfully', async () => {
3445
const deployResult = await deployStack(integTestApp, stack);
3546

3647

3748
// THEN
3849
expect(deployResult.outputs.AthenaWorkgroupName).toEqual('demo');
39-
expect(deployResult.outputs.ResultsBucketName).toContain('athena-logs');
50+
expect(deployResult.outputs.AthenaWorkgroupName2).toEqual('custom');
51+
expect(deployResult.outputs.ResultsBucketName).toContain('demo-athena-logs');
52+
expect(deployResult.outputs.ResultsBucketName2).toContain('custom-athena-logs');
4053

4154
}, 9000000);
4255
});

core/test/e2e/data-domain.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const stack = new cdk.Stack(integTestApp, 'DataDomainE2eTest');
1919

2020
const domain = new DataDomain(stack, 'DataDomain', {
2121
domainName: 'test',
22-
centralAccountId: '628862645339',
22+
centralAccountId: '111111111111',
2323
crawlerWorkflow: true,
2424
});
2525

core/test/unit/athena-demo-setup.test.ts

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,59 @@ import { Match, Template } from 'aws-cdk-lib/assertions';
1616
describe ('AthenaDemoSetup', () => {
1717

1818
const athenaDemoSetupStack = new Stack();
19-
// Instantiate an AthenaDemoSetup
20-
new AthenaDemoSetup(athenaDemoSetupStack, 'AthenaDefault');
21-
19+
// Instantiate an AthenaDemoSetup with default name
20+
new AthenaDemoSetup(athenaDemoSetupStack, 'AthenaDefault', {});
21+
// Instantiate an AthenaDemoSetup with custom name
22+
new AthenaDemoSetup(athenaDemoSetupStack, 'NamedAthenaDefault', {workgroupName: 'custom-name'});
2223
const template = Template.fromStack(athenaDemoSetupStack);
2324

24-
// test('Athena demo setup creates the proper result bucket', () => {
25+
test('Athena demo setup creates the proper result bucket', () => {
2526

26-
// // Test if a bucket is created for results
27-
// template.resourceCountIs('AWS::S3::Bucket', 2);
27+
// Test if buckets are created for results (+1 for access logs)
28+
template.resourceCountIs('AWS::S3::Bucket', 3);
2829

29-
// // Test if the Amazon S3 Bucket for the result is correct
30-
// // template.hasResourceProperties('AWS::S3::Bucket',
31-
// // Match.objectLike({
32-
// // BucketName: {
33-
// // 'Fn::Join': [
34-
// // '',
35-
// // [
36-
// // 'athena-logs-',
37-
// // {
38-
// // Ref: 'AWS::AccountId',
39-
// // },
40-
// // '-',
41-
// // {
42-
// // Ref: 'AWS::Region',
43-
// // },
44-
// // ],
45-
// // ],
46-
// // },
47-
// // }),
48-
// // );
49-
// });
30+
// Test if the Amazon S3 Bucket for the result is correct
31+
template.hasResourceProperties('AWS::S3::Bucket',
32+
Match.objectLike({
33+
BucketName: {
34+
'Fn::Join': [
35+
'',
36+
[
37+
'demo-athena-logs-',
38+
{
39+
Ref: 'AWS::AccountId',
40+
},
41+
'-',
42+
{
43+
Ref: 'AWS::Region',
44+
},
45+
],
46+
],
47+
},
48+
}),
49+
);
50+
});
51+
52+
// Test if the Amazon S3 Bucket for the result is correct
53+
template.hasResourceProperties('AWS::S3::Bucket',
54+
Match.objectLike({
55+
BucketName: {
56+
'Fn::Join': [
57+
'',
58+
[
59+
'custom-name-athena-logs-',
60+
{
61+
Ref: 'AWS::AccountId',
62+
},
63+
'-',
64+
{
65+
Ref: 'AWS::Region',
66+
},
67+
],
68+
],
69+
},
70+
}),
71+
);
5072

5173
test('Athena Demo Setup creates the proper Athena workgroup', () => {
5274

@@ -74,5 +96,30 @@ describe ('AthenaDemoSetup', () => {
7496
},
7597
}),
7698
);
99+
100+
// Test if the Amazon Athena Workgroup is correct
101+
template.hasResourceProperties('AWS::Athena::WorkGroup',
102+
Match.objectLike({
103+
Name: 'custom-name',
104+
WorkGroupConfiguration: {
105+
RequesterPaysEnabled: true,
106+
PublishCloudWatchMetricsEnabled: false,
107+
ResultConfiguration: {
108+
OutputLocation: {
109+
'Fn::Join': [
110+
'',
111+
[
112+
's3://',
113+
{
114+
Ref: Match.anyValue(),
115+
},
116+
'/athena-console-results',
117+
],
118+
],
119+
},
120+
},
121+
},
122+
}),
123+
);
77124
});
78125
});

core/test/unit/cdk-nag/nag-athena-demo-setup.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const mockApp = new App();
1818

1919
const athenaDemoSetupStack = new Stack(mockApp, 'athena-demo-setup');
2020
// Instantiate an AthenaDemoSetup
21-
new AthenaDemoSetup(athenaDemoSetupStack, 'athenaDemo');
21+
new AthenaDemoSetup(athenaDemoSetupStack, 'athenaDemo', {});
2222

2323
Aspects.of(athenaDemoSetupStack).add(new AwsSolutionsChecks());
2424

0 commit comments

Comments
 (0)