

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# EMR Studio의 노트북 CLI 명령 샘플
<a name="emr-managed-notebooks-headless-cli"></a>

이 주제에서는 EMR Notebook에 대한 CLI 명령 샘플을 보여줍니다. 이 예제에서는 EMR Notebooks 콘솔의 데모 노트북을 사용합니다. 노트북을 찾으려면 홈 디렉터리에 상대적인 파일 경로를 사용합니다. 이 예제에서는 두 개의 노트북 파일(`demo_pyspark.ipynb` 및 `my_folder/python3.ipynb`)을 실행할 수 있습니다.

**참고**  
EMR Notebooks는 콘솔에서 EMR Studio Workspace로 사용 가능합니다. 콘솔의 **워크스페이스 생성** 버튼을 사용하면 새 노트북을 생성할 수 있습니다. EMR Notebooks 사용자는 Workspace에 액세스하거나 Workspace를 생성하려면 추가 IAM 역할 권한이 필요합니다. 자세한 내용은 [Amazon EMR Notebooks가 콘솔에서 Amazon EMR Studio 워크스페이스 역할](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-managed-notebooks-migration.html) 및 [Amazon EMR 콘솔](https://docs.aws.amazon.com/emr/latest/ManagementGuide/whats-new-in-console.html)을 참조하세요.

`demo_pyspark.ipynb` 파일의 상대 경로는 아래와 같이 `demo_pyspark.ipynb`입니다.

![코드 셀이 있는 demo_pyspark.ipynb 파일과 필요한 라이브러리 설치 제목을 보여주는 Jupyter 노트북 인터페이스입니다.](http://docs.aws.amazon.com/ko_kr/emr/latest/ManagementGuide/images/notebook_exe_folder_structure_1.png)


`python3.ipynb`의 상대 경로는 아래와 같이 `my_folder/python3.ipynb`입니다.

![my_folder 디렉터리에 있는 python3.ipynb 파일을 보여주는 파일 브라우저입니다.](http://docs.aws.amazon.com/ko_kr/emr/latest/ManagementGuide/images/notebook_exe_folder_structure_2.png)


Amazon EMR API `NotebookExecution` 작업에 대한 자세한 내용은 [Amazon EMR API 작업](https://docs.aws.amazon.com/emr/latest/APIReference/API_Operations.html)을 참조하세요.

## 노트북 실행
<a name="emr-managed-notebooks-api-actions"></a>

다음 예제에서 볼 수 있듯이 AWS CLI 를 사용하여 `start-notebook-execution` 작업과 함께 노트북을 실행할 수 있습니다.

**Example - Amazon EMR(Amazon EC2에서 실행) 클러스터를 사용하는 EMR Studio Workspace에서 EMR 노트북 실행**  

```
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 - EMR Notebooks 클러스터를 사용하여 EMR Studio Workspace에서 EMR 노트북 실행**  

```
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 - Amazon S3 위치를 지정하는 EMR 노트북 실행**  

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

## 노트북 출력
<a name="emr-managed-notebooks-headless-cli-output"></a>

 다음은 샘플 노트북의 출력입니다. 셀 3에는 새로 삽입된 파라미터 값이 표시됩니다.

![셀 3에서 재정의된 값이 있는 파라미터 주입을 보여주는 Jupyter 노트북 셀.](http://docs.aws.amazon.com/ko_kr/emr/latest/ManagementGuide/images/HelloWorld_notebook.png)


## 노트북 설명
<a name="emr-managed-notebooks-headless-cli-describe"></a>

`describe-notebook-execution` 작업을 사용하여 특정 노트북 실행에 대한 정보에 액세스할 수 있습니다.

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

## 노트북 중지
<a name="emr-managed-notebooks-headless-cli-stop"></a>

노트북에서 중지하려는 실행이 실행 중인 경우 `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": []
    }
}
```

## 시작 시간을 기준으로 노트북의 실행 나열
<a name="emr-managed-notebooks-headless-cli-list"></a>

`--from` 파라미터를 `list-notebook-executions`로 전달하여 시작 시간별로 노트북의 실행을 나열할 수 있습니다.

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

## 시작 시간 및 상태를 기준으로 노트북의 실행 나열
<a name="emr-managed-notebooks-headless-cli-list"></a>

`list-notebook-executions` 명령은 `--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
        }
    ]
}
```