Esempi di CLI comandi per Notebook - Amazon EMR

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Esempi di CLI comandi per Notebook

Questo argomento mostra esempi di CLI comandi per un EMR notebook. L'esempio utilizza il notebook demo della console EMR Notebooks. Per individuare il notebook, utilizza il percorso di file relativo alla home directory. In questo esempio, ci sono due file di notebook che puoi eseguire: demo_pyspark.ipynb e my_folder/python3.ipynb.

Nota

EMRI notebook sono disponibili come EMR spazi di lavoro Studio nella console. Il pulsante Crea area di lavoro nella console consente di creare nuovi notebook. Per accedere o creare aree di lavoro, gli utenti di EMR Notebooks necessitano di autorizzazioni di ruolo aggiuntive. IAM Per ulteriori informazioni, consulta Amazon EMR Notebooks are Amazon EMR Studio Workspace nella console e nella console Amazon. EMR

Il percorso relativo del file demo_pyspark.ipynb è demo_pyspark.ipynb, mostrato di seguito.

Jupyter notebook interface showing a file explorer and code editor with PySpark content.

Il percorso relativo per python3.ipynb è my_folder/python3.ipynb, mostrato di seguito.

File explorer showing python3.ipynb in my_folder, and Jupyter notebook interface with code.

Per informazioni sulle EMR API NotebookExecution azioni Amazon, consulta Amazon EMR API actions. .

Esecuzione di un notebook

Puoi utilizzare il plugin AWS CLI per far funzionare il notebook con l'start-notebook-executionazione, come dimostrano gli esempi seguenti.

Esempio — Esecuzione di un EMR notebook in uno EMR Studio Workspace con un cluster Amazon EMR (in esecuzione su AmazonEC2)
aws emr --region us-east-1 \ start-notebook-execution \ --editor-id e-ABCDEFG123456 \ --notebook-params '{"input_param":"my-value", "good_superhero":["superman", "batman"]}' \ --relative-path test.ipynb \ --notebook-execution-name my-execution \ --execution-engine '{"Id" : "j-1234ABCD123"}' \ --service-role EMR_Notebooks_DefaultRole { "NotebookExecutionId": "ex-ABCDEFGHIJ1234ABCD" }
Esempio — Esecuzione di un EMR notebook in uno EMR Studio Workspace con un EMR cluster Notebooks
aws emr start-notebook-execution \ --region us-east-1 \ --service-role EMR_Notebooks_DefaultRole \ --environment-variables '{"KERNEL_EXTRA_SPARK_OPTS": "--conf spark.executor.instances=1", "KERNEL_LAUNCH_TIMEOUT": "350"}' \ --output-notebook-format HTML \ --execution-engine Id=arn:aws:emr-containers:us-west-2:account-id:/virtualclusters/ABCDEFG/endpoints/ABCDEF,Type=EMR_ON_EKS,ExecutionRoleArn=arn:aws:iam::account-id:role/execution-role \ --editor-id e-ABCDEFG \ --relative-path EMRonEKS-spark_python.ipynb
Esempio — Esecuzione di un EMR notebook specificando la sua posizione in Amazon S3
aws emr start-notebook-execution \ --region us-east-1 \ --notebook-execution-name my-execution-on-emr-on-eks-cluster \ --service-role EMR_Notebooks_DefaultRole \ --environment-variables '{"KERNEL_EXTRA_SPARK_OPTS": "--conf spark.executor.instances=1", "KERNEL_LAUNCH_TIMEOUT": "350"}' \ --output-notebook-format HTML \ --execution-engine Id=arn:aws:emr-containers:us-west-2:account-id:/virtualclusters/ABCDEF/endpoints/ABCDEF,Type=EMR_ON_EKS,ExecutionRoleArn=arn:aws:iam::account-id:role/execution-role \ --notebook-s3-location '{"Bucket": "your-s3-bucket","Key": "s3-prefix-to-notebook-location/EMRonEKS-spark_python.ipynb"}' \ --output-notebook-s3-location '{"Bucket": "your-s3-bucket","Key": "s3-prefix-for-storing-output-notebook"}'

Output del notebook

Ecco l'output di un notebook campione. La cella 3 mostra i valori di parametro appena inseriti.

Jupyter notebook cells showing Python code and output for parameter injection and manipulation.

Descrizione di un notebook

Puoi utilizzare l'operazione describe-notebook-execution per accedere alle informazioni sull'esecuzione di un notebook specifico.

aws emr --region us-east-1 \ describe-notebook-execution --notebook-execution-id ex-IZWZZVR9DKQ9WQ7VZWXJZR29UGHTE { "NotebookExecution": { "NotebookExecutionId": "ex-IZWZZVR9DKQ9WQ7VZWXJZR29UGHTE", "EditorId": "e-BKTM2DIHXBEDRU44ANWRKIU8N", "ExecutionEngine": { "Id": "j-2QMOV6JAX1TS2", "Type": "EMR", "MasterInstanceSecurityGroupId": "sg-05ce12e58cd4f715e" }, "NotebookExecutionName": "my-execution", "NotebookParams": "{\"input_param\":\"my-value\", \"good_superhero\":[\"superman\", \"batman\"]}", "Status": "FINISHED", "StartTime": 1593490857.009, "Arn": "arn:aws:elasticmapreduce:us-east-1:123456789012:notebook-execution/ex-IZWZZVR9DKQ9WQ7VZWXJZR29UGHTE", "LastStateChangeReason": "Execution is finished for cluster j-2QMOV6JAX1TS2.", "NotebookInstanceSecurityGroupId": "sg-0683b0a39966d4a6a", "Tags": [] } }

Arrestare un notebook

Se il notebook sta eseguendo un'esecuzione che desideri arrestare, puoi farlo con il comando stop-notebook-execution.

# stop a running execution aws emr --region us-east-1 \ stop-notebook-execution --notebook-execution-id ex-IZWZX78UVPAATC8LHJR129B1RBN4T # describe it aws emr --region us-east-1 \ describe-notebook-execution --notebook-execution-id ex-IZWZX78UVPAATC8LHJR129B1RBN4T { "NotebookExecution": { "NotebookExecutionId": "ex-IZWZX78UVPAATC8LHJR129B1RBN4T", "EditorId": "e-BKTM2DIHXBEDRU44ANWRKIU8N", "ExecutionEngine": { "Id": "j-2QMOV6JAX1TS2", "Type": "EMR" }, "NotebookExecutionName": "my-execution", "NotebookParams": "{\"input_param\":\"my-value\", \"good_superhero\":[\"superman\", \"batman\"]}", "Status": "STOPPED", "StartTime": 1593490876.241, "Arn": "arn:aws:elasticmapreduce:us-east-1:123456789012:editor-execution/ex-IZWZX78UVPAATC8LHJR129B1RBN4T", "LastStateChangeReason": "Execution is stopped for cluster j-2QMOV6JAX1TS2. Internal error", "Tags": [] } }

Elencazione delle esecuzioni di un notebook per ora di inizio

Puoi trasmettere un parametro --from a list-notebook-executions per elencare le esecuzioni del notebook in base all'ora di inizio.

# filter by start time aws emr --region us-east-1 \ list-notebook-executions --from 1593400000.000 { "NotebookExecutions": [ { "NotebookExecutionId": "ex-IZWZX78UVPAATC8LHJR129B1RBN4T", "EditorId": "e-BKTM2DIHXBEDRU44ANWRKIU8N", "NotebookExecutionName": "my-execution", "Status": "STOPPED", "StartTime": 1593490876.241 }, { "NotebookExecutionId": "ex-IZWZZVR9DKQ9WQ7VZWXJZR29UGHTE", "EditorId": "e-BKTM2DIHXBEDRU44ANWRKIU8N", "NotebookExecutionName": "my-execution", "Status": "RUNNING", "StartTime": 1593490857.009 }, { "NotebookExecutionId": "ex-IZWZYRS0M14L5V95WZ9OQ399SKMNW", "EditorId": "e-BKTM2DIHXBEDRU44ANWRKIU8N", "NotebookExecutionName": "my-execution", "Status": "STOPPED", "StartTime": 1593490292.995 }, { "NotebookExecutionId": "ex-IZX009ZK83IVY5E33VH8MDMELVK8K", "EditorId": "e-BKTM2DIHXBEDRU44ANWRKIU8N", "NotebookExecutionName": "my-execution", "Status": "FINISHED", "StartTime": 1593489834.765 }, { "NotebookExecutionId": "ex-IZWZXOZF88JWDF9J09GJ91R57VI0N", "EditorId": "e-BKTM2DIHXBEDRU44ANWRKIU8N", "NotebookExecutionName": "my-execution", "Status": "FAILED", "StartTime": 1593488934.688 } ] }

Elencazione delle esecuzioni di un notebook per ora di inizio e stato

Il comando list-notebook-executions può anche filtrare i risultati in base a un parametro --status.

# filter by start time and status aws emr --region us-east-1 \ list-notebook-executions --from 1593400000.000 --status FINISHED { "NotebookExecutions": [ { "NotebookExecutionId": "ex-IZWZZVR9DKQ9WQ7VZWXJZR29UGHTE", "EditorId": "e-BKTM2DIHXBEDRU44ANWRKIU8N", "NotebookExecutionName": "my-execution", "Status": "FINISHED", "StartTime": 1593490857.009 }, { "NotebookExecutionId": "ex-IZX009ZK83IVY5E33VH8MDMELVK8K", "EditorId": "e-BKTM2DIHXBEDRU44ANWRKIU8N", "NotebookExecutionName": "my-execution", "Status": "FINISHED", "StartTime": 1593489834.765 } ] }