Skip to content

Commit cbac240

Browse files
authored
feat(glue): database description property (#27744)
Closes #27740. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a59dc0c commit cbac240

File tree

8 files changed

+62
-7
lines changed

8 files changed

+62
-7
lines changed

packages/@aws-cdk/aws-glue-alpha/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ See [documentation](https://docs.aws.amazon.com/glue/latest/dg/encryption-securi
202202
A `Database` is a logical grouping of `Tables` in the Glue Catalog.
203203

204204
```ts
205-
new glue.Database(this, 'MyDatabase');
205+
new glue.Database(this, 'MyDatabase', {
206+
databaseName: 'my_database',
207+
description: 'my_database_description',
208+
});
206209
```
207210

208211
## Table

packages/@aws-cdk/aws-glue-alpha/lib/database.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export interface DatabaseProps {
4343
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-database-databaseinput.html
4444
*/
4545
readonly locationUri?: string;
46+
47+
/**
48+
* A description of the database.
49+
*
50+
* @default - no database description
51+
*/
52+
readonly description?: string;
4653
}
4754

4855
/**
@@ -96,8 +103,13 @@ export class Database extends Resource implements IDatabase {
96103
}),
97104
});
98105

106+
if (props.description !== undefined) {
107+
validateDescription(props.description);
108+
}
109+
99110
let databaseInput: CfnDatabase.DatabaseInputProperty = {
100111
name: this.physicalName,
112+
description: props.description,
101113
};
102114

103115
if (props.locationUri !== undefined) {
@@ -133,6 +145,12 @@ export class Database extends Resource implements IDatabase {
133145

134146
function validateLocationUri(locationUri: string): void {
135147
if (locationUri.length < 1 || locationUri.length > 1024) {
136-
throw new Error(`locationUri length must be (inclusively) between 1 and 1024, but was ${locationUri.length}`);
148+
throw new Error(`locationUri length must be (inclusively) between 1 and 1024, got ${locationUri.length}`);
149+
}
150+
}
151+
152+
function validateDescription(description: string): void {
153+
if (description.length > 2048) {
154+
throw new Error(`description length must be less than or equal to 2048, got ${description.length}`);
137155
}
138156
}

packages/@aws-cdk/aws-glue-alpha/test/database.test.ts

+32-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ test('explicit locationURI', () => {
5858

5959
});
6060

61+
test('explicit description', () => {
62+
new glue.Database(stack, 'Database', {
63+
description: 'database-description',
64+
});
65+
66+
Template.fromStack(stack).templateMatches({
67+
Resources: {
68+
DatabaseB269D8BB: {
69+
Type: 'AWS::Glue::Database',
70+
Properties: {
71+
CatalogId: {
72+
Ref: 'AWS::AccountId',
73+
},
74+
DatabaseInput: {
75+
Description: 'database-description',
76+
Name: 'database',
77+
},
78+
},
79+
},
80+
},
81+
});
82+
});
83+
6184
test('fromDatabase', () => {
6285
// WHEN
6386
const database = glue.Database.fromDatabaseArn(stack, 'import', 'arn:aws:glue:us-east-1:123456789012:database/db1');
@@ -85,7 +108,15 @@ test('locationUri length must be <= 1024', () => {
85108
new glue.Database(stack, 'Database', {
86109
locationUri: 'a'.repeat(1025),
87110
}),
88-
).toThrow();
111+
).toThrow('locationUri length must be (inclusively) between 1 and 1024, got 1025');
112+
});
113+
114+
test('description length must be <= 2048', () => {
115+
expect(() =>
116+
new glue.Database(stack, 'Database', {
117+
description: 'a'.repeat(2049),
118+
}),
119+
).toThrow('description length must be less than or equal to 2048, got 2049');
89120
});
90121

91122
test('can specify a physical name', () => {

packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.assets.json

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

packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"Ref": "AWS::AccountId"
1313
},
1414
"DatabaseInput": {
15+
"Description": "my_database_description",
1516
"Name": "my_database"
1617
}
1718
}

packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/manifest.json

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

packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/tree.json

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

packages/@aws-cdk/aws-glue-alpha/test/integ.table.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const bucket = new s3.Bucket(stack, 'DataBucket', {
1616

1717
const database = new glue.Database(stack, 'MyDatabase', {
1818
databaseName: 'my_database',
19+
description: 'my_database_description',
1920
});
2021

2122
const columns = [{

0 commit comments

Comments
 (0)