Package: aws-solutions-constructs.aws-apigateway-sagemakerendpoint
aws-apigateway-sagemakerendpoint module---All classes are under active development and subject to non-backward compatible changes or removal in any
future version. These are not subject to theSemantic Versioningmodel.
This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.Reference Documentation:https://docs.aws.amazon.com/solutions/latest/constructs/LanguagePackagePythonaws_solutions_constructs.aws_apigateway_sagemakerendpointTypescript@aws-solutions-constructs/aws-apigateway-sagemakerendpointJavasoftware.amazon.awsconstructs.services.apigatewaysagemakerendpointOverviewThis AWS Solutions Construct implements an Amazon API Gateway connected to an Amazon SageMaker endpoint pattern.Here is a minimal deployable pattern definition:Typescriptimport{Construct}from'constructs';import{Stack,StackProps}from'aws-cdk-lib';import{ApiGatewayToSageMakerEndpoint,ApiGatewayToSageMakerEndpointProps}from'@aws-solutions-constructs/aws-apigateway-sagemakerendpoint';//BelowisanexampleVTL(VelocityTemplateLanguage)mappingtemplateformappingtheApiGETrequesttotheSagemakerPOSTrequestconstrequestTemplate=`{"instances":[# set( $user_id = $input.params("user_id") )# set( $items = $input.params("items") )# foreach( $item in $items.split(",") )# if( $foreach.hasNext ),#end{"in0":[$user_id],"in1":[$item]}$esc.newline# end]}`//Replace'my-endpoint'withyourSagemakerInferenceEndpointnewApiGatewayToSageMakerEndpoint(this,'test-apigw-sagemakerendpoint',{endpointName:'my-endpoint',resourcePath:'{user_id}',requestMappingTemplate:requestTemplate});Pythonfromaws_solutions_constructs.aws_apigateway_sagemakerendpointimportApiGatewayToSageMakerEndpointfromaws_cdkimportStackfromconstructsimportConstruct# Below is an example VTL (Velocity Template Language) mapping template for mapping the Api GET request to the Sagemaker POST requestrequest_template="""{"instances": [# set( $user_id = $input.params("user_id") )# set( $items = $input.params("items") )# foreach( $item in $items.split(",") )# if( $foreach.hasNext ),#end{"in0": [$user_id], "in1": [$item]}$esc.newline# end]}"""# Replace 'my-endpoint' with your Sagemaker Inference EndpointApiGatewayToSageMakerEndpoint(self,'test-apigw-sagemakerendpoint',endpoint_name='my-endpoint',resource_path='{user_id}',request_mapping_template=request_template)Javaimportsoftware.constructs.Construct;importsoftware.amazon.awscdk.Stack;importsoftware.amazon.awscdk.StackProps;importsoftware.amazon.awsconstructs.services.apigatewaysagemakerendpoint.*;// Create an example VTL (Velocity Template Language) mapping template for mapping the Api GET request to the Sagemaker POST requestfinalStringrequestTemplate="{"+"\"instances\": ["+"# set( $user_id = $input.params(\"user_id\") )"+"# set( $items = $input.params(\"items\") )"+"# foreach( $item in $items.split(\",\") )"+"# if( $foreach.hasNext ),#end"+"{\"in0\": [$user_id], \"in1\": [$item]}"+"    $esc.newline"+"# end"+"]"+"}";// Replace ""my-endpoint"" with your Sagemaker Inference EndpointnewApiGatewayToSageMakerEndpoint(this,"ApiGatewayToSageMakerEndpointPattern",newApiGatewayToSageMakerEndpointProps.Builder().endpointName("my-endpoint").resourcePath("{user_id}").requestMappingTemplate(requestTemplate).build());Pattern Construct PropsNameTypeDescriptionapiGatewayProps?api.RestApiPropsOptional user-provided props to override the default props for the API Gateway.apiGatewayExecutionRole?iam.RoleIAM Role used by API Gateway to invoke the SageMaker endpoint. If not specified, a default role is created with access toendpointName.endpointNamestringName of the deployed SageMaker inference endpoint.resourceName?stringOptional resource name where the GET method will be available.resourcePathstringResource path for the GET method. The variable defined here can be referenced inrequestMappingTemplate.requestMappingTemplatestringMapping template to convert GET requests for the defaultapplication/jsoncontent-type received on the REST API to POST requests expected by the SageMaker endpoint.additionalRequestTemplates{ [contentType: string]: string; }Optional Request Templates for content-types other thanapplication/json. Use therequestMappingTemplateproperty to set the request template for theapplication/jsoncontent-type.responseMappingTemplate?stringOptional mapping template to convert responses received from the SageMaker endpoint.logGroupProps?logs.LogGroupPropsUser provided props to override the default props for for the CloudWatchLogs LogGroup.Pattern PropertiesNameTypeDescriptionapiGatewayapi.RestApiReturns an instance of the API Gateway REST API created by the pattern.apiGatewayRoleiam.RoleReturns an instance of the iam.Role created by the construct for API Gateway.apiGatewayCloudWatchRole?iam.RoleReturns an instance of the iam.Role created by the construct for API Gateway for CloudWatch access.apiGatewayLogGrouplogs.LogGroupReturns an instance of the LogGroup created by the construct for API Gateway access logging to CloudWatch.Sample API UsageNote: Each SageMaker endpoint is unique, and the response from the API will depend on the deployed model. The example given below assumes the sample fromthis blog post. For a reference on how that'd be implemented, please refer tointeg.apigateway-sagemakerendpoint-overwrite.ts.MethodRequest PathQuery StringSageMaker ActionDescriptionGET/321items=101,131,162sagemaker:InvokeEndpointRetrieves the predictions for a specific user and items.Default settingsOut of the box implementation of the Construct without any override will set the following defaults:Amazon API GatewayDeploy an edge-optimized API endpointEnable CloudWatch logging for API GatewayConfigure least privilege access IAM role for API GatewaySet the default authorizationType for all API methods to IAMEnable X-Ray TracingValidate request parameters before passing data to SageMakerArchitecture© Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.