如何在没有 lambda 的情况下访问/调用 sagemaker 端点?

发布于 2025-01-10 06:15:29 字数 262 浏览 0 评论 0原文

根据 aws 文档,api 网关中的最大超时限制小于 30 秒。因此,如果请求/响应需要超过 30 秒,则将 sagemaker 端点与 api 网关连接起来就没有意义。有什么解决方法吗?在 api 网关和 sagemaker 端点之间添加 lambda 将增加更多时间来处理请求/响应,这是我想避免的。此外,还会增加 lambda 冷启动时间,并且 sagemaker 无服务器端点构建在 lambda 之上,因此也会增加冷启动时间。有没有一种方法可以调用无服务器 sagemaker 端点,而无需这些开销?

based on the aws documentation, maximum timeout limit is less that 30 seconds in api gateway.so hooking up an sagemaker endpoint with api gateway wouldn't make sense, if the request/response is going to take more than 30 seconds. is there any workaround ? adding a lambda in between api gateway and sagemaker endpoint is going to add more time to process request/response, which i would like to avoid. also, there will be added time for lambda cold starts and sagemaker serverless endpoints are built on top of lambda so that will also add cold start time. is there a way to invoke the serverless sagemaker endpoints , without these overhead?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧人九事 2025-01-17 06:15:29

确实可以在不使用任何其他 AWS 服务的情况下从 sagemaker 调用 sagemaker 端点,并且它们具有调用 URL 这一事实也证明了这一点。

设置方法如下:

  1. 创建一个仅具有编程访问权限的用户并附加一个策略 json,该策略应如下所示:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "sagemaker:InvokeEndpoint",
            "Resource": "arn:aws:sagemaker:<region>:<account-id>:endpoint/<endpoint-name>"
        }
    ]
} 

您可以将 替换为 * 让该用户调用所有端点。

  1. 使用 ACCESS-KEY 和 SECRET-ACCESS-KEY 在邮递员中配置授权,如此屏幕截图所示。还可以在高级选项卡中添加参数,如屏幕截图所示。
    输入图片此处描述

  2. 然后用相关的内容类型填写您的正文。

  3. 然后添加或删除其他标头,例如变体名称或型号名称(如果您已设置它们)并且标头应如下屏幕截图所示:在此处输入图像描述

  4. 发送请求以接收回复,例如这
    输入图片此处描述

上面屏幕截图中的 URL 和凭据不再起作用,废话!

如果您希望代码使用某些返回值直接调用端点-结束语言,这里是 python 代码

It is indeed possible to invoke sagemaker endpoints from sagemaker without using any other AWS services and that is also manifested by the fact that they have invocation URLs.

Here's how you set it up:

  1. create an user with only programmatic access and attach a policy json that should look something like below:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "sagemaker:InvokeEndpoint",
            "Resource": "arn:aws:sagemaker:<region>:<account-id>:endpoint/<endpoint-name>"
        }
    ]
} 

you can replace <endpoint-name> with * to let this user invoke all endpoints.

  1. use the ACCESS-KEY and SECRET-ACCESS-KEY to configure authorisation in postman like shown in this screenshot. also add the parameters in advanced tab like shown in the screenshot.
    enter image description here

  2. then fill up your body with the relevant content type.

  3. then add or remove additional headers like variant-name or model-name, if you have them set up and the headers should look like shown in this screenshot: enter image description here

  4. send the request to receive reponse like this
    enter image description here

URL and credentials in the above screenshots doesn't work anymore, duh!

and if you want code to invoke the endpoint directly using some back-end language, here's code for python.

执手闯天涯 2025-01-17 06:15:29

您可以使用映射模板将 SageMaker 端点直接连接到 API Gateway,无需中间 Lambda,https://aws.amazon.com/fr/blogs/machine-learning/creating-a-machine-learning-powered-rest-api-with-amazon-api-gateway-mapping-templates-and-amazon -sagemaker/

您还可以使用AWS SDK调用终端节点(例如CLIboto3),不一定需要为 API GW 执行此操作。

You can connect SageMaker endpoints to API Gateway directly, without intermediary Lambdas, using mapping templates https://aws.amazon.com/fr/blogs/machine-learning/creating-a-machine-learning-powered-rest-api-with-amazon-api-gateway-mapping-templates-and-amazon-sagemaker/

You can also invoke endpoints with AWS SDKs (eg CLI, boto3), no need to do it for API GW necessarily.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文