Skip to content
New issue

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

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

Already on GitHub? # to your account

sagemaker-runtime InvokeEndpoint double-encodes the body #1010

Open
pbrisbin opened this issue Nov 19, 2024 · 1 comment
Open

sagemaker-runtime InvokeEndpoint double-encodes the body #1010

pbrisbin opened this issue Nov 19, 2024 · 1 comment

Comments

@pbrisbin
Copy link
Contributor

We're using the InvokeEndpoint function with JSON as the body. We believe it arrives at the server double-encoded. I say "we believe" because it's really hard to log what we're seeing and be confident we aren't introducing our own escaping 😅 .

Anyway, I think this is because of the use of postJSON and toJSON body (where body :: Text and contains already-encoded JSON in our case):

instance Core.AWSRequest InvokeEndpoint where
  request overrides =
    Request.postJSON (overrides defaultService)

instance Data.ToJSON InvokeEndpoint where
  toJSON InvokeEndpoint' {..} = Data.toJSON body

From the docs, the entire body is meant to be included as itself and is assumed to be in the given Content-Type.

And, as far as I can tell (I find searching for this stuff difficult), the CLI/python libraries do this:

        r = self.http.request("POST", url, body=Body, preload_content=False, headers=headers)

source

So I think the body field should probably be ByteString and sent to the server directly, not via postJSON.

@pbrisbin
Copy link
Contributor Author

From those same docs, it looks like the response can be any content-type as well. So we shouldn't be using receiveJSON here either, I'd think.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant