【问题标题】:How to run different Jupyter notebooks conditionally in a AWS Sagemaker notebook instance如何在 AWS Sagemaker 笔记本实例中有条件地运行不同的 Jupyter 笔记本
【发布时间】:2021-08-21 03:51:34
【问题描述】:

我有一个 AWS sagemaker 笔记本实例,它有 2 个不同的 jupyter 笔记本。每一个都应该在某些条件下起作用。

所以,如果条件 A 存在,Jupyter Notebook 1 应该运行,如果条件 B 存在,Jupyter Notebook 2 应该运行。

到目前为止,我已经尝试过这段代码,但它不起作用:

if condition A:

    sm_client = boto3.client('sagemaker')
    notebook_instance_name = NotebookInstanceName
    notebook_instance_name = 'Calorie-1615128222'
    url = sm_client.create_presigned_notebook_instance_url(NotebookInstanceName=notebook_instance_name)['AuthorizedUrl']
    
    print(url)

    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 = websockets.connect("wss://{}/terminals/websocket/1".format(http_hn))
    
    ws.send("""[ "stdin", "jupyter nbconvert --execute --to notebook --inplace /home/ec2-user/SageMaker/Calorie/Notebook1.ipynb 
--ExecutePreprocessor.kernel_name=conda_tensorflow2_p36 --ExecutePreprocessor.timeout=1500\\r" ]""")
    #ws.send("""[ "stdin", "jupyter nbconvert --execute Notebook1.ipynb --ExecutePreprocessor.kernel_name=conda_tensorflow2_p36 --ExecutePreprocessor.timeout=1500\\r" ]""")
    
    time.sleep(5)
    ws.close()
    print("websocket client created")
    #return None
    

请帮忙。非常感谢

【问题讨论】:

    标签: python amazon-web-services jupyter-notebook amazon-sagemaker aws-sam


    【解决方案1】:

    您是否考虑过根据您的用例使用AWS Step FunctionsSageMaker Pipelines 进行编排?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-12
      • 2020-05-17
      • 1970-01-01
      • 1970-01-01
      • 2021-05-09
      • 2018-09-23
      • 2021-07-12
      • 1970-01-01
      相关资源
      最近更新 更多