Part #2: Create Your Model Endpoint With Amazon SageMaker, AWS Lambda, and AWS API Gateway
Originally Published Feb 02, 2024
In this series, we look at how to use Amazon SageMaker and MongoDB Atlas Vector Search to semantically search your data.
Read more on Developer Center
Author: Dominic Frei
1 Like
I am getting this error : curl -X GET ‘https://lpeg644c9b.execute-api.us-east-1.amazonaws.com/proddidi/sageMakerResource?query=foo’
{“error”: “An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (422) from primary with message "Failed to deserialize the JSON body into the target type: missing field inputs at line 1 column 22". See https://eu-central-1.console.aws.amazon.com/cloudwatch/home?region=eu-central-1#logEventViewer:group=/aws/sagemaker/Endpoints/jumpstart-dft-hf-textembedding-all-20250417-123155 in account 102570980430 for more information.”}% (base) didibitini@Didis-Air atlas_starter_python-master %
1 Like
Hello, it working with the below code :
import json
import boto3
sagemaker_runtime_client = boto3.client(“sagemaker-runtime”)
def lambda_handler(event, context):
try:
# Extract the query parameter ‘query’ from the event
query_param = event.get(‘queryStringParameters’, {}).get(‘query’, ‘’)
if query_param:
embedding = get_embedding(query_param)
return {
'statusCode': 200,
'body': json.dumps({'embedding': embedding})
}
else:
return {
'statusCode': 400,
'body': json.dumps({'error': 'No query parameter provided didi'})
}
except Exception as e:
return {
'statusCode': 500,
'body': json.dumps({'error': str(e)})
}
def get_embedding(synopsis):
input_data = {“inputs”: synopsis}
response = sagemaker_runtime_client.invoke_endpoint(
EndpointName=“jumpstart-dft-hf-textembedding-all-20250417-123155”,
Body=json.dumps(input_data),
ContentType=“application/json”
)
result = json.loads(response[“Body”].read().decode())
embedding = result[0]
return embedding
1 Like