From 7520309f5e6386ae59947bc083c3bd2d841925fd Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Fri, 28 Jun 2019 16:40:46 +0200 Subject: [PATCH] fix(events): correct token resolution in RuleTargetInput Fixes #3119 --- packages/@aws-cdk/aws-events/lib/input.ts | 2 +- .../@aws-cdk/aws-events/test/test.input.ts | 39 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-events/lib/input.ts b/packages/@aws-cdk/aws-events/lib/input.ts index d0f30065e476b..821912f313849 100644 --- a/packages/@aws-cdk/aws-events/lib/input.ts +++ b/packages/@aws-cdk/aws-events/lib/input.ts @@ -148,7 +148,7 @@ class FieldAwareEventInput extends RuleTargetInput { } public resolveToken(t: Token, _context: IResolveContext) { - if (!isEventField(t)) { return t; } + if (!isEventField(t)) { return Token.asString(t); } const key = keyForField(t); if (inputPathsMap[key] && inputPathsMap[key] !== t.path) { diff --git a/packages/@aws-cdk/aws-events/test/test.input.ts b/packages/@aws-cdk/aws-events/test/test.input.ts index 4e7bb315bc2c9..cb7d8c64c218d 100644 --- a/packages/@aws-cdk/aws-events/test/test.input.ts +++ b/packages/@aws-cdk/aws-events/test/test.input.ts @@ -1,4 +1,5 @@ import { expect, haveResourceLike } from '@aws-cdk/assert'; +import { User } from '@aws-cdk/aws-iam'; import cdk = require('@aws-cdk/core'); import { Duration, Stack } from '@aws-cdk/core'; import { Test } from 'nodeunit'; @@ -27,6 +28,42 @@ export = { })); test.done(); }, + + 'can use token'(test: Test) { + // GIVEN + const stack = new Stack(); + const rule = new Rule(stack, 'Rule', { + schedule: Schedule.rate(Duration.minutes(1)), + }); + const user = new User(stack, 'User'); + + // WHEN + rule.addTarget(new SomeTarget(RuleTargetInput.fromObject({ userArn: user.userArn }))); + + // THEN + expect(stack).to(haveResourceLike('AWS::Events::Rule', { + Targets: [ + { + Input: { + 'Fn::Join': [ + '', + [ + '{\"userArn\":\"', + { + 'Fn::GetAtt': [ + 'User00B015A1', + 'Arn' + ] + }, + '\"}' + ] + ] + } + } + ] + })); + test.done(); + }, }, 'text templates': { @@ -107,4 +144,4 @@ class SomeTarget implements IRuleTarget { public bind() { return { id: 'T1', arn: 'ARN1', input: this.input }; } -} \ No newline at end of file +}