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

"Calling API gateway using Stepfunctions" feature is not properly supported by CDK, when using CallApiGatewayRestApiEndpoint #14184

Closed
Vinith1994 opened this issue Apr 15, 2021 · 5 comments · Fixed by #18595
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions @aws-cdk/aws-stepfunctions-tasks bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@Vinith1994
Copy link

We are trying to use the CallApiGatewayRestApiEndpoint construct with WAIT_FOR_TASK_TOKEN integration pattern. Per the AWS docs on the contract, we need to specify the headers like this:

"Headers": { "TaskToken.$": "States.Array($$.Task.Token)" }

However, we're not sure how to do that with the CallApiGatewayRestApiEndpoint construct. We tried something like this, which would generate the expected headers:

headers = aws_stepfunctions.TaskInput.from_object({
            "TaskToken.$":"States.Array($$.Task.Token)"
        })
step1 = aws_stepfunctions_tasks.CallApiGatewayRestApiEndpoint(
            self.wf.stack, "APIGW",
            api=rest_api,
            method=HttpMethod.POST,
            stage_name="prod",
            headers=headers,
            integration_pattern=aws_stepfunctions.IntegrationPattern.REQUEST_RESPONSE,
            auth_type=aws_stepfunctions_tasks.AuthType.IAM_ROLE
        )

but when we set IntegrationPattern to WAIT_FOR_TASK_TOKEN, CDK complains that task token is missing:

Task Token is required in headers for WAIT_FOR_TASK_TOKEN pattern. Use JsonPath.taskToken to set the token.

But if we make the value of the header field a string instead of list/array, then CDK wouldn't raise an error. however when we execute this state machine, step functions would complain that the format of header field is incorrect.

headers = aws_stepfunctions.TaskInput.from_object({
            "TaskToken.$":"$$.Task.Token"
        })
        step1 = aws_stepfunctions_tasks.CallApiGatewayRestApiEndpoint(
            self.wf.stack, "APIGW",
            api=rest_api,
            method=HttpMethod.POST,
            stage_name="prod",
            headers=headers,
            integration_pattern=aws_stepfunctions.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
            auth_type=aws_stepfunctions_tasks.AuthType.IAM_ROLE
        )

Reproduction Steps

Described above

What did you expect to happen?

CDK shouldn't complain when we pass Task Token using States.Array within headers and when we use WAIT_FOR_TASK_TOKEN pattern.

What actually happened?

Seems like for calling API gateway using stepfunctions, we need to pass task token within array inside the header. But CDK doesn't detect task token if we do this way. Also, note that CDK currently doesn't support intrinsic functions (Such as States.Array).

Environment

  • CDK CLI Version : 1.98.0
  • Framework Version: 1.98.0
  • Node.js Version: v14.6.0
  • OS : Linux
  • Language (Version): Python (3.7.3)

This is 🐛 Bug Report

@Vinith1994 Vinith1994 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 15, 2021
@github-actions github-actions bot added @aws-cdk/aws-apigateway Related to Amazon API Gateway @aws-cdk/aws-stepfunctions Related to AWS StepFunctions labels Apr 15, 2021
@Vinith1994 Vinith1994 changed the title Calling API gateway with Stepfunctions is not possible with current CDK Calling API gateway with Stepfunctions is not possible with current CDK, when we use CallApiGatewayRestApiEndpoint Apr 15, 2021
@Vinith1994 Vinith1994 changed the title Calling API gateway with Stepfunctions is not possible with current CDK, when we use CallApiGatewayRestApiEndpoint "Calling API gateway using Stepfunctions" feature is not properly supported by CDK, when using CallApiGatewayRestApiEndpoint Apr 15, 2021
@nija-at nija-at removed the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Apr 15, 2021
@nija-at nija-at removed their assignment Apr 15, 2021
@paraspra
Copy link

This bug is exactly similar to this issue.
However from what I have observed "Headers" field is not strictly required to build task to call ApiGateway. One can create task without header field as well.

@Vinith1994
Copy link
Author

@paraspra We need header field for the task token

@shivlaks shivlaks added p1 effort/medium Medium work item – several days of effort @aws-cdk/aws-stepfunctions-tasks and removed needs-triage This issue or PR still needs to be triaged. labels May 18, 2021
@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 21, 2022

You must use JsonPath.taskToken, putting $$.Task.Token in the middle of a string is apparently not correctly detected by our library.

The code probably needs to look like this:

headers = aws_stepfunctions.TaskInput.from_object({
            "TaskToken.$":"States.Array(" + aws_stepfunctions.JsonPath.task_token + ")"
        })

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 21, 2022

Nevermind, this does not work.

rix0rrr added a commit that referenced this issue Jan 21, 2022
…teway

To pass the Task Token in headers to an API Gateway, the token must
be wrapped in an array (because that's the value type of headers).

Because JSONPath evaluation needs to happen to resolve the token,
we need to use the `States.Array()` function in a `JsonPathToken`
to properly resolve this. However, doing that makes the existing
validation code fail the validation checking that you are passing
the task token somewhere.

Add convenience methods for the intrinsics, and update the checker
to also find paths referenced inside intrinsic functions.

Fixes #14184, fixes #14181.
@mergify mergify bot closed this as completed in #18595 Jan 25, 2022
mergify bot pushed a commit that referenced this issue Jan 25, 2022
…teway (#18595)

To pass the Task Token in headers to an API Gateway, the token must
be wrapped in an array (because that's the value type of headers).

Because JSONPath evaluation needs to happen to resolve the token,
we need to use the `States.Array()` function in a `JsonPathToken`
to properly resolve this. However, doing that makes the existing
validation code fail the validation checking that you are passing
the task token somewhere.

Add convenience methods for the intrinsics, and update the checker
to also find paths referenced inside intrinsic functions.

Fixes #14184, fixes #14181.


----

*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.

LukvonStrom pushed a commit to LukvonStrom/aws-cdk that referenced this issue Jan 26, 2022
…teway (aws#18595)

To pass the Task Token in headers to an API Gateway, the token must
be wrapped in an array (because that's the value type of headers).

Because JSONPath evaluation needs to happen to resolve the token,
we need to use the `States.Array()` function in a `JsonPathToken`
to properly resolve this. However, doing that makes the existing
validation code fail the validation checking that you are passing
the task token somewhere.

Add convenience methods for the intrinsics, and update the checker
to also find paths referenced inside intrinsic functions.

Fixes aws#14184, fixes aws#14181.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…teway (aws#18595)

To pass the Task Token in headers to an API Gateway, the token must
be wrapped in an array (because that's the value type of headers).

Because JSONPath evaluation needs to happen to resolve the token,
we need to use the `States.Array()` function in a `JsonPathToken`
to properly resolve this. However, doing that makes the existing
validation code fail the validation checking that you are passing
the task token somewhere.

Add convenience methods for the intrinsics, and update the checker
to also find paths referenced inside intrinsic functions.

Fixes aws#14184, fixes aws#14181.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions @aws-cdk/aws-stepfunctions-tasks bug This issue is a bug. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants