阅读 AWS SageMaker InvokeEndpoint 的“敏感”结果。

huangapple go评论91阅读模式
英文:

Reading the "sensitive" results of AWS SageMaker InvokeEndpoint

问题

我正在尝试使用Go SDK调用SageMaker无服务器端点,但结果没有返回,而是标记为“敏感”。根据文档中的说明,它说不会返回正文,但没有说明如何检索它。

当我使用aws-cli调用时,它会正确地将结果JSON填充到输出文件中。

svc := sagemakerruntime.New(sess)
out, err := svc.InvokeEndpoint(&sagemakerruntime.InvokeEndpointInput{
	Body:         []byte(`xxx`),
	ContentType:  aws.String("application/json"),
	EndpointName: aws.String("xxx"),
})

结果:

{
  Body: <sensitive>,
  ContentType: "application/json",
  InvokedProductionVariant: "single-variant"
}

当我使用aws-cli调用时,它会正确地将结果JSON填充到输出文件中。

aws sagemaker-runtime invoke-endpoint --content-type 'application/json' --endpoint-name xxx --body xxx /tmp/sagemaker-output
英文:

I'm trying to invoke a sagemaker serverless endpoint using the Go SDK and the result is not returned, it's marked as "sensitive". From the docs it says that the body will not be returned but it doesn't say how to retrieve it.

svc := sagemakerruntime.New(sess)
out, err := svc.InvokeEndpoint(&amp;sagemakerruntime.InvokeEndpointInput{
	Body:         []byte(`xxx`),
	ContentType:  aws.String(&quot;application/json&quot;),
	EndpointName: aws.String(&quot;xxx&quot;),
})

Result:

{
  Body: &lt;sensitive&gt;,
  ContentType: &quot;application/json&quot;,
  InvokedProductionVariant: &quot;single-variant&quot;
}

When I invoke it using the aws-cli, it populates the output file correctly with the result json.

aws sagemaker-runtime invoke-endpoint --content-type &#39;application/json&#39; --endpoint-name xxx --body xxx /tmp/sagemaker-output

答案1

得分: 0

根据文档所述,这只会影响StringGoString方法返回的字符串。你仍然可以直接访问Body字段。

package main

import (
	"fmt"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/sagemakerruntime"
)

func main() {
	output := &sagemakerruntime.InvokeEndpointOutput{
		Body:                     []byte("body data"),
		ContentType:              aws.String("application/json"),
		InvokedProductionVariant: aws.String("single-variant"),
	}

	fmt.Println(output)
	fmt.Printf("body: %s\n", output.Body)
}

输出:

{
  Body: <sensitive>,
  ContentType: "application/json",
  InvokedProductionVariant: "single-variant"
}
body: body data
英文:

> Body is a sensitive parameter and its value will be replaced with "sensitive" in string returned by InvokeEndpointOutput's String and GoString methods.

As stated in the document, it only affects the string returned by the String and GoString methods. You still can access the Body field directly.

package main

import (
	&quot;fmt&quot;

	&quot;github.com/aws/aws-sdk-go/aws&quot;
	&quot;github.com/aws/aws-sdk-go/service/sagemakerruntime&quot;
)

func main() {
	output := &amp;sagemakerruntime.InvokeEndpointOutput{
		Body:                     []byte(&quot;body data&quot;),
		ContentType:              aws.String(&quot;application/json&quot;),
		InvokedProductionVariant: aws.String(&quot;single-variant&quot;),
	}

	fmt.Println(output)
	fmt.Printf(&quot;body: %s\n&quot;, output.Body)
}

Output:

{
  Body: &lt;sensitive&gt;,
  ContentType: &quot;application/json&quot;,
  InvokedProductionVariant: &quot;single-variant&quot;
}
body: body data

huangapple
  • 本文由 发表于 2023年4月27日 13:50:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76117119.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定