

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 Amazon EMR 進行增強型步驟偵錯
<a name="emr-enhanced-step-debugging"></a>

如果 Amazon EMR 步驟失敗，並且您搭配使用 Step API 操作與 AMI 5.x 或更新版本提交了工作，則 Amazon EMR 可以在某些情況中找到並傳回步驟失敗的根本原因，相關日誌檔案的名稱，以及透過 API 進行的應用程式堆疊追蹤的一部分。例如，您可以識別以下失敗：
+ 常見 Hadoop 錯誤 (例如輸出目錄已存在，輸入目錄不存在，或應用程式將記憶體用盡)。
+ Java 錯誤 (例如使用不相容的 Java 版本來編譯應用程式，或應用程式透過找不到的主要類別來執行)。
+ 存取在 Amazon S3 中儲存的物件時出現問題。

您可以使用 [DescribeStep](https://docs.aws.amazon.com/ElasticMapReduce/latest/API/API_DescribeStep.html) 和 [ListSteps](https://docs.aws.amazon.com/ElasticMapReduce/latest/API/API_ListSteps.html) API 操作來獲得此資訊。這些操作傳回的 [StepSummary](https://docs.aws.amazon.com/ElasticMapReduce/latest/API/API_StepSummary.html) 的 [FailureDetails](https://docs.aws.amazon.com/ElasticMapReduce/latest/API/API_FailureDetails.html) 欄位。若要存取 FailureDetails 資訊，請使用 AWS CLI、主控台或 AWS SDK。

------
#### [ Console ]

新的 Amazon EMR 主控台不提供步驟偵錯。不過，可以使用下列步驟來檢視叢集終止詳細資訊。

**使用主控台檢視失敗詳細資訊**

1. 登入 AWS 管理主控台，並在 https：//[https://console.aws.amazon.com/emr](https://console.aws.amazon.com/emr) 開啟 Amazon EMR 主控台。

1. 在左側導覽窗格中的 **EMR on EC2** 下，選擇**叢集**，然後選取您要檢視的叢集。

1. 請記下叢集詳細資訊頁面之**摘要**區段中的**狀態**值。如果狀態為**因錯誤而終止**，請將游標暫留在文字上以檢視叢集失敗詳細資訊。

------
#### [ CLI ]

**使用 檢視失敗詳細資訊 AWS CLI**
+ 若要使用 取得步驟的失敗詳細資訊 AWS CLI，請使用 `describe-step`命令。

  ```
  aws emr describe-step --cluster-id j-1K48XXXXXHCB --step-id s-3QM0XXXXXM1W
  ```

  輸出格式應類似以下內容：

  ```
  {
    "Step": {
      "Status": {
        "FailureDetails": {
          "LogFile": "s3://amzn-s3-demo-bucket/logs/j-1K48XXXXXHCB/steps/s-3QM0XXXXXM1W/stderr.gz",
          "Message": "org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory s3://amzn-s3-demo-bucket/logs/beta already exists",
          "Reason": "Output directory already exists."
        },
        "Timeline": {
          "EndDateTime": 1469034209.143,
          "CreationDateTime": 1469033847.105,
          "StartDateTime": 1469034202.881
        },
        "State": "FAILED",
        "StateChangeReason": {}
      },
      "Config": {
        "Args": [
          "wordcount",
          "s3://amzn-s3-demo-bucket/input/input.txt",
          "s3://amzn-s3-demo-bucket/logs/beta"
        ],
        "Jar": "s3://amzn-s3-demo-bucket/jars/hadoop-mapreduce-examples-2.7.2-amzn-1.jar",
        "Properties": {}
      },
      "Id": "s-3QM0XXXXXM1W",
      "ActionOnFailure": "CONTINUE",
      "Name": "ExampleJob"
    }
  }
  ```

------