From a20c841970ab8ea7af41e424f6cf813c899c9f37 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Sun, 30 Jun 2019 14:18:54 +0200 Subject: [PATCH] fix(events): correct token resolution in RuleTargetInput (#3127) 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 +}