Lambda function implementation

0

I want to use lambda function to parse the response returned by Sagemaker endpoint. My function should get a text as an input and parse it, then return. In function body there will be invoked get_result(), which uses .vocab file as an argument. I have uploaded .vocab file and get_result.py to my lambda function directory. I don't know what to do with dependencies that get_result() uses. Here is how the lambda function looks like

import os import io import boto3 import json import csv

ENDPOINT_NAME = os.environ['ENDPOINT_NAME'] runtime= boto3.client('runtime.sagemaker')

def lambda_handler(event, context): sagemaker_runtime = boto3.client('sagemaker-runtime', region_name='us-east-1') print("Received event: " + json.dumps(event, indent=2))

data = json.loads(json.dumps(event))
payload = data['data']
print(payload)

with open("tmp_splitted/voice_6539544344_Hamaspyur_3093_34.wav", "rb") as file:
    audio_data = file.read()

response = sagemaker_runtime.invoke_endpoint(
    EndpointName=endpoint_name,
    ContentType="audio/x-audio",  # Change this to the appropriate audio format
    Accept="application/json",
    Body=audio_data
)
print(response)
result = json.loads(response['Body'].read().decode())
print(result)
best_correction = get_best_correction(result)

return best_correction

When I press test button I see this result, can someone help me to understand why do I see the result of last test?

Zhenya
asked 23 days ago133 views
1 Answer
0
Accepted Answer

As per the screenshot provided, you are making code changes but not deploying it. Hence when you hit test button, it uses the deployed code, not the code change you made currently.

You can deploy the changes by clicking on "Deploy" button which is present next to "Test" button.

answered 23 days ago
profile pictureAWS
EXPERT
reviewed 23 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions