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

Sagemaker Runtime service "wrapping" content in a dictionary #588

Open
cirocavani opened this issue Oct 18, 2022 · 0 comments
Open

Sagemaker Runtime service "wrapping" content in a dictionary #588

cirocavani opened this issue Oct 18, 2022 · 0 comments

Comments

@cirocavani
Copy link

cirocavani commented Oct 18, 2022

Sagemaker Runtime service sends the body as a JSON Object with key "Body" and invocation body in value. This is different from boto3 where the content is sent as is (no extra JSON Object wrapping the payload).

Example:

using AWS: @service
@service Sagemaker_Runtime

body = Dict("feature1" => "value1")
response = Sagemaker_Runtime.invoke_endpoint(body, "sagemaker-endpoint")
# the content sent is `{"Body": {"feature1": "value1"}}` but the endpoint expects `{"feature1": "value1"}`

Workaround:

using AWS
using AWS.AWSServices: sagemaker_runtime

function invoke_endpoint(
    Body, EndpointName; aws_config::AbstractAWSConfig=global_aws_config()
)
    return sagemaker_runtime(
        "POST",
        "/endpoints/$(EndpointName)/invocations",
        Body;
        aws_config=aws_config,
    )
end

body = Dict("feature1" => "value1")
response = invoke_endpoint(payload, "sagemaker-endpoint")
# the endpoint receives `{"feature1": "value1"}`

Looking the code, there are two parts:

  1. invocation body been wrapped in a dictionary:

https://github.com/JuliaCloud/AWS.jl/blob/v1.78.0/src/services/sagemaker_runtime.jl#L72

https://github.com/JuliaCloud/AWS.jl/blob/v1.78.0/src/services/sagemaker_runtime.jl#L86

  1. then serialization as JSON string:

https://github.com/JuliaCloud/AWS.jl/blob/v1.78.0/src/AWS.jl#L426

Per AWS Documentation, body could be other formats than JSON not supported with sagemaker_runtime as a RestJSONService.

https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_runtime_InvokeEndpoint.html#API_runtime_InvokeEndpoint_RequestBody

https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-inference.html#ir-serialization

I can give a try to fix this issue. Let me know if there is an approach that make more sense.

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

No branches or pull requests

1 participant