Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-events-targets): ApiDestination target ignores path_parameter_values and query_string_parameters #21101

Closed
soucema9 opened this issue Jul 12, 2022 · 1 comment · Fixed by #21111
Assignees
Labels
@aws-cdk/aws-events-targets bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@soucema9
Copy link
Contributor

Describe the bug

ApiDestination target construct ignores path_parameter_values and query_string_parameters if no header_parameters are provided.

Expected Behavior

If only path_parameter_values is provided it is rendered to CF template

aws_events_targets.ApiDestination(
    api_destination=my_api_destination,
    path_parameter_values=["$.detail.pathParameter"],
)
{
    "Id": "Target0",
    "Arn": ...,
    "RoleArn": ...,
    "HttpParameters": {
        "PathParameterValues": [ "$.detail.pathParameter" ]
    }
}

If only query_string_parameters is provided it is rendered to CF template

aws_events_targets.ApiDestination(
    api_destination=my_api_destination,
    query_string_parameters={"queryParameterName": "$.detail.queryParameterValue"},
)
{
    "Id": "Target0",
    "Arn": ...,
    "RoleArn": ...,
    "HttpParameters": {
        "QueryStringParameters": {
            "queryParameterName": "$.detail.queryParameterValue"
       }
    }
}

Current Behavior

Currently both path_parameter_values and query_string_parameters parameters are ignored and HttpParameters object is not added to CF template.

aws_events_targets.ApiDestination(
    api_destination=my_api_destination,
    path_parameter_values=["$.detail.pathParameter"],
    query_string_parameters={"queryParameterName": "$.detail.queryParameterValue"},
)
{
    "Id": "Target0",
    "Arn": ...,
    "RoleArn": ...,
    // missing HttpParameters
}

But if header_parameters is added everything seems to work. HttpParameters object is added to CF template and it even correctly represents path_parameter_values and query_string_parameters parameters.

aws_events_targets.ApiDestination(
    api_destination=my_api_destination,
    path_parameter_values=["$.detail.pathParameter"],
    query_string_parameters={"queryParameterName": "$.detail.queryParameterValue"},
    header_parameters={"cdk-workaround": "$.detail.headerValue"},
)
{
    "Id": "Target0",
    "Arn": ...,
    "RoleArn": ...,
    "HttpParameters": {
        "HeaderParameters": {
           "cdk-workaround": "$.detail.headerValue"
        },
        "PathParameterValues": [
            "$.detail.pathParameter"
        ],
        "QueryStringParameters": {
            "queryParameterName": "$.detail.queryParameterValue"
        }
    }
}

Reproduction Steps

from aws_cdk import aws_events, aws_events_targets, core

app = core.App()
stack = core.Stack(app, 'stack-name')

my_api_destination = aws_events.ApiDestination(
    stack, 'MyApiDestination',
    connection=aws_events.Connection(
        stack, 'MyConnection',
        authorization=aws_events.Authorization.api_key(
            api_key_name='Authorization', 
            api_key_value=core.SecretValue.unsafe_plain_text('xxx'))
    ),
    endpoint='https://example.com/*',
    http_method=aws_events.HttpMethod.POST,
)

rule = aws_events.Rule(
    stack, 'EventBridgeRule',
    event_pattern=aws_events.EventPattern(account=['123456789012']),
    targets=[
        aws_events_targets.ApiDestination(
            api_destination=my_api_destination,
            path_parameter_values=["$.detail.pathParameter"],
            query_string_parameters={"queryParameterName": "$.detail.queryParameterValue"},
            # header_parameters={"cdk-workaround": "$.detail.headerValue"},
        )
    ],
)

app.synth()

Possible Solution

I'm not a TypeScript developer. But it seems that problem is combination of !! and ?? operators in this condition.

public bind(_rule: events.IRule, _id?: string): events.RuleTargetConfig {
const httpParameters: events.CfnRule.HttpParametersProperty | undefined =
!!this.props.headerParameters ??
!!this.props.pathParameterValues ??
!!this.props.queryStringParameters
? {
headerParameters: this.props.headerParameters,
pathParameterValues: this.props.pathParameterValues,
queryStringParameters: this.props.queryStringParameters,
} : undefined;

Additional Information/Context

No response

CDK CLI Version

2.31.1 (build 42432c6)

Framework Version

No response

Node.js Version

v16.3.0

OS

macOS 12.4

Language

Python

Language Version

Python 3.8

Other information

No response

@soucema9 soucema9 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 12, 2022
@mergify mergify bot closed this as completed in #21111 Jul 14, 2022
mergify bot pushed a commit that referenced this issue Jul 14, 2022
…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*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-events-targets bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
2 participants