From f6cca37c54c94ed04eacad28dd67e039eee644a2 Mon Sep 17 00:00:00 2001 From: Mike Wrighton Date: Mon, 9 Oct 2023 17:11:21 -0400 Subject: [PATCH 1/3] Fix prefix validation logic in aws-glue-alpha. --- packages/@aws-cdk/aws-glue-alpha/lib/job.ts | 10 +++++----- packages/@aws-cdk/aws-glue-alpha/test/job.test.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/@aws-cdk/aws-glue-alpha/lib/job.ts b/packages/@aws-cdk/aws-glue-alpha/lib/job.ts index 825511c1fdfab..5b56b260ae841 100644 --- a/packages/@aws-cdk/aws-glue-alpha/lib/job.ts +++ b/packages/@aws-cdk/aws-glue-alpha/lib/job.ts @@ -840,12 +840,12 @@ export class Job extends JobBase { const errors: string[] = []; - if (!prefix.startsWith('/')) { - errors.push('Prefix must begin with \'/\''); + if (prefix.startsWith('/')) { + errors.push('Prefix must not begin with \'/\''); } - if (prefix.endsWith('/')) { - errors.push('Prefix must not end with \'/\''); + if (!prefix.endsWith('/')) { + errors.push('Prefix must end with \'/\''); } if (errors.length > 0) { @@ -854,7 +854,7 @@ export class Job extends JobBase { } private cleanPrefixForGrant(prefix?: string): string | undefined { - return prefix !== undefined ? prefix.slice(1) + '/*' : undefined; + return prefix !== undefined ? `${prefix}*` : undefined; } private setupContinuousLogging(role: iam.IRole, props: ContinuousLoggingProps) { diff --git a/packages/@aws-cdk/aws-glue-alpha/test/job.test.ts b/packages/@aws-cdk/aws-glue-alpha/test/job.test.ts index cfea34c396147..748d89b5668a2 100644 --- a/packages/@aws-cdk/aws-glue-alpha/test/job.test.ts +++ b/packages/@aws-cdk/aws-glue-alpha/test/job.test.ts @@ -632,14 +632,14 @@ describe('Job', () => { }); describe('with bucket and path provided', () => { const sparkUIBucketName = 'sparkbucketname'; - const prefix = '/foob/bart'; - const badPrefix = 'foob/bart/'; + const prefix = 'foob/bart/'; + const badPrefix = '/foob/bart'; let sparkUIBucket: s3.IBucket; const expectedErrors = [ `Invalid prefix format (value: ${badPrefix})`, - 'Prefix must begin with \'/\'', - 'Prefix must not end with \'/\'', + 'Prefix must not begin with \'/\'', + 'Prefix must end with \'/\'', ].join(EOL); it('fails if path is mis-formatted', () => { expect(() => new glue.Job(stack, 'BadPrefixJob', { @@ -699,7 +699,7 @@ describe('Job', () => { [ 'arn:', { Ref: 'AWS::Partition' }, - `:s3:::sparkbucketname${prefix}/*`, + `:s3:::sparkbucketname/${prefix}*`, ], ], }, @@ -718,7 +718,7 @@ describe('Job', () => { Template.fromStack(stack).hasResourceProperties('AWS::Glue::Job', { DefaultArguments: { '--enable-spark-ui': 'true', - '--spark-event-logs-path': `s3://${sparkUIBucketName}${prefix}`, + '--spark-event-logs-path': `s3://${sparkUIBucketName}/${prefix}`, }, }); }); From e07a5d506b089e3fa87848f91b2946fa710eab55 Mon Sep 17 00:00:00 2001 From: Mike Wrighton Date: Tue, 10 Oct 2023 09:23:39 -0400 Subject: [PATCH 2/3] Comments --- packages/@aws-cdk/aws-glue-alpha/lib/job.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-glue-alpha/lib/job.ts b/packages/@aws-cdk/aws-glue-alpha/lib/job.ts index 5b56b260ae841..d9287d55340ff 100644 --- a/packages/@aws-cdk/aws-glue-alpha/lib/job.ts +++ b/packages/@aws-cdk/aws-glue-alpha/lib/job.ts @@ -384,13 +384,13 @@ export interface SparkUIProps { /** * The bucket where the Glue job stores the logs. * - * @default a new bucket will be created. + * @default - a new bucket will be created. */ readonly bucket?: s3.IBucket; /** * The path inside the bucket (objects prefix) where the Glue job stores the logs. - * Use format `'/foo/bar'` + * Use format `'foo/bar/'` * * @default - the logs will be written at the root of the bucket */ @@ -406,13 +406,15 @@ export interface SparkUIProps { export interface SparkUILoggingLocation { /** * The bucket where the Glue job stores the logs. + * + * @default - a new bucket will be created. */ readonly bucket: s3.IBucket; /** * The path inside the bucket (objects prefix) where the Glue job stores the logs. * - * @default '/' - the logs will be written at the root of the bucket + * @default - the logs will be written at the root of the bucket */ readonly prefix?: string; } From 598cdc3de589fa685c6deb71ba0a764672c200bb Mon Sep 17 00:00:00 2001 From: mikewrighton Date: Tue, 10 Oct 2023 11:08:22 -0400 Subject: [PATCH 3/3] Update packages/@aws-cdk/aws-glue-alpha/lib/job.ts Co-authored-by: Parker Scanlon <69879391+scanlonp@users.noreply.github.com> --- packages/@aws-cdk/aws-glue-alpha/lib/job.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-glue-alpha/lib/job.ts b/packages/@aws-cdk/aws-glue-alpha/lib/job.ts index d9287d55340ff..229d02173dd58 100644 --- a/packages/@aws-cdk/aws-glue-alpha/lib/job.ts +++ b/packages/@aws-cdk/aws-glue-alpha/lib/job.ts @@ -406,7 +406,7 @@ export interface SparkUIProps { export interface SparkUILoggingLocation { /** * The bucket where the Glue job stores the logs. - * + * * @default - a new bucket will be created. */ readonly bucket: s3.IBucket;