Skip to content

Commit

Permalink
fix(events-targets): api destination target ignores pathParameterValu…
Browse files Browse the repository at this point in the history
…es and queryStringParameters (#21111)

fixes #21101


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
soucema9 committed Jul 14, 2022
1 parent e123087 commit 8446c5c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-events-targets/lib/api-destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export class ApiDestination implements events.IRuleTarget {
*/
public bind(_rule: events.IRule, _id?: string): events.RuleTargetConfig {
const httpParameters: events.CfnRule.HttpParametersProperty | undefined =
!!this.props.headerParameters ??
!!this.props.pathParameterValues ??
!!this.props.queryStringParameters
this.props.headerParameters ??
this.props.pathParameterValues ??
this.props.queryStringParameters
? {
headerParameters: this.props.headerParameters,
pathParameterValues: this.props.pathParameterValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,64 @@ describe('with basic auth connection', () => {
],
});
});

test('with header parameter', () => {
// WHEN
rule.addTarget(new targets.ApiDestination(destination, {
headerParameters: { headerName: 'headerValue' },
}));

// THEN
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::Events::Rule', {
Targets: [
{
Arn: { 'Fn::GetAtt': ['DestinationApiDestinationA879FAE5', 'Arn'] },
Id: 'Target0',
RoleArn: { 'Fn::GetAtt': ['DestinationEventsRole7DA63556', 'Arn'] },
HttpParameters: { HeaderParameters: { headerName: 'headerValue' } },
},
],
});
});

test('with query parameter', () => {
// WHEN
rule.addTarget(new targets.ApiDestination(destination, {
queryStringParameters: { queryName: 'queryValue' },
}));

// THEN
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::Events::Rule', {
Targets: [
{
Arn: { 'Fn::GetAtt': ['DestinationApiDestinationA879FAE5', 'Arn'] },
Id: 'Target0',
RoleArn: { 'Fn::GetAtt': ['DestinationEventsRole7DA63556', 'Arn'] },
HttpParameters: { QueryStringParameters: { queryName: 'queryValue' } },
},
],
});
});

test('with path parameter', () => {
// WHEN
rule.addTarget(new targets.ApiDestination(destination, {
pathParameterValues: ['pathValue'],
}));

// THEN
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::Events::Rule', {
Targets: [
{
Arn: { 'Fn::GetAtt': ['DestinationApiDestinationA879FAE5', 'Arn'] },
Id: 'Target0',
RoleArn: { 'Fn::GetAtt': ['DestinationEventsRole7DA63556', 'Arn'] },
HttpParameters: { PathParameterValues: ['pathValue'] },
},
],
});
});
});

0 comments on commit 8446c5c

Please sign in to comment.