Skip to content

Commit

Permalink
fix(events): correct token resolution in RuleTargetInput
Browse files Browse the repository at this point in the history
Fixes aws#3119
  • Loading branch information
jogold committed Jun 28, 2019
1 parent edc70b4 commit 325a79f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-events/lib/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
39 changes: 38 additions & 1 deletion packages/@aws-cdk/aws-events/test/test.input.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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': {
Expand Down Expand Up @@ -107,4 +144,4 @@ class SomeTarget implements IRuleTarget {
public bind() {
return { id: 'T1', arn: 'ARN1', input: this.input };
}
}
}

0 comments on commit 325a79f

Please sign in to comment.