Skip to content

Commit 186b8ab

Browse files
authored
fix(scheduler-alpha): scheduler input always get transformed to string with extra double quotes (#31894)
### Issue # (if applicable) None ### Reason for this change When using `ScheduleTargetInput.fromText("some-string")`, the string is always wrapped with an extra double quotes in the final template: ``` "Input": "\"some-string\"", ``` Customers cannot get rid of the extra escaped double quotes other than using escape hatches. ### Description of changes Skip converting the text to JSON string, which is the reason causing the extra double quotes. ### Description of how you validated changes Unit test and integ test. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* ---- BREAKING CHANGE: Got rid of extra double quotes on Schedule input which blocks customer intention of using no double quotes in the input text
1 parent 8c15b5f commit 186b8ab

25 files changed

+48845
-45323
lines changed

packages/@aws-cdk/aws-scheduler-alpha/lib/input.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export abstract class ScheduleTargetInput {
1818
* @param text Text to use as the input for the target
1919
*/
2020
public static fromText(text: string): ScheduleTargetInput {
21-
return new FieldAwareEventInput(text);
21+
return new FieldAwareEventInput(text, false);
2222
}
2323

2424
/**
@@ -28,7 +28,7 @@ export abstract class ScheduleTargetInput {
2828
* @param obj object to use to convert to JSON to use as input for the target
2929
*/
3030
public static fromObject(obj: any): ScheduleTargetInput {
31-
return new FieldAwareEventInput(obj);
31+
return new FieldAwareEventInput(obj, true);
3232
}
3333

3434
protected constructor() {
@@ -41,7 +41,7 @@ export abstract class ScheduleTargetInput {
4141
}
4242

4343
class FieldAwareEventInput extends ScheduleTargetInput {
44-
constructor(private readonly input: any) {
44+
constructor(private readonly input: any, private readonly toJsonString: boolean) {
4545
super();
4646
}
4747

@@ -57,10 +57,11 @@ class FieldAwareEventInput extends ScheduleTargetInput {
5757
}
5858

5959
const stack = Stack.of(schedule);
60-
return stack.toJsonString(Tokenization.resolve(this.input, {
60+
const inputString = Tokenization.resolve(this.input, {
6161
scope: schedule,
6262
resolver: new Replacer(),
63-
}));
63+
});
64+
return this.toJsonString ? stack.toJsonString(inputString) : inputString;
6465
}
6566
}
6667

packages/@aws-cdk/aws-scheduler-alpha/test/input.test.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,44 @@ describe('schedule target input', () => {
4343
Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
4444
Properties: {
4545
Target: {
46-
Input: '"test"',
46+
Input: 'test',
4747
},
4848
},
4949
});
5050
});
5151

52-
test('create an input from text with a ref inside', () => {
52+
test('create an input from text concatenated from literal string with a token', () => {
5353
new Schedule(stack, 'MyScheduleDummy', {
5454
schedule: expr,
55-
target: new SomeLambdaTarget(func, ScheduleTargetInput.fromText(stack.account)),
55+
target: new SomeLambdaTarget(func, ScheduleTargetInput.fromText(`ac-${stack.account}`)),
5656
});
57+
5758
Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
5859
Properties: {
5960
Target: {
6061
Input: {
61-
'Fn::Join': ['', ['"', { Ref: 'AWS::AccountId' }, '"']],
62+
'Fn::Join': ['', ['ac-', { Ref: 'AWS::AccountId' }]],
6263
},
6364
},
6465
},
6566
});
6667
});
6768

69+
test('create an input from text with a ref inside', () => {
70+
new Schedule(stack, 'MyScheduleDummy', {
71+
schedule: expr,
72+
target: new SomeLambdaTarget(func, ScheduleTargetInput.fromText(stack.account)),
73+
});
74+
75+
Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
76+
Properties: {
77+
Target: {
78+
Input: { Ref: 'AWS::AccountId' },
79+
},
80+
},
81+
});
82+
});
83+
6884
test('create an input from object', () => {
6985
const input = ScheduleTargetInput.fromObject({
7086
test: 'test',
@@ -115,7 +131,7 @@ describe('schedule target input', () => {
115131
Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
116132
Properties: {
117133
Target: {
118-
Input: '"Test=<aws.scheduler.schedule-arn>"',
134+
Input: 'Test=<aws.scheduler.schedule-arn>',
119135
},
120136
},
121137
});

packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SomeLambdaTarget implements scheduler.IScheduleTarget {
1515
return {
1616
arn: this.fn.functionArn,
1717
role: this.role,
18-
input: scheduler.ScheduleTargetInput.fromText('Input Text'),
18+
input: scheduler.ScheduleTargetInput.fromObject('Input Text'),
1919
retryPolicy: {
2020
maximumEventAgeInSeconds: 180,
2121
maximumRetryAttempts: 3,

packages/@aws-cdk/aws-scheduler-targets-alpha/test/integ.lambda-invoke.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const importedLambdaTagValue = 'importedLambdaTagValue';
6262
new scheduler.Schedule(scheduleStack, 'ScheduleWithImportedLambda', {
6363
schedule: scheduler.ScheduleExpression.rate(cdk.Duration.minutes(1)),
6464
target: new LambdaInvoke(importedFunc, {
65-
input: scheduler.ScheduleTargetInput.fromText(importedLambdaTagValue),
65+
input: scheduler.ScheduleTargetInput.fromObject(importedLambdaTagValue),
6666
}),
6767
});
6868

@@ -88,7 +88,7 @@ const sameStackLambdaTagValue = 'sameStackLambdaTagValue';
8888
new scheduler.Schedule(scheduleStack, 'ScheduleWithSameStackLambda', {
8989
schedule: scheduler.ScheduleExpression.rate(cdk.Duration.minutes(1)),
9090
target: new LambdaInvoke(sameStackFunc, {
91-
input: scheduler.ScheduleTargetInput.fromText(sameStackLambdaTagValue),
91+
input: scheduler.ScheduleTargetInput.fromObject(sameStackLambdaTagValue),
9292
}),
9393
});
9494

packages/@aws-cdk/aws-scheduler-targets-alpha/test/integ.sns-publish.js.snapshot/AwsSchedulerTargetsSnsPublish.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-scheduler-targets-alpha/test/integ.sns-publish.js.snapshot/AwsSchedulerTargetsSnsPublish.template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"Arn": {
7676
"Ref": "TopicBFC7AF6E"
7777
},
78-
"Input": "\"Hello, Scheduler!\"",
78+
"Input": "Hello, Scheduler!",
7979
"RetryPolicy": {
8080
"MaximumEventAgeInSeconds": 86400,
8181
"MaximumRetryAttempts": 185

packages/@aws-cdk/aws-scheduler-targets-alpha/test/integ.sns-publish.js.snapshot/IntegTestSnsPublishDefaultTestDeployAssert36D5D430.assets.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)