繁体   English   中英

通过 Websocket 在 AWS SageMaker 中自动执行 a.ipynb 文件

[英]Automate the execution of a .ipynb file in AWS SageMaker by Websocket

我有一个问题。 11月10日之前,我的lambda代码使用websocket与sagemaker通信,可以自动执行a.ipynb文件。 代码如下

import boto3
import time
from botocore.vendored import requests
import websocket

def lambda_handler(event, context):
    sm_client = boto3.client('sagemaker')
    notebook_instance_name = 'test'
    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())

    ws = websocket.create_connection
      ("wss://{}/terminals/websocket/1".format(http_hn),  
      cookie=cookies, 
      host=http_hn, 
      origin=http_proto + "//" + http_hn,
      header=["User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"])


    ws.send("""[ "stdin", "jupyter nbconvert --execute --to notebook --inplace /home/ec2-user/SageMaker/Scikit.ipynb --ExecutePreprocessor.kernel_name=python3 --ExecutePreprocessor.timeout=1500\\r" ]""")
    time.sleep(1)
    ws.close()
    return None

但是11月18号的时候,发现websocket连接报错。 错误代码为 WebSocketBadStatusException: Handshake status 200 OK。 想不通几天了。 有人有建议/解决方案吗?

我调查这篇文章很多天了。 但我没有得到答案。

您可以考虑使用 SageMaker 处理作业自动化您的笔记本。 请在此处查看此博客文章: https://aws.amazon.com/blogs/machine-learning/scheduling-jupyter-notebooks-on-sagemaker-ephemeral-instances/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM