diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/input.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/input.ts index 682ce0687e374..b7c87e1a98f86 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/input.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/input.ts @@ -18,7 +18,7 @@ export abstract class ScheduleTargetInput { * @param text Text to use as the input for the target */ public static fromText(text: string): ScheduleTargetInput { - return new FieldAwareEventInput(text); + return new FieldAwareEventInput(text, false); } /** @@ -28,7 +28,7 @@ export abstract class ScheduleTargetInput { * @param obj object to use to convert to JSON to use as input for the target */ public static fromObject(obj: any): ScheduleTargetInput { - return new FieldAwareEventInput(obj); + return new FieldAwareEventInput(obj, true); } protected constructor() { @@ -41,7 +41,7 @@ export abstract class ScheduleTargetInput { } class FieldAwareEventInput extends ScheduleTargetInput { - constructor(private readonly input: any) { + constructor(private readonly input: any, private readonly toJsonString: boolean) { super(); } @@ -57,10 +57,11 @@ class FieldAwareEventInput extends ScheduleTargetInput { } const stack = Stack.of(schedule); - return stack.toJsonString(Tokenization.resolve(this.input, { + const inputString = Tokenization.resolve(this.input, { scope: schedule, resolver: new Replacer(), - })); + }); + return this.toJsonString ? stack.toJsonString(inputString) : inputString; } } diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/input.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/input.test.ts index afb890b7957ec..281a8b1b688b0 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/input.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/input.test.ts @@ -43,7 +43,7 @@ describe('schedule target input', () => { Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', { Properties: { Target: { - Input: '"test"', + Input: 'test', }, }, }); @@ -52,13 +52,14 @@ describe('schedule target input', () => { test('create an input from text with a ref inside', () => { new Schedule(stack, 'MyScheduleDummy', { schedule: expr, - target: new SomeLambdaTarget(func, ScheduleTargetInput.fromText(stack.account)), + target: new SomeLambdaTarget(func, ScheduleTargetInput.fromText(`a-${stack.account}`)), }); + Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', { Properties: { Target: { Input: { - 'Fn::Join': ['', ['"', { Ref: 'AWS::AccountId' }, '"']], + 'Fn::Join': ['', ['a-', { Ref: 'AWS::AccountId' }]], }, }, }, @@ -115,7 +116,7 @@ describe('schedule target input', () => { Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', { Properties: { Target: { - Input: '"Test="', + Input: 'Test=', }, }, });