Abdullah Şamil Güser

Invoke Model Endpoint From External Clients

Integration Overview (Lesson 96)

1. Python SDKs (Direct Client Interaction with SageMaker Endpoint)

2. AWS Lambda (Microservice-Based Integration)

3. API Gateway and Lambda (Exposing Endpoints as RESTful APIs)

4. Data Transformations

Labs - Client to Endpoint

Using SageMaker SDK (Lesson 97)

Using Boto3 SDK (Lesson 98)

Lab - Microservice - Lambda to Endpoint

1. Format Payload (Lesson 99)

2. Lambda to Endpoint (Lesson 101)

Setting up IAM Role for Lambda

  1. Use your my_admin account.
  2. Select Roles and create a new role.
  3. Role Configuration:
    • Select AWS service as Lambda.
    • Assign SageMakerInvokeEndpoint policy for SageMaker endpoint invocation and AWSLambdaBasicExecutionRole for Lambda function logging.
    • Give name : lambda_sagemaker_invoke_endpoint

Creating a Lambda Function

  1. Under Services, select Lambda. Then Create Function.

  2. We can Author from Scratch:
    • Name: bikerental_prediction
    • Runtime: Python 3.6 or later.
    • Permissions: Use the role lambda_sagemaker_invoke_endpoint.
  3. Implementing the Function:
    • Use the code from invoke_using_boto3_lambda.py in the IntegrationExamples folder.
    • Define the entry point as lambda_handler.
    • Deploy changes.
  4. Environment Variable:
    • Set ENDPOINT_NAME to your SageMaker endpoint name.
  5. Save and Test the Function:
    • Create a test event using LambdaTestEvent.txt file.
    • First create an event for a single observation (Bike Single Observation)
    • Name the event as BikeSingleObservation
    • Click Test and check the results.

Monitoring and Logging

3. API Gateway, Lambda, Endpoint (Lesson 103)

Setting up API Gateway

  1. Login to AWS Management Console with my_admin account, navigate to API Gateway.
  2. Create a new REST API named BikeRentalPrediction.
  3. Select Create Method ans select POST method.
  4. Select Integration Type as Lambda Function.

Testing Integration

Deploying API Gateway

Invoking API from Various Clients

  1. Using Browser Extension (e.g., RESTer):
    • Method: POST
    • URL: API Gateway URL
    • Body: JSON payload
    • Content Type: application/json
    • Send request and receive predictions.
  2. Using Python Client