本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
AW-每個地方-邏輯點

所有類都在積極開發中,並且在任何未來版本中都會受到非向後兼容的更改或刪除。這些不受語義版本
請注意: 為了確保功能正確,專案中的 AWS 解決方案建構套件和 AWS CDK 套件必須是相同的版本。
語言 | 套件 |
---|---|
![]() |
aws_solutions_constructs.aws_apigateway_sagemakerendpoint
|
![]() |
@aws-solutions-constructs/aws-apigateway-sagemakerendpoint
|
![]() |
software.amazon.awsconstructs.services.apigatewaysagemakerendpoint
|
Overview
這個 AWS 解決方案建構實作了一個連接到亞馬遜 SagMaker 終端節點的 Amazon API Gateway REST API。
下面是 TypeScript 中的最小可部署模式定義:
import { ApiGatewayToSageMakerEndpoint, ApiGatewayToSageMakerEndpointProps } from '@aws-solutions-constructs/aws-apigateway-sagemakerendpoint'; // Below is an example VTL (Velocity Template Language) mapping template for mapping the Api GET request to the Sagemaker POST request const requestTemplate = `{ "instances": [ #set( $user_id = $input.params("user_id") ) #set( $items = $input.params("items") ) #foreach( $item in $items.split(",") ) {"in0": [$user_id], "in1": [$item]}#if( $foreach.hasNext ),#end $esc.newline #end ] }`; // Replace 'my-endpoint' with your Sagemaker Inference Endpoint new ApiGatewayToSageMakerEndpoint(this, 'test-apigw-sagemakerendpoint', { endpointName: 'my-endpoint', resourcePath: '{user_id}', requestMappingTemplate: requestTemplate });
Initializer
new ApiGatewayToSageMakerEndpoint(scope: Construct, id: string, props: ApiGatewayToSageMakerEndpointProps);
參數
-
scope
Construct
-
id
string
模式建立道具
名稱 | 類型 | 描述 |
---|---|---|
阿比格特威道具? |
api.RestApiProps
|
選用的使用者提供的道具,可覆寫 API Gateway REST API 的預設道具。 |
應用程式執行角色? |
iam.Role
|
API Gateway 使用的 IAM 角色叫用 SageMaker 端點。如果未指定,則會建立預設角色,並存取endpointName 。 |
Endpoint Name |
string
|
已部署的 SageMaker 推論端點的名稱。 |
ResourcenName? |
string
|
可選的資源名稱,其中 GET 方法將可用。 |
resourcePath |
string
|
GET 方法的資源路徑。這裡定義的變量可以在requestMappingTemplate 。 |
請求對映範本 |
string
|
對應範本,將 REST API 上接收的 GET 要求轉換為 SageMaker 端點所預期的 POST 要求。 |
ResponseMappingTemplate? |
string
|
選用的對應範本,可轉換從 SageMaker 端點接收到的回應。 |
記錄群組道具? |
logs.LogGroupProps
|
可選的使用者提供的道具,用於覆寫 CloudWatch Logs 日誌群組的預設道具。 |
模式性質
名稱 | 類型 | 描述 |
---|---|---|
ApeGateway |
api.LambdaRestApi
|
返回由模式創建的 API Gateway REST API 的實例。 |
應用方式角色 |
iam.Role
|
傳回由 API Gateway REST API 模式所建立的 IAM 角色執行個體。 |
雲端觀察角色 |
iam.Role
|
傳回模式所建立的 IAM 角色執行個體,該模式可啟用從 API Gateway REST API 存取記錄至 CloudWatch。 |
應用路徑記錄群組 |
logs.LogGroup
|
傳回傳送 API Gateway REST API 存取記錄檔的模式所建立之記錄群組的執行個體。 |
範例 API 使用
請注意: 每個 SageMaker 端點都是唯一的,API 的回應將取決於部署的模型。下面給出的例子假定從樣本這篇博客文章
方法 | 請求路徑 | 查詢字串 | SageMaker 動作 | 描述 |
---|---|---|---|---|
GET |
/321
|
items=101,131,162
|
sagemaker:InvokeEndpoint
|
擷取特定使用者和項目的預測。 |
預設設定
此模式的開箱即用實現沒有任何覆蓋將設置以下默認值:
Amazon API Gateway
-
部署邊緣最佳化的 API 端點
-
啟用適用於 API Gateway 的 CloudWatch 日誌
-
設定 API Gateway 的最低權限存取 IAM 角色
-
將所有 API 方法的預設授權類型設定為 IAM
-
啟用 X-Ray 追蹤
-
在將數據傳遞給 SageMaker 之前驗證請求參數
Architecture

GitHub
要查看此模式的代碼,創建/查看問題和提取請求,以及更多: | |
---|---|
![]() |
@aws-解決方案-構造/AW-應用-邏輯點 |