

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Contoh perintah CLI Notebook di EMR Studio
<a name="emr-managed-notebooks-headless-cli"></a>

Topik ini menunjukkan contoh perintah CLI untuk notebook EMR. Contoh menggunakan notebook demo dari konsol EMR Notebooks. Untuk menemukan buku catatan, gunakan jalur file relatif ke direktori home. Dalam contoh ini, ada dua file notebook yang dapat Anda jalankan: `demo_pyspark.ipynb` dan`my_folder/python3.ipynb`. 

**catatan**  
EMR Notebooks tersedia sebagai EMR Studio Workspaces di konsol. Tombol **Create Workspace** di konsol memungkinkan Anda membuat notebook baru. Untuk mengakses atau membuat Ruang Kerja, pengguna EMR Notebooks memerlukan izin peran IAM tambahan. [Untuk informasi selengkapnya, lihat [Amazon EMR Notebook adalah Amazon EMR Studio Workspaces di konsol dan konsol Amazon EMR](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-managed-notebooks-migration.html).](https://docs.aws.amazon.com/emr/latest/ManagementGuide/whats-new-in-console.html)

Jalur relatif untuk file `demo_pyspark.ipynb` adalah`demo_pyspark.ipynb`, ditunjukkan di bawah ini.

![Antarmuka notebook Jupyter menampilkan file demo_pyspark.ipynb dengan sel kode dan Instal judul perpustakaan yang diperlukan.](http://docs.aws.amazon.com/id_id/emr/latest/ManagementGuide/images/notebook_exe_folder_structure_1.png)


Jalur relatif untuk `python3.ipynb` adalah`my_folder/python3.ipynb`, ditunjukkan di bawah ini.

![Browser file menampilkan file python3.ipynb yang terletak di direktori my_folder.](http://docs.aws.amazon.com/id_id/emr/latest/ManagementGuide/images/notebook_exe_folder_structure_2.png)


Untuk informasi tentang tindakan Amazon EMR API, lihat `NotebookExecution` tindakan Amazon [EMR](https://docs.aws.amazon.com/emr/latest/APIReference/API_Operations.html) API. .

## Jalankan buku catatan
<a name="emr-managed-notebooks-api-actions"></a>

Anda dapat menggunakan AWS CLI untuk menjalankan notebook Anda dengan `start-notebook-execution` tindakan, seperti contoh berikut menunjukkan. 

**Example - Menjalankan notebook EMR di EMR Studio Workspace dengan klaster Amazon EMR (berjalan di Amazon EC2)**  

```
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}}"
}
```

**Example - Menjalankan notebook EMR di Ruang Kerja EMR Studio dengan cluster EMR 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}}
```

**Example - Menjalankan notebook EMR yang menentukan lokasi Amazon S3-nya**  

```
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": "{{amzn-s3-demo-bucket}}","Key": "{{s3-prefix-to-notebook-location}}/EMRonEKS-spark_python.ipynb"}' \
    --output-notebook-s3-location '{"Bucket": "{{amzn-s3-demo-bucket}}","Key": "{{s3-prefix-for-storing-output-notebook}}"}'
```

## Keluaran notebook
<a name="emr-managed-notebooks-headless-cli-output"></a>

 Berikut adalah output dari notebook sampel. Sel 3 menunjukkan nilai parameter yang baru disuntikkan.

![Sel notebook Jupyter menunjukkan injeksi parameter dengan nilai yang diganti di sel 3.](http://docs.aws.amazon.com/id_id/emr/latest/ManagementGuide/images/HelloWorld_notebook.png)


## Jelaskan buku catatan
<a name="emr-managed-notebooks-headless-cli-describe"></a>

Anda dapat menggunakan `describe-notebook-execution` tindakan untuk mengakses informasi tentang eksekusi notebook tertentu.

```
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": []
    }
}
```

## Hentikan buku catatan
<a name="emr-managed-notebooks-headless-cli-stop"></a>

Jika notebook Anda menjalankan eksekusi yang ingin Anda hentikan, Anda dapat melakukannya dengan `stop-notebook-execution` perintah.

```
# 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": []
    }
}
```

## Buat daftar eksekusi untuk buku catatan berdasarkan waktu mulai
<a name="emr-managed-notebooks-headless-cli-list"></a>

Anda dapat meneruskan `--from` parameter `list-notebook-executions` ke daftar eksekusi notebook Anda berdasarkan waktu mulai.

```
# 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
        }
    ]
}
```

## Buat daftar eksekusi untuk buku catatan berdasarkan waktu mulai dan status
<a name="emr-managed-notebooks-headless-cli-list"></a>

`list-notebook-executions`Perintah juga dapat mengambil `--status` parameter untuk memfilter hasil.

```
# 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
        }
    ]
}
```