Error 500 received in AWS Lambda test when get starting Sagemaker jupyter notebook

0

Hi Guys, I'm trying to automate Jupyther Notebook using lambda function with API Gateway and Websocket. I used this tutorial https://www.youtube.com/watch?v=wSdVAa7b5Octo configure my services (lambda, API Gateway, and Sagemaker/Jupyter notebook). I make a little bit of modifications because the recent Python version, in the tutorial, works with Python 3.6 and I used 3.8. Note: In Python 3.8 the method request was changed

import requests

I Attached PICs from the Error 500 printout, sagemaker and notbook configuration!

My complete Python code:

import boto3
import time
import requests
from websocket_client import websocket
def lambda_handler(event, context):
    sm_client = boto3.client('sagemaker')
    notebook_instance_name = 'nbCareboxstatistics'
    url = sm_client.create_presigned_notebook_instance_url(NotebookInstanceName=notebook_instance_name)['AuthorizedUrl']
    url_tokens = url.split('/')
    http_proto = url_tokens[0]
    http_hn = url_tokens[2].split('?')[0].split('#')[0]
    s = requests.Session()
    r = s.get(url)
    cookies = "; ".join(key + "=" + value for key, value in s.cookies.items())
    print(cookies)
    ws = websocket.create_connection(
        "wss://{}/terminals/websocket/1".format(http_hn),
        cookie=cookies,
        host=http_hn,
        origin=http_proto + "//" + http_hn
    )
    print(ws)
    ws.send("""[ "stdin", "jupyter nbconvert --execute --to notebook --inplace /home/ec2-user/SageMaker/nbCareboxstatisticsv1.ipynb --ExecutePreprocessor.kernel_name=python3 --ExecutePreprocessor.timeout=1500\\r" ]""")
    
    time.sleep(1)
    ws.close()
    print("websocket client created")
    return None

I did all those configurations as a tutorial and received the error below:

Error 500 Sagemaker configurations Notebook instance active on Sagemaker

Anybody can help how to solve it?

BR Alex,

1 Answer
0

Have you verified if the URL was passed as a valid parameter?

AWS
vtjean
answered a year 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