DEV Community

Developer213
Developer213

Posted on

Handle notebook



import streamlit as st
import boto3
import json

# AWS Lambda client
lambda_client = boto3.client("lambda", region_name="your-region")  # Replace with actual region

# Function to fetch active Jupyter notebooks (Mocked List, Replace with actual API call)
def get_active_notebooks():
    return ["notebook-1", "notebook-2", "notebook-3"]  # Replace with actual source

# Function to invoke Lambda
def trigger_lambda(notebook_name, action):
    payload = {"notebook_name": notebook_name, "action": action}
    response = lambda_client.invoke(
        FunctionName="your-lambda-function-name",  # Replace with actual Lambda function name
        InvocationType="RequestResponse",
        Payload=json.dumps(payload),
    )
    return json.loads(response["Payload"].read())

# Streamlit UI
st.title("Jupyter Notebook Manager")

# Dropdown for active notebooks
notebooks = get_active_notebooks()
selected_notebook = st.selectbox("Select Notebook:", notebooks)

# Action selection
action = st.radio("Action:", ["Start", "Stop"])

# Trigger button
if st.button(f"{action} Notebook"):
    result = trigger_lambda(selected_notebook, action.lower())
    st.success(f"Lambda Response: {result}")
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more