Skip to content

Commit 923b9f1

Browse files
authored
fix(events-targets): parameter JobName can exceed limit of 128 characters (#24786)
`BatchJob` should generate a `JobName` with a length smaller than 128 characters, otherwise, it will fail during `synth`. Closes #24654. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8a655bd commit 923b9f1

File tree

11 files changed

+1021
-2
lines changed

11 files changed

+1021
-2
lines changed

packages/@aws-cdk/aws-batch/test/aws-events-targets/batch.test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,37 @@ describe('Batch job event target', () => {
310310
],
311311
});
312312
});
313+
314+
test('should validate jobName minimum and maximum length', () => {
315+
const rule = new events.Rule(stack, 'Rule', {
316+
schedule: events.Schedule.expression('rate(1 min)'),
317+
});
318+
319+
expect(() => {
320+
rule.addTarget(
321+
new targets.BatchJob(
322+
jobQueue.jobQueueArn,
323+
jobQueue,
324+
jobDefinition.jobDefinitionArn,
325+
jobDefinition,
326+
{
327+
jobName: '',
328+
},
329+
),
330+
);
331+
}).toThrowError(/must have length between 1 and 128/);
332+
expect(() => {
333+
rule.addTarget(
334+
new targets.BatchJob(
335+
jobQueue.jobQueueArn,
336+
jobQueue,
337+
jobDefinition.jobDefinitionArn,
338+
jobDefinition,
339+
{
340+
jobName: 'a'.repeat(200),
341+
},
342+
),
343+
);
344+
}).toThrowError(/must have length between 1 and 128/);
345+
});
313346
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "31.0.0",
3+
"files": {
4+
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
5+
"source": {
6+
"path": "BatchUniqueNameTestDefaultTestDeployAssertA3886AB9.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"Parameters": {
3+
"BootstrapVersion": {
4+
"Type": "AWS::SSM::Parameter::Value<String>",
5+
"Default": "/cdk-bootstrap/hnb659fds/version",
6+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
7+
}
8+
},
9+
"Rules": {
10+
"CheckBootstrapVersion": {
11+
"Assertions": [
12+
{
13+
"Assert": {
14+
"Fn::Not": [
15+
{
16+
"Fn::Contains": [
17+
[
18+
"1",
19+
"2",
20+
"3",
21+
"4",
22+
"5"
23+
],
24+
{
25+
"Ref": "BootstrapVersion"
26+
}
27+
]
28+
}
29+
]
30+
},
31+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
32+
}
33+
]
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"31.0.0"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "31.0.0",
3+
"testCases": {
4+
"BatchUniqueNameTest/DefaultTest": {
5+
"stacks": [
6+
"stack"
7+
],
8+
"assertionStack": "BatchUniqueNameTest/DefaultTest/DeployAssert",
9+
"assertionStackName": "BatchUniqueNameTestDefaultTestDeployAssertA3886AB9"
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"version": "31.0.0",
3+
"artifacts": {
4+
"stack.assets": {
5+
"type": "cdk:asset-manifest",
6+
"properties": {
7+
"file": "stack.assets.json",
8+
"requiresBootstrapStackVersion": 6,
9+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
10+
}
11+
},
12+
"stack": {
13+
"type": "aws:cloudformation:stack",
14+
"environment": "aws://unknown-account/unknown-region",
15+
"properties": {
16+
"templateFile": "stack.template.json",
17+
"validateOnSynth": false,
18+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
19+
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/fc5aee66236b7c22643f298a9dbade30928a43ce59854880e447781626009ffe.json",
21+
"requiresBootstrapStackVersion": 6,
22+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
23+
"additionalDependencies": [
24+
"stack.assets"
25+
],
26+
"lookupRole": {
27+
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
28+
"requiresBootstrapStackVersion": 8,
29+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
30+
}
31+
},
32+
"dependencies": [
33+
"stack.assets"
34+
],
35+
"metadata": {
36+
"/stack/ComputeEnvironment/BatchServiceRole/Resource": [
37+
{
38+
"type": "aws:cdk:logicalId",
39+
"data": "ComputeEnvironmentBatchServiceRole3533BE31"
40+
}
41+
],
42+
"/stack/ComputeEnvironment/Resource": [
43+
{
44+
"type": "aws:cdk:logicalId",
45+
"data": "ComputeEnvironmentC570994D"
46+
}
47+
],
48+
"/stack/MyQueue/MyQueue": [
49+
{
50+
"type": "aws:cdk:logicalId",
51+
"data": "MyQueue4F9177CF"
52+
}
53+
],
54+
"/stack/container/ExecutionRole/Resource": [
55+
{
56+
"type": "aws:cdk:logicalId",
57+
"data": "containerExecutionRoleFD602179"
58+
}
59+
],
60+
"/stack/MyJob/Resource": [
61+
{
62+
"type": "aws:cdk:logicalId",
63+
"data": "MyJob8719E923"
64+
}
65+
],
66+
"/stack/MyJob/EventsRole/Resource": [
67+
{
68+
"type": "aws:cdk:logicalId",
69+
"data": "MyJobEventsRoleCF43C336"
70+
}
71+
],
72+
"/stack/MyJob/EventsRole/DefaultPolicy/Resource": [
73+
{
74+
"type": "aws:cdk:logicalId",
75+
"data": "MyJobEventsRoleDefaultPolicy7266D3A7"
76+
}
77+
],
78+
"/stack/Rule/Resource": [
79+
{
80+
"type": "aws:cdk:logicalId",
81+
"data": "Rule4C995B7F"
82+
}
83+
],
84+
"/stack/BootstrapVersion": [
85+
{
86+
"type": "aws:cdk:logicalId",
87+
"data": "BootstrapVersion"
88+
}
89+
],
90+
"/stack/CheckBootstrapVersion": [
91+
{
92+
"type": "aws:cdk:logicalId",
93+
"data": "CheckBootstrapVersion"
94+
}
95+
]
96+
},
97+
"displayName": "stack"
98+
},
99+
"BatchUniqueNameTestDefaultTestDeployAssertA3886AB9.assets": {
100+
"type": "cdk:asset-manifest",
101+
"properties": {
102+
"file": "BatchUniqueNameTestDefaultTestDeployAssertA3886AB9.assets.json",
103+
"requiresBootstrapStackVersion": 6,
104+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
105+
}
106+
},
107+
"BatchUniqueNameTestDefaultTestDeployAssertA3886AB9": {
108+
"type": "aws:cloudformation:stack",
109+
"environment": "aws://unknown-account/unknown-region",
110+
"properties": {
111+
"templateFile": "BatchUniqueNameTestDefaultTestDeployAssertA3886AB9.template.json",
112+
"validateOnSynth": false,
113+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
114+
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
115+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
116+
"requiresBootstrapStackVersion": 6,
117+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
118+
"additionalDependencies": [
119+
"BatchUniqueNameTestDefaultTestDeployAssertA3886AB9.assets"
120+
],
121+
"lookupRole": {
122+
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
123+
"requiresBootstrapStackVersion": 8,
124+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
125+
}
126+
},
127+
"dependencies": [
128+
"BatchUniqueNameTestDefaultTestDeployAssertA3886AB9.assets"
129+
],
130+
"metadata": {
131+
"/BatchUniqueNameTest/DefaultTest/DeployAssert/BootstrapVersion": [
132+
{
133+
"type": "aws:cdk:logicalId",
134+
"data": "BootstrapVersion"
135+
}
136+
],
137+
"/BatchUniqueNameTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [
138+
{
139+
"type": "aws:cdk:logicalId",
140+
"data": "CheckBootstrapVersion"
141+
}
142+
]
143+
},
144+
"displayName": "BatchUniqueNameTest/DefaultTest/DeployAssert"
145+
},
146+
"Tree": {
147+
"type": "cdk:tree",
148+
"properties": {
149+
"file": "tree.json"
150+
}
151+
}
152+
}
153+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "31.0.0",
3+
"files": {
4+
"fc5aee66236b7c22643f298a9dbade30928a43ce59854880e447781626009ffe": {
5+
"source": {
6+
"path": "stack.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "fc5aee66236b7c22643f298a9dbade30928a43ce59854880e447781626009ffe.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}

0 commit comments

Comments
 (0)