Skip to content

sagemaker-runtime InvokeEndpoint double-encodes the body #1010

Open
@pbrisbin

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions