diff --git a/packages/@aws-cdk/aws-glue/README.md b/packages/@aws-cdk/aws-glue/README.md index 31030b9af93a0..d5260e12d771d 100644 --- a/packages/@aws-cdk/aws-glue/README.md +++ b/packages/@aws-cdk/aws-glue/README.md @@ -136,7 +136,6 @@ A `SecurityConfiguration` is a set of security properties that can be used by AW ```ts new glue.SecurityConfiguration(this, 'MySecurityConfiguration', { - securityConfigurationName: 'name', cloudWatchEncryption: { mode: glue.CloudWatchEncryptionMode.KMS, }, @@ -154,7 +153,6 @@ By default, a shared KMS key is created for use with the encryption configuratio ```ts declare const key: kms.Key; new glue.SecurityConfiguration(this, 'MySecurityConfiguration', { - securityConfigurationName: 'name', cloudWatchEncryption: { mode: glue.CloudWatchEncryptionMode.KMS, kmsKey: key, @@ -169,9 +167,7 @@ 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', { - databaseName: 'my_database', -}); +new glue.Database(this, 'MyDatabase'); ``` ## Table @@ -182,7 +178,6 @@ A Glue table describes a table of data in S3: its structure (column names and ty declare const myDatabase: glue.Database; new glue.Table(this, 'MyTable', { database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -205,7 +200,6 @@ new glue.Table(this, 'MyTable', { s3Prefix: 'my-table/', // ... database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -224,7 +218,6 @@ To improve query performance, a table can specify `partitionKeys` on which data declare const myDatabase: glue.Database; new glue.Table(this, 'MyTable', { database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -256,7 +249,6 @@ property: declare const myDatabase: glue.Database; new glue.Table(this, 'MyTable', { database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -294,7 +286,6 @@ If you have a table with a large number of partitions that grows over time, cons declare const myDatabase: glue.Database; new glue.Table(this, 'MyTable', { database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -324,7 +315,6 @@ new glue.Table(this, 'MyTable', { encryption: glue.TableEncryption.S3_MANAGED, // ... database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -342,7 +332,6 @@ new glue.Table(this, 'MyTable', { encryption: glue.TableEncryption.KMS, // ... database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -356,7 +345,6 @@ new glue.Table(this, 'MyTable', { encryptionKey: new kms.Key(this, 'MyKey'), // ... database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -373,7 +361,6 @@ new glue.Table(this, 'MyTable', { encryption: glue.TableEncryption.KMS_MANAGED, // ... database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -391,7 +378,6 @@ new glue.Table(this, 'MyTable', { encryption: glue.TableEncryption.CLIENT_SIDE_KMS, // ... database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -405,7 +391,6 @@ new glue.Table(this, 'MyTable', { encryptionKey: new kms.Key(this, 'MyKey'), // ... database: myDatabase, - tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -447,7 +432,6 @@ new glue.Table(this, 'MyTable', { }], // ... database: myDatabase, - tableName: 'my_table', dataFormat: glue.DataFormat.JSON, }); ``` diff --git a/packages/@aws-cdk/aws-glue/lib/database.ts b/packages/@aws-cdk/aws-glue/lib/database.ts index e93afa2a5fc3c..8032dc17315a4 100644 --- a/packages/@aws-cdk/aws-glue/lib/database.ts +++ b/packages/@aws-cdk/aws-glue/lib/database.ts @@ -1,4 +1,4 @@ -import { ArnFormat, IResource, Resource, Stack } from '@aws-cdk/core'; +import { ArnFormat, IResource, Lazy, Names, Resource, Stack } from '@aws-cdk/core'; import { Construct } from 'constructs'; import { CfnDatabase } from './glue.generated'; @@ -31,8 +31,10 @@ export interface IDatabase extends IResource { export interface DatabaseProps { /** * The name of the database. + * + * @default - generated by CDK. */ - readonly databaseName: string; + readonly databaseName?: string; /** * The location of the database (for example, an HDFS path). @@ -86,13 +88,16 @@ export class Database extends Resource implements IDatabase { */ public readonly locationUri?: string; - constructor(scope: Construct, id: string, props: DatabaseProps) { + constructor(scope: Construct, id: string, props: DatabaseProps = {}) { super(scope, id, { - physicalName: props.databaseName, + physicalName: props.databaseName ?? + Lazy.string({ + produce: () => Names.uniqueResourceName(this, {}).toLowerCase(), + }), }); let databaseInput: CfnDatabase.DatabaseInputProperty = { - name: props.databaseName, + name: this.physicalName, }; if (props.locationUri !== undefined) { diff --git a/packages/@aws-cdk/aws-glue/lib/security-configuration.ts b/packages/@aws-cdk/aws-glue/lib/security-configuration.ts index f1e7297147794..b62112f0ce1d6 100644 --- a/packages/@aws-cdk/aws-glue/lib/security-configuration.ts +++ b/packages/@aws-cdk/aws-glue/lib/security-configuration.ts @@ -1,5 +1,6 @@ import * as kms from '@aws-cdk/aws-kms'; import * as cdk from '@aws-cdk/core'; +import { Lazy, Names } from '@aws-cdk/core'; import * as constructs from 'constructs'; import { CfnSecurityConfiguration } from './glue.generated'; @@ -114,8 +115,10 @@ export interface JobBookmarksEncryption { export interface SecurityConfigurationProps { /** * The name of the security configuration. + * + * @default - generated by CDK. */ - readonly securityConfigurationName: string; + readonly securityConfigurationName?: string; /** * The encryption configuration for Amazon CloudWatch Logs. @@ -184,9 +187,12 @@ export class SecurityConfiguration extends cdk.Resource implements ISecurityConf */ public readonly s3EncryptionKey?: kms.IKey; - constructor(scope: constructs.Construct, id: string, props: SecurityConfigurationProps) { + constructor(scope: constructs.Construct, id: string, props: SecurityConfigurationProps = {}) { super(scope, id, { - physicalName: props.securityConfigurationName, + physicalName: props.securityConfigurationName ?? + Lazy.string({ + produce: () => Names.uniqueResourceName(this, {}), + }), }); if (!props.s3Encryption && !props.cloudWatchEncryption && !props.jobBookmarksEncryption) { @@ -230,7 +236,7 @@ export class SecurityConfiguration extends cdk.Resource implements ISecurityConf } const resource = new CfnSecurityConfiguration(this, 'Resource', { - name: props.securityConfigurationName, + name: this.physicalName, encryptionConfiguration: { cloudWatchEncryption, jobBookmarksEncryption, diff --git a/packages/@aws-cdk/aws-glue/lib/table.ts b/packages/@aws-cdk/aws-glue/lib/table.ts index ea958879d816b..0bd08a798b18f 100644 --- a/packages/@aws-cdk/aws-glue/lib/table.ts +++ b/packages/@aws-cdk/aws-glue/lib/table.ts @@ -1,7 +1,7 @@ import * as iam from '@aws-cdk/aws-iam'; import * as kms from '@aws-cdk/aws-kms'; import * as s3 from '@aws-cdk/aws-s3'; -import { ArnFormat, Fn, IResource, Names, Resource, Stack } from '@aws-cdk/core'; +import { ArnFormat, Fn, IResource, Lazy, Names, Resource, Stack } from '@aws-cdk/core'; import * as cr from '@aws-cdk/custom-resources'; import { AwsCustomResource } from '@aws-cdk/custom-resources'; import { Construct } from 'constructs'; @@ -83,8 +83,10 @@ export interface TableAttributes { export interface TableProps { /** * Name of the table. + * + * @default - generated by CDK. */ - readonly tableName: string; + readonly tableName?: string; /** * Description of the table. @@ -282,7 +284,10 @@ export class Table extends Resource implements ITable { constructor(scope: Construct, id: string, props: TableProps) { super(scope, id, { - physicalName: props.tableName, + physicalName: props.tableName ?? + Lazy.string({ + produce: () => Names.uniqueResourceName(this, {}).toLowerCase(), + }), }); this.database = props.database; @@ -306,7 +311,7 @@ export class Table extends Resource implements ITable { tableInput: { name: this.physicalName, - description: props.description || `${props.tableName} generated by CDK`, + description: props.description || `${this.physicalName} generated by CDK`, partitionKeys: renderColumns(props.partitionKeys), diff --git a/packages/@aws-cdk/aws-glue/test/database.test.ts b/packages/@aws-cdk/aws-glue/test/database.test.ts index 6d94eb710131a..637f7cecab8e1 100644 --- a/packages/@aws-cdk/aws-glue/test/database.test.ts +++ b/packages/@aws-cdk/aws-glue/test/database.test.ts @@ -14,9 +14,7 @@ beforeEach( () => { }); test('default database does not create a bucket', () => { - new glue.Database(stack, 'Database', { - databaseName: 'test_database', - }); + new glue.Database(stack, 'Database'); Template.fromStack(stack).templateMatches({ Resources: { @@ -27,7 +25,7 @@ test('default database does not create a bucket', () => { Ref: 'AWS::AccountId', }, DatabaseInput: { - Name: 'test_database', + Name: 'database', }, }, }, @@ -38,7 +36,6 @@ test('default database does not create a bucket', () => { test('explicit locationURI', () => { new glue.Database(stack, 'Database', { - databaseName: 'test_database', locationUri: 's3://my-uri/', }); @@ -52,7 +49,7 @@ test('explicit locationURI', () => { }, DatabaseInput: { LocationUri: 's3://my-uri/', - Name: 'test_database', + Name: 'database', }, }, }, @@ -78,7 +75,6 @@ test('fromDatabase', () => { test('locationUri length must be >= 1', () => { expect(() => new glue.Database(stack, 'Database', { - databaseName: 'test_database', locationUri: '', }), ).toThrow(); @@ -87,8 +83,18 @@ test('locationUri length must be >= 1', () => { test('locationUri length must be <= 1024', () => { expect(() => new glue.Database(stack, 'Database', { - databaseName: 'test_database', locationUri: 'a'.repeat(1025), }), ).toThrow(); }); + +test('can specify a physical name', () => { + new glue.Database(stack, 'Database', { + databaseName: 'my_database', + }); + Template.fromStack(stack).hasResourceProperties('AWS::Glue::Database', { + DatabaseInput: { + Name: 'my_database', + }, + }); +}); diff --git a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/aws-glue-connection.assets.json b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/aws-glue-connection.assets.json index 038b458f1930e..8b82f404206c1 100644 --- a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/aws-glue-connection.assets.json +++ b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/aws-glue-connection.assets.json @@ -1,5 +1,5 @@ { - "version": "20.0.0", + "version": "22.0.0", "files": { "f076d8bcdf0c659b5885c5698672513188f149a0fe66e8f214a4ff4eaf97fda9": { "source": { diff --git a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/cdk.out b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/cdk.out index 588d7b269d34f..145739f539580 100644 --- a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"20.0.0"} \ No newline at end of file +{"version":"22.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/integ.json b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/integ.json index c1be8a55da270..da91047cc2a94 100644 --- a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "20.0.0", + "version": "22.0.0", "testCases": { "integ.connection": { "stacks": [ diff --git a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/manifest.json b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/manifest.json index 8927a6ad37eae..f289952f0aa43 100644 --- a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/manifest.json @@ -1,12 +1,6 @@ { - "version": "20.0.0", + "version": "22.0.0", "artifacts": { - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - }, "aws-glue-connection.assets": { "type": "cdk:asset-manifest", "properties": { @@ -203,6 +197,12 @@ ] }, "displayName": "aws-glue-connection" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/tree.json b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/tree.json index e3f335fe35e24..d00e8b8a4faea 100644 --- a/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-glue/test/integ.connection.js.snapshot/tree.json @@ -4,14 +4,6 @@ "id": "App", "path": "", "children": { - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" - } - }, "aws-glue-connection": { "id": "aws-glue-connection", "path": "aws-glue-connection", @@ -91,8 +83,8 @@ "id": "Acl", "path": "aws-glue-connection/Vpc/PublicSubnet1/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -258,8 +250,8 @@ "id": "Acl", "path": "aws-glue-connection/Vpc/PublicSubnet2/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -425,8 +417,8 @@ "id": "Acl", "path": "aws-glue-connection/Vpc/PrivateSubnet1/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -544,8 +536,8 @@ "id": "Acl", "path": "aws-glue-connection/Vpc/PrivateSubnet2/Acl", "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" } }, "RouteTable": { @@ -742,17 +734,41 @@ "fqn": "@aws-cdk/aws-glue.Connection", "version": "0.0.0" } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "aws-glue-connection/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "aws-glue-connection/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } } }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.85" + "version": "10.1.168" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-glue/test/security-configuration.test.ts b/packages/@aws-cdk/aws-glue/test/security-configuration.test.ts index ca42a4eb53453..1af745354e695 100644 --- a/packages/@aws-cdk/aws-glue/test/security-configuration.test.ts +++ b/packages/@aws-cdk/aws-glue/test/security-configuration.test.ts @@ -6,9 +6,8 @@ import * as glue from '../lib'; test('throws when a security configuration has no encryption config', () => { const stack = new cdk.Stack(); - expect(() => new glue.SecurityConfiguration(stack, 'SecurityConfiguration', { - securityConfigurationName: 'name', - })).toThrowError(/One of cloudWatchEncryption, jobBookmarksEncryption or s3Encryption must be defined/); + expect(() => new glue.SecurityConfiguration(stack, 'SecurityConfiguration')) + .toThrowError(/One of cloudWatchEncryption, jobBookmarksEncryption or s3Encryption must be defined/); }); test('a security configuration with encryption configuration requiring kms key and providing an explicit one', () => { @@ -17,7 +16,6 @@ test('a security configuration with encryption configuration requiring kms key a const key = kms.Key.fromKeyArn(stack, 'ImportedKey', keyArn); const securityConfiguration = new glue.SecurityConfiguration(stack, 'SecurityConfiguration', { - securityConfigurationName: 'name', cloudWatchEncryption: { mode: glue.CloudWatchEncryptionMode.KMS, kmsKey: key, @@ -29,7 +27,7 @@ test('a security configuration with encryption configuration requiring kms key a expect(securityConfiguration.s3EncryptionKey).toBeUndefined(); Template.fromStack(stack).hasResourceProperties('AWS::Glue::SecurityConfiguration', { - Name: 'name', + Name: 'SecurityConfiguration', EncryptionConfiguration: { CloudWatchEncryption: { CloudWatchEncryptionMode: 'SSE-KMS', @@ -43,7 +41,6 @@ test('a security configuration with an encryption configuration requiring kms ke const stack = new cdk.Stack(); const securityConfiguration = new glue.SecurityConfiguration(stack, 'SecurityConfiguration', { - securityConfigurationName: 'name', cloudWatchEncryption: { mode: glue.CloudWatchEncryptionMode.KMS, }, @@ -56,7 +53,7 @@ test('a security configuration with an encryption configuration requiring kms ke Template.fromStack(stack).resourceCountIs('AWS::KMS::Key', 1); Template.fromStack(stack).hasResourceProperties('AWS::Glue::SecurityConfiguration', { - Name: 'name', + Name: 'SecurityConfiguration', EncryptionConfiguration: { CloudWatchEncryption: { CloudWatchEncryptionMode: 'SSE-KMS', @@ -72,7 +69,6 @@ test('a security configuration with all encryption configs and mixed kms key inp const key = kms.Key.fromKeyArn(stack, 'ImportedKey', keyArn); const securityConfiguration = new glue.SecurityConfiguration(stack, 'SecurityConfiguration', { - securityConfigurationName: 'name', cloudWatchEncryption: { mode: glue.CloudWatchEncryptionMode.KMS, }, @@ -92,7 +88,7 @@ test('a security configuration with all encryption configs and mixed kms key inp Template.fromStack(stack).resourceCountIs('AWS::KMS::Key', 1); Template.fromStack(stack).hasResourceProperties('AWS::Glue::SecurityConfiguration', { - Name: 'name', + Name: 'SecurityConfiguration', EncryptionConfiguration: { CloudWatchEncryption: { CloudWatchEncryptionMode: 'SSE-KMS', @@ -119,3 +115,16 @@ test('fromSecurityConfigurationName', () => { expect(securityConfiguration.securityConfigurationName).toEqual(name); }); + +test('can specify a physical name', () => { + const stack = new cdk.Stack(); + new glue.SecurityConfiguration(stack, 'SecurityConfiguration', { + securityConfigurationName: 'MySecurityConfiguration', + cloudWatchEncryption: { + mode: glue.CloudWatchEncryptionMode.KMS, + }, + }); + Template.fromStack(stack).hasResourceProperties('AWS::Glue::SecurityConfiguration', { + Name: 'MySecurityConfiguration', + }); +}); diff --git a/packages/@aws-cdk/aws-glue/test/table.test.ts b/packages/@aws-cdk/aws-glue/test/table.test.ts index 152c489dd520c..520c6a8528f49 100644 --- a/packages/@aws-cdk/aws-glue/test/table.test.ts +++ b/packages/@aws-cdk/aws-glue/test/table.test.ts @@ -10,14 +10,11 @@ import { CfnTable } from '../lib/glue.generated'; test('unpartitioned JSON table', () => { const app = new cdk.App(); const dbStack = new cdk.Stack(app, 'db'); - const database = new glue.Database(dbStack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(dbStack, 'Database'); const tableStack = new cdk.Stack(app, 'table'); const table = new glue.Table(tableStack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -40,8 +37,8 @@ test('unpartitioned JSON table', () => { 'Fn::ImportValue': 'db:ExportsOutputRefDatabaseB269D8BB88F4B1C4', }, TableInput: { - Name: 'table', - Description: 'table generated by CDK', + Name: 'tabletable8fff2c2b', + Description: 'tabletable8fff2c2b generated by CDK', Parameters: { classification: 'json', has_encrypted_data: false, @@ -81,14 +78,11 @@ test('unpartitioned JSON table', () => { test('partitioned JSON table', () => { const app = new cdk.App(); const dbStack = new cdk.Stack(app, 'db'); - const database = new glue.Database(dbStack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(dbStack, 'Database'); const tableStack = new cdk.Stack(app, 'table'); const table = new glue.Table(tableStack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -111,8 +105,8 @@ test('partitioned JSON table', () => { 'Fn::ImportValue': 'db:ExportsOutputRefDatabaseB269D8BB88F4B1C4', }, TableInput: { - Name: 'table', - Description: 'table generated by CDK', + Name: 'tabletable8fff2c2b', + Description: 'tabletable8fff2c2b generated by CDK', Parameters: { classification: 'json', has_encrypted_data: false, @@ -157,13 +151,10 @@ test('partitioned JSON table', () => { test('compressed table', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -223,14 +214,11 @@ test('compressed table', () => { test('table.node.defaultChild', () => { // GIVEN const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); // WHEN const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -245,13 +233,10 @@ test('table.node.defaultChild', () => { test('encrypted table: SSE-S3', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -323,13 +308,10 @@ test('encrypted table: SSE-S3', () => { test('encrypted table: SSE-KMS (implicitly created key)', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -410,16 +392,13 @@ test('encrypted table: SSE-KMS (implicitly created key)', () => { test('encrypted table: SSE-KMS (explicitly created key)', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const encryptionKey = new kms.Key(stack, 'MyKey', { description: 'OurKey', }); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -502,13 +481,10 @@ test('encrypted table: SSE-KMS (explicitly created key)', () => { test('encrypted table: SSE-KMS_MANAGED', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -580,13 +556,10 @@ test('encrypted table: SSE-KMS_MANAGED', () => { test('encrypted table: CSE-KMS (implicitly created key)', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -648,16 +621,13 @@ test('encrypted table: CSE-KMS (implicitly created key)', () => { test('encrypted table: CSE-KMS (explicitly created key)', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const encryptionKey = new kms.Key(stack, 'MyKey', { description: 'MyKey', }); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -722,9 +692,7 @@ test('encrypted table: CSE-KMS (explicitly created key)', () => { test('encrypted table: CSE-KMS (explicitly passed bucket and key)', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const bucket = new s3.Bucket(stack, 'Bucket'); const encryptionKey = new kms.Key(stack, 'MyKey', { description: 'MyKey', @@ -732,7 +700,6 @@ test('encrypted table: CSE-KMS (explicitly passed bucket and key)', () => { const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -801,15 +768,12 @@ test('explicit s3 bucket and prefix', () => { const dbStack = new cdk.Stack(app, 'db'); const stack = new cdk.Stack(app, 'app'); const bucket = new s3.Bucket(stack, 'ExplicitBucket'); - const database = new glue.Database(dbStack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(dbStack, 'Database'); new glue.Table(stack, 'Table', { database, bucket, s3Prefix: 'prefix/', - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -825,8 +789,8 @@ test('explicit s3 bucket and prefix', () => { 'Fn::ImportValue': 'db:ExportsOutputRefDatabaseB269D8BB88F4B1C4', }, TableInput: { - Description: 'table generated by CDK', - Name: 'table', + Description: 'apptablecb9c398f generated by CDK', + Name: 'apptablecb9c398f', Parameters: { classification: 'json', has_encrypted_data: false, @@ -868,15 +832,12 @@ test('explicit s3 bucket and with empty prefix', () => { const dbStack = new cdk.Stack(app, 'db'); const stack = new cdk.Stack(app, 'app'); const bucket = new s3.Bucket(stack, 'ExplicitBucket'); - const database = new glue.Database(dbStack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(dbStack, 'Database'); new glue.Table(stack, 'Table', { database, bucket, s3Prefix: '', - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -892,8 +853,8 @@ test('explicit s3 bucket and with empty prefix', () => { 'Fn::ImportValue': 'db:ExportsOutputRefDatabaseB269D8BB88F4B1C4', }, TableInput: { - Description: 'table generated by CDK', - Name: 'table', + Description: 'apptablecb9c398f generated by CDK', + Name: 'apptablecb9c398f', Parameters: { classification: 'json', has_encrypted_data: false, @@ -933,13 +894,10 @@ test('explicit s3 bucket and with empty prefix', () => { describe('add partition index', () => { test('fails if no partition keys', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -955,13 +913,10 @@ describe('add partition index', () => { test('fails if partition index does not match partition keys', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -981,13 +936,10 @@ describe('add partition index', () => { test('fails with index name < 1 character', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -1007,9 +959,7 @@ describe('add partition index', () => { test('fails with > 3 indexes', () => { const stack = new cdk.Stack(); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const indexes: PartitionIndex[] = [{ indexName: 'ind1', @@ -1027,7 +977,6 @@ describe('add partition index', () => { expect(() => new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -1046,13 +995,10 @@ describe('grants', () => { test('custom permissions', () => { const stack = new cdk.Stack(); const user = new iam.User(stack, 'User'); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -1112,13 +1058,10 @@ describe('grants', () => { test('read only', () => { const stack = new cdk.Stack(); const user = new iam.User(stack, 'User'); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -1216,13 +1159,10 @@ describe('grants', () => { test('write only', () => { const stack = new cdk.Stack(); const user = new iam.User(stack, 'User'); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -1322,13 +1262,10 @@ describe('grants', () => { test('read and write', () => { const stack = new cdk.Stack(); const user = new iam.User(stack, 'User'); - const database = new glue.Database(stack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(stack, 'Database'); const table = new glue.Table(stack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -1441,7 +1378,6 @@ describe('validate', () => { expect(() => { createTable({ columns: [], - tableName: 'name', }); }).toThrowError('you must specify at least one column for the table'); @@ -1450,7 +1386,6 @@ describe('validate', () => { test('unique column names', () => { expect(() => { createTable({ - tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -1466,7 +1401,6 @@ describe('validate', () => { test('unique partition keys', () => { expect(() => { createTable({ - tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -1486,7 +1420,6 @@ describe('validate', () => { test('column names and partition keys are all unique', () => { expect(() => { createTable({ - tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -1503,7 +1436,6 @@ describe('validate', () => { test('can not specify an explicit bucket and encryption', () => { expect(() => { createTable({ - tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -1516,7 +1448,6 @@ describe('validate', () => { test('can explicitly pass bucket if Encryption undefined', () => { expect(() => createTable({ - tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -1528,7 +1459,6 @@ describe('validate', () => { test('can explicitly pass bucket if Unencrypted', () => { expect(() => createTable({ - tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -1540,7 +1470,6 @@ describe('validate', () => { test('can explicitly pass bucket if ClientSideKms', () => { expect(() => createTable({ - tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.STRING, @@ -1569,14 +1498,11 @@ test.each([ ])('Partition filtering on table %s', (_, enabled) => { const app = new cdk.App(); const dbStack = new cdk.Stack(app, 'db'); - const database = new glue.Database(dbStack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(dbStack, 'Database'); const tableStack = new cdk.Stack(app, 'table'); new glue.Table(tableStack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -1597,8 +1523,8 @@ test.each([ 'Fn::ImportValue': 'db:ExportsOutputRefDatabaseB269D8BB88F4B1C4', }, TableInput: { - Name: 'table', - Description: 'table generated by CDK', + Name: 'tabletable8fff2c2b', + Description: 'tabletable8fff2c2b generated by CDK', Parameters: { 'classification': 'json', 'has_encrypted_data': false, @@ -1614,14 +1540,11 @@ test.each([ test('Partition filtering on table is not defined (default behavior)', () => { const app = new cdk.App(); const dbStack = new cdk.Stack(app, 'db'); - const database = new glue.Database(dbStack, 'Database', { - databaseName: 'database', - }); + const database = new glue.Database(dbStack, 'Database'); const tableStack = new cdk.Stack(app, 'table'); new glue.Table(tableStack, 'Table', { database, - tableName: 'table', columns: [{ name: 'col', type: glue.Schema.STRING, @@ -1642,8 +1565,8 @@ test('Partition filtering on table is not defined (default behavior)', () => { 'Fn::ImportValue': 'db:ExportsOutputRefDatabaseB269D8BB88F4B1C4', }, TableInput: { - Name: 'table', - Description: 'table generated by CDK', + Name: 'tabletable8fff2c2b', + Description: 'tabletable8fff2c2b generated by CDK', Parameters: { classification: 'json', has_encrypted_data: false, @@ -1655,13 +1578,33 @@ test('Partition filtering on table is not defined (default behavior)', () => { }); }); +test('can specify a physical name', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app, 'Stack'); + const database = new glue.Database(stack, 'Database'); + new glue.Table(stack, 'Table', { + database, + tableName: 'my_table', + columns: [{ + name: 'col', + type: glue.Schema.STRING, + }], + dataFormat: glue.DataFormat.JSON, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::Glue::Table', { + TableInput: { + Name: 'my_table', + Description: 'my_table generated by CDK', + }, + }); +}); + function createTable(props: Pick>): void { const stack = new cdk.Stack(); new glue.Table(stack, 'table', { ...props, - database: new glue.Database(stack, 'db', { - databaseName: 'database_name', - }), + database: new glue.Database(stack, 'db'), dataFormat: glue.DataFormat.JSON, }); }