From bdc1c26bc71b2c60ef18fec3a149fb5758acfcd3 Mon Sep 17 00:00:00 2001 From: Michael Sambol Date: Sat, 30 Dec 2023 15:48:28 -0600 Subject: [PATCH] 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* --- packages/@aws-cdk/aws-glue-alpha/README.md | 5 ++- .../@aws-cdk/aws-glue-alpha/lib/database.ts | 20 ++++++++++- .../aws-glue-alpha/test/database.test.ts | 33 ++++++++++++++++++- .../aws-cdk-glue.assets.json | 4 +-- .../aws-cdk-glue.template.json | 1 + .../integ.table.js.snapshot/manifest.json | 2 +- .../test/integ.table.js.snapshot/tree.json | 3 +- .../aws-glue-alpha/test/integ.table.ts | 1 + 8 files changed, 62 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-glue-alpha/README.md b/packages/@aws-cdk/aws-glue-alpha/README.md index 7da9ff427ecec..67018d6559724 100644 --- a/packages/@aws-cdk/aws-glue-alpha/README.md +++ b/packages/@aws-cdk/aws-glue-alpha/README.md @@ -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 diff --git a/packages/@aws-cdk/aws-glue-alpha/lib/database.ts b/packages/@aws-cdk/aws-glue-alpha/lib/database.ts index 8368caa0c89a5..6b208b3fdfecd 100644 --- a/packages/@aws-cdk/aws-glue-alpha/lib/database.ts +++ b/packages/@aws-cdk/aws-glue-alpha/lib/database.ts @@ -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; } /** @@ -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) { @@ -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}`); } } diff --git a/packages/@aws-cdk/aws-glue-alpha/test/database.test.ts b/packages/@aws-cdk/aws-glue-alpha/test/database.test.ts index 5acb1e88f09c2..2379c07071808 100644 --- a/packages/@aws-cdk/aws-glue-alpha/test/database.test.ts +++ b/packages/@aws-cdk/aws-glue-alpha/test/database.test.ts @@ -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'); @@ -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', () => { diff --git a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.assets.json b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.assets.json index 99d84e8b93cc1..d8eee410e2343 100644 --- a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.assets.json +++ b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.assets.json @@ -1,7 +1,7 @@ { "version": "34.0.0", "files": { - "b91bf4cf21d2d51d240c781968ceabd5c521d572397afa2f3e8ed032b9dab278": { + "da03946f3d9f7502490ea840d2b597db3ee9912d25cfc58e27cd53a0432b663e": { "source": { "path": "aws-cdk-glue.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "b91bf4cf21d2d51d240c781968ceabd5c521d572397afa2f3e8ed032b9dab278.json", + "objectKey": "da03946f3d9f7502490ea840d2b597db3ee9912d25cfc58e27cd53a0432b663e.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.template.json b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.template.json index 743215cd09bff..f55cb568118b6 100644 --- a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.template.json +++ b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.template.json @@ -12,6 +12,7 @@ "Ref": "AWS::AccountId" }, "DatabaseInput": { + "Description": "my_database_description", "Name": "my_database" } } diff --git a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/manifest.json b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/manifest.json index dee2a80c834e3..7fed09b87ad66 100644 --- a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/b91bf4cf21d2d51d240c781968ceabd5c521d572397afa2f3e8ed032b9dab278.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/da03946f3d9f7502490ea840d2b597db3ee9912d25cfc58e27cd53a0432b663e.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/tree.json b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/tree.json index 7d8e102d6d975..9b5807f68bb18 100644 --- a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/tree.json @@ -44,7 +44,8 @@ "Ref": "AWS::AccountId" }, "databaseInput": { - "name": "my_database" + "name": "my_database", + "description": "my_database_description" } } }, diff --git a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.ts b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.ts index 45d2ccb0110a1..250cf6ee3fedb 100644 --- a/packages/@aws-cdk/aws-glue-alpha/test/integ.table.ts +++ b/packages/@aws-cdk/aws-glue-alpha/test/integ.table.ts @@ -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 = [{