Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(glue): database description property #27744

Merged
merged 7 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-glue-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ See [documentation](https://docs.aws.amazon.com/glue/latest/dg/encryption-securi
A `Database` is a logical grouping of `Tables` in the Glue Catalog.

```ts
new glue.Database(this, 'MyDatabase');
new glue.Database(this, 'MyDatabase', {
databaseName: 'my_database',
description: 'my_database_description',
});
```

## Table
Expand Down
20 changes: 19 additions & 1 deletion packages/@aws-cdk/aws-glue-alpha/lib/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export interface DatabaseProps {
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-database-databaseinput.html
*/
readonly locationUri?: string;

/**
* A description of the database.
*
* @default - no database description
*/
readonly description?: string;
}

/**
Expand Down Expand Up @@ -96,8 +103,13 @@ export class Database extends Resource implements IDatabase {
}),
});

if (props.description !== undefined) {
validateDescription(props.description);
}

let databaseInput: CfnDatabase.DatabaseInputProperty = {
name: this.physicalName,
description: props.description,
};

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

function validateLocationUri(locationUri: string): void {
if (locationUri.length < 1 || locationUri.length > 1024) {
throw new Error(`locationUri length must be (inclusively) between 1 and 1024, but was ${locationUri.length}`);
throw new Error(`locationUri length must be (inclusively) between 1 and 1024, got ${locationUri.length}`);
}
}

function validateDescription(description: string): void {
if (description.length > 2048) {
throw new Error(`description length must be less than or equal to 2048, got ${description.length}`);
}
}
33 changes: 32 additions & 1 deletion packages/@aws-cdk/aws-glue-alpha/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ test('explicit locationURI', () => {

});

test('explicit description', () => {
new glue.Database(stack, 'Database', {
description: 'database-description',
});

Template.fromStack(stack).templateMatches({
Resources: {
DatabaseB269D8BB: {
Type: 'AWS::Glue::Database',
Properties: {
CatalogId: {
Ref: 'AWS::AccountId',
},
DatabaseInput: {
Description: 'database-description',
Name: 'database',
},
},
},
},
});
});

test('fromDatabase', () => {
// WHEN
const database = glue.Database.fromDatabaseArn(stack, 'import', 'arn:aws:glue:us-east-1:123456789012:database/db1');
Expand Down Expand Up @@ -85,7 +108,15 @@ test('locationUri length must be <= 1024', () => {
new glue.Database(stack, 'Database', {
locationUri: 'a'.repeat(1025),
}),
).toThrow();
).toThrow('locationUri length must be (inclusively) between 1 and 1024, got 1025');
});

test('description length must be <= 2048', () => {
expect(() =>
new glue.Database(stack, 'Database', {
description: 'a'.repeat(2049),
}),
).toThrow('description length must be less than or equal to 2048, got 2049');
});

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"Ref": "AWS::AccountId"
},
"DatabaseInput": {
"Description": "my_database_description",
"Name": "my_database"
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-glue-alpha/test/integ.table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const bucket = new s3.Bucket(stack, 'DataBucket', {

const database = new glue.Database(stack, 'MyDatabase', {
databaseName: 'my_database',
description: 'my_database_description',
});

const columns = [{
Expand Down