Skip to content

Step Functions cant invoke http endpoint that has a pipe character in path

0

I'm integrating with a third party public api that uses pipe characters in the user_id. For example I need to invoke a GET request to https://example.com/users/app|1234 where "app|1234" is the user id. I have a simple step function with a single task to execute a http:invoke task. When I setup the task with an ApiEndpoint value of https://example.com/users/app|1234, I get the following error when running it:

... "ApiEndpoint":"https://example.com/users/app|1234"}' could not be used to start the Task: [The value for the 'ApiEndpoint' field is not valid]

I tried escaping the pipe character like so: https://example.com/users/app%7C1234

With the pipe escaped the task will executes, but the request is sent as https://example.com/users/app%257C1234. The % character is escaped!

This seems like a bug to me. Has anyone else encountered this? Is there a known workaround?

Here is what my state machine looks like

{
  "QueryLanguage": "JSONPath",
  "Comment": "A description of my state machine",
  "StartAt": "Call HTTPS APIs",
  "States": {
    "Call HTTPS APIs": {
      "Type": "Task",
      "Resource": "arn:aws:states:::http:invoke",
      "Parameters": {
        "ApiEndpoint": "https://example.com/users/app|1234",
        "Method": "GET",
        "InvocationConfig": {
          "ConnectionArn": "..."
        }
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 1,
          "MaxAttempts": 3,
          "JitterStrategy": "FULL"
        }
      ],
      "End": true
    }
  }
}

asked 2 years ago341 views

2 Answers
1

The | character falls under the list of unwise characters in the RFC 2396 specification:

   Other characters are excluded because gateways and other transport
   agents are known to sometimes modify such characters, or they are
   used as delimiters.

   unwise      = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"

   Data corresponding to excluded characters must be escaped in order to
   be properly represented within a URI.

Step Functions encodes provided URLs before invoking the Task state HTTP call, which is why your % character is being encoded into %25. There is currently no way to use a HTTPS task with a pipe symbol.
I've reached out to the team to explore if that logic can be adjusted however.

AWS
EXPERT

answered 2 years ago

  • @ben-from-aws thanks for confirming. I'd be very interested to hear what response you get back from the step functions team.

  • Hi, it's been a while but the issue has been fixed by the team. Could you please try again

-3

The issue you're encountering with the pipe character in the URL is indeed a challenge when working with AWS Step Functions' HTTP Task. Step Functions appears to be applying URL encoding to certain special characters, which is causing the problem you're experiencing.

To work around this issue, you can try the following approach:

  1. Instead of putting the full URL in the ApiEndpoint parameter, split it into two parts:

    • Use the base URL (https://example.com) as the ApiEndpoint
    • Put the path with the special character (/users/app|1234) in a separate Path parameter
  2. Modify your state machine definition to use this approach. Here's how you can structure it:

{
  "QueryLanguage": "JSONPath",
  "Comment": "A description of my state machine",
  "StartAt": "Call HTTPS APIs",
  "States": {
    "Call HTTPS APIs": {
      "Type": "Task",
      "Resource": "arn:aws:states:::http:invoke",
      "Parameters": {
        "ApiEndpoint": "https://example.com",
        "Method": "GET",
        "Path": "/users/app|1234",
        "InvocationConfig": {
          "ConnectionArn": "..."
        }
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 1,
          "MaxAttempts": 3,
          "JitterStrategy": "FULL"
        }
      ],
      "End": true
    }
  }
}

By separating the base URL and the path, you can avoid the automatic URL encoding that Step Functions is applying to the full URL. This should allow the pipe character to be sent correctly in the request.

If you need to make the user ID dynamic, you can use a path reference to pass it as a parameter. For example:

"Path.The issue you're encountering with the pipe character in the URL is indeed a challenge when working with AWS Step Functions' HTTP Task. Step Functions appears to be applying URL encoding to certain special characters, which is causing the problem you're experiencing.

To work around this issue, you can try the following approach:

1. Instead of putting the full URL in the `ApiEndpoint` parameter, split it into two parts:
   - Use the base URL (https://example.com) as the `ApiEndpoint`
   - Put the path with the special character (/users/app|1234) in a separate `Path` parameter

2. Modify your state machine definition to use this approach. Here's how you can structure it:

```json
{
  "QueryLanguage": "JSONPath",
  "Comment": "A description of my state machine",
  "StartAt": "Call HTTPS APIs",
  "States": {
    "Call HTTPS APIs": {
      "Type": "Task",
      "Resource": "arn:aws:states:::http:invoke",
      "Parameters": {
        "ApiEndpoint": "https://example.com",
        "Method": "GET",
        "Path": "/users/app|1234",
        "InvocationConfig": {
          "ConnectionArn": "..."
        }
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 1,
          "MaxAttempts": 3,
          "JitterStrategy": "FULL"
        }
      ],
      "End": true
    }
  }
}

By separating the base URL and the path, you can avoid the automatic URL encoding that Step Functions is applying to the full URL. This should allow the pipe character to be sent correctly in the request.

If you need to make the user ID dynamic, you can use a path reference to pass it as a parameter. For example:

"Path.$": "$.userPath"

Then in your input to the state machine, you would provide the path including the pipe character:

{
  "userPath": "/users/app|1234"
}

This approach should allow you to successfully make requests to URLs containing pipe characters or other special characters that might otherwise be encoded unexpectedly.quot;: "$.userPath"


Then in your input to the state machine, you would provide the path including the pipe character:

```json
{
  "userPath": "/users/app|1234"
}

This approach should allow you to successfully make requests to URLs containing pipe characters or other special characters that might otherwise be encoded unexpectedly.
Sources
Call HTTPS APIs in Step Functions workflows - AWS Step Functions
Passing parameters to a service API in Step Functions - AWS Step Functions

answered 2 years ago

  • When I tried this I get the error: The field "Path" is not supported by Step Functions.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.