Skip to content

Commit b898d3b

Browse files
authored
fix(glue-alpha): prefix validation logic is incorrect (#27472)
There was logic in `aws-glue-alpha.Job` that expected `SparkUIProps.prefix` to be specified in the form `/prefix-name`, instead of the more conventional `prefix-name/`. This fix addresses the validation and handling of this prefix field to support the correct format. BREAKING CHANGE: `SparkUIProps.prefix` strings in the original `/prefix-name` format will now result in a validation error. To retain the same behavior, prefixes must be changed to the new `prefix-name/` format. Closes #27396. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7d92a9c commit b898d3b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,13 @@ export interface SparkUIProps {
384384
/**
385385
* The bucket where the Glue job stores the logs.
386386
*
387-
* @default a new bucket will be created.
387+
* @default - a new bucket will be created.
388388
*/
389389
readonly bucket?: s3.IBucket;
390390

391391
/**
392392
* The path inside the bucket (objects prefix) where the Glue job stores the logs.
393-
* Use format `'/foo/bar'`
393+
* Use format `'foo/bar/'`
394394
*
395395
* @default - the logs will be written at the root of the bucket
396396
*/
@@ -406,13 +406,15 @@ export interface SparkUIProps {
406406
export interface SparkUILoggingLocation {
407407
/**
408408
* The bucket where the Glue job stores the logs.
409+
*
410+
* @default - a new bucket will be created.
409411
*/
410412
readonly bucket: s3.IBucket;
411413

412414
/**
413415
* The path inside the bucket (objects prefix) where the Glue job stores the logs.
414416
*
415-
* @default '/' - the logs will be written at the root of the bucket
417+
* @default - the logs will be written at the root of the bucket
416418
*/
417419
readonly prefix?: string;
418420
}
@@ -840,12 +842,12 @@ export class Job extends JobBase {
840842

841843
const errors: string[] = [];
842844

843-
if (!prefix.startsWith('/')) {
844-
errors.push('Prefix must begin with \'/\'');
845+
if (prefix.startsWith('/')) {
846+
errors.push('Prefix must not begin with \'/\'');
845847
}
846848

847-
if (prefix.endsWith('/')) {
848-
errors.push('Prefix must not end with \'/\'');
849+
if (!prefix.endsWith('/')) {
850+
errors.push('Prefix must end with \'/\'');
849851
}
850852

851853
if (errors.length > 0) {
@@ -854,7 +856,7 @@ export class Job extends JobBase {
854856
}
855857

856858
private cleanPrefixForGrant(prefix?: string): string | undefined {
857-
return prefix !== undefined ? prefix.slice(1) + '/*' : undefined;
859+
return prefix !== undefined ? `${prefix}*` : undefined;
858860
}
859861

860862
private setupContinuousLogging(role: iam.IRole, props: ContinuousLoggingProps) {

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -632,14 +632,14 @@ describe('Job', () => {
632632
});
633633
describe('with bucket and path provided', () => {
634634
const sparkUIBucketName = 'sparkbucketname';
635-
const prefix = '/foob/bart';
636-
const badPrefix = 'foob/bart/';
635+
const prefix = 'foob/bart/';
636+
const badPrefix = '/foob/bart';
637637
let sparkUIBucket: s3.IBucket;
638638

639639
const expectedErrors = [
640640
`Invalid prefix format (value: ${badPrefix})`,
641-
'Prefix must begin with \'/\'',
642-
'Prefix must not end with \'/\'',
641+
'Prefix must not begin with \'/\'',
642+
'Prefix must end with \'/\'',
643643
].join(EOL);
644644
it('fails if path is mis-formatted', () => {
645645
expect(() => new glue.Job(stack, 'BadPrefixJob', {
@@ -699,7 +699,7 @@ describe('Job', () => {
699699
[
700700
'arn:',
701701
{ Ref: 'AWS::Partition' },
702-
`:s3:::sparkbucketname${prefix}/*`,
702+
`:s3:::sparkbucketname/${prefix}*`,
703703
],
704704
],
705705
},
@@ -718,7 +718,7 @@ describe('Job', () => {
718718
Template.fromStack(stack).hasResourceProperties('AWS::Glue::Job', {
719719
DefaultArguments: {
720720
'--enable-spark-ui': 'true',
721-
'--spark-event-logs-path': `s3://${sparkUIBucketName}${prefix}`,
721+
'--spark-event-logs-path': `s3://${sparkUIBucketName}/${prefix}`,
722722
},
723723
});
724724
});

0 commit comments

Comments
 (0)