【トラブル】【AWS】Amazon EMR に関するトラブル

■ はじめに

EMRで起こったトラブルを纏める。

目次

【1】エラー「GlueJobRunnerSession is not authorized to perform」が表示
【2】エラー「Terminated with errors Bootstrap failure」が表示
【3】エラー「IOException: (in directory "."): error=2, No such file or directory」が表示
【4】エラー「FAIL : hive download directory」が表示

別のEMRのトラブルは、以下の関連記事を参照のこと。

EMR / DBアクセス に関するトラブルシューティング
https://dk521123.hatenablog.com/entry/2021/06/17/114611
Amazon EMR の クローン 時の トラブル
https://dk521123.hatenablog.com/entry/2021/08/19/113707
EMR起動時にエラー「An EC2 ClientInternalError has occurred」が表示
https://dk521123.hatenablog.com/entry/2022/04/14/141250
EMRのStep実行時にエラー「Insufficient Lake Formation permission(s) on default」が表示
https://dk521123.hatenablog.com/entry/2022/05/09/101121
Amazon EMR ~ Log4j / CVE-2021-44228 対策 ~
https://dk521123.hatenablog.com/entry/2022/04/18/153148
EMRでINSERTを実行した際に Fail する
https://dk521123.hatenablog.com/entry/2022/05/14/001031
EMRで Auto Scaling が FAILED する
https://dk521123.hatenablog.com/entry/2022/05/18/092046

【1】エラー「GlueJobRunnerSession is not authorized to perform」が表示

Glue 経由で、EMRを起動しようとした際に、以下のエラーが表示された。

1)エラー内容

ClientError: An error occurred (AccessDeninedException)
 when calling the RunJobFlow operation:
User arn:aws:xxx:xxxxxxxx:assumed-role/<GlueRole>/GlueJobRunnerSession
 is not authorized to perform:
elasticmapreduce:RunJobFlow on resource:
arn:aws:elasticmapreduce:<AWS region>:xxxxxxxx:xxxxx/*

2)原因

IAM Policyで制限をかけていた。
⇒ 以下のサイトで扱っているような使用しているロールでアクセス制限していた。
 (「Role サンプル」の場合、タグ「Owner」が「admin」を設定していなかった)

https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/access_tags.html
https://docs.aws.amazon.com/ja_jp/emr/latest/ManagementGuide/security_iam_emr-with-iam.html

IAM Policy については、以下の関連記事を参照のこと。

https://dk521123.hatenablog.com/entry/2020/09/30/133123

Role サンプル

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticmapreduce:RunJobFlow"
            ],
            "Resource": "arn:aws:ec2:elasticmapreduce:*/*",
            "Condition": {
                "StringEquals": {"elasticmapreduce:ResourceTag/Owner": "admin"}
            }
        }
    ]
}

3)解決案

起動時のタグに指定した値を設定する

【2】エラー「Terminated with errors Bootstrap failure」が表示

AWS EMRを起動した際に、以下の「エラー内容」が表示。

1)エラー内容

Terminated with errors Bootstrap failure

エラー内容詳細 (詳細画面・サブタイトル より)

Terminated with errors On the master instance (i-xxxx), application provisioning

2)原因

# このエラーメッセージが表示されるのは、おそらく、色々な原因があり、
# その数だけ対処方法は変わると思うが、今回は、、、

* 使用しているシェルスクリプトの改行コードがCRLFだった
 => 元々は、Git の 改行コード自動変換 core.autocrlf で、
  CRLFに変換されてしまっていた。
  詳細は以下の関連記事を参照のこと。

Git ~ 改行コード自動変換 core.autocrlf ~
https://dk521123.hatenablog.com/entry/2021/08/17/171756

3)解決案

* シェルスクリプトの改行コードを、Linux用のLFコードに変更。

4)補足:トラブルシュート方法(ログの追い方)

https://aws.amazon.com/jp/premiumsupport/knowledge-center/emr-cluster-bootstrap-failed/

より抜粋

ブートストラップアクションが失敗した原因を特定するには、
ブートストラップアクションの stderr ログを確認します。
このログは、次のような Amazon Simple Storage Service (Amazon S3) のパスにあります。
~~~~
s3://<log-bucket>/<cluster-id>/node/<instance-id>/bootstrap-actions/
~~~~

【3】エラー「IOException: (in directory "."): error=2, No such file or directory」が表示

EMR の Step 実行中に以下の「エラー内容」が表示された

1)エラー内容

java.io.IOException: Cannot run program "/mnt1/yarn/usercache/hadoop/steps/s-xxxx/./sample.sh": (in directory "."): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
・・・略・・・

2)原因

『【2】エラー「Terminated with errors Bootstrap failure」が表示』と同じ

* 使用しているシェルスクリプトの改行コードがCRLFだった

3)解決案

『【2】エラー「Terminated with errors Bootstrap failure」が表示』と同じ

* シェルスクリプトの改行コードを、Linux用のLFコードに変更。

【4】エラー「FAIL : hive download directory」が表示

* AWS EMRを起動した際に、以下の「エラー内容」が表示。
* 「The specified bucket does not exist」とのことなので
 指定したS3バケットのスペルミスの可能性があるので
 確認したが、問題なし

1)エラー内容

stdout

Downloading 's3://xxxx/xxxx.sh'  to '/mnt/var/lib/hadoop/steps/s-xxxx/.'
2020-xxxx START xxxx.sh
2020-xxxx FAIL :  hive download directory
2020-xxxx END xxxx.sh

stderr

fatal error: An error occurred (NoSuchBucket)
 when calling the ListObjectsV2 operation:
 The specified bucket does not exist
download directory fail.
Command exiting with ret '1'

関連記事

EMR / DBアクセス に関するトラブルシューティング
https://dk521123.hatenablog.com/entry/2021/06/17/114611
EMR起動時にエラー「An EC2 ClientInternalError has occurred」が表示
https://dk521123.hatenablog.com/entry/2022/04/14/141250
EMRのStep実行時にエラー「Insufficient Lake Formation permission(s) on default」が表示
https://dk521123.hatenablog.com/entry/2022/05/09/101121
Hive に関するトラブルシューティング
https://dk521123.hatenablog.com/entry/2020/11/20/174039
Hive / Partition に関するトラブルシューティング
https://dk521123.hatenablog.com/entry/2020/05/28/175428
エラー「SemanticException Cartesian products are disabled for safety reasons」が発生する
https://dk521123.hatenablog.com/entry/2021/06/12/093046
テーブルアクセス時に例外「Vertex failed, ... InvalidInputException」が発生する
https://dk521123.hatenablog.com/entry/2021/07/06/120134
EMRでINSERTを実行した際に Fail する
https://dk521123.hatenablog.com/entry/2022/05/14/001031
Amazon EMR の クローン 時の トラブル
https://dk521123.hatenablog.com/entry/2021/08/19/113707
Amazon EMR ~ Log4j / CVE-2021-44228 対策 ~
https://dk521123.hatenablog.com/entry/2022/04/18/153148
EMRで Auto Scaling が FAILED する
https://dk521123.hatenablog.com/entry/2022/05/18/092046
Amazon EMR ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2020/02/20/230519
Amazon EMR ~ 基本編 ~
https://dk521123.hatenablog.com/entry/2020/05/27/175610
Amazon EMR ~ boto3 編 ~
https://dk521123.hatenablog.com/entry/2020/06/24/173334
Hive / HiveQL ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2019/11/25/235219
Hive / HiveQL ~ あれこれ編 ~
https://dk521123.hatenablog.com/entry/2020/03/04/225943
Amazon EMR ~ boto3 編 ~
https://dk521123.hatenablog.com/entry/2020/06/24/173334
IAM ~ IAM Policy 編 ~
https://dk521123.hatenablog.com/entry/2020/09/30/133123
EMRのBootstrapでエラー「BOOTSTRAP_FAILURE_BA_DOWNLOAD_FAILED_PRIMARY」が表示
https://dk521123.hatenablog.com/entry/2023/08/17/002559
Git ~ 改行コード自動変換 core.autocrlf ~
https://dk521123.hatenablog.com/entry/2021/08/17/171756