【发布时间】: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