【トラブル】【AWS】boto3 AWS Glue API のトラブル ~ job/crawler編 ~

■ はじめに

https://dk521123.hatenablog.com/entry/2020/01/16/205331

の続き。
boto3 AWS Glue API のトラブル の長くなったので、分冊。

目次

【1】create_Job()で例外「AccessDeniedException」が発生する
【2】create_crawler() / update_crawler() で例外「InvalidInputException」が発生する

* trigger に関するAPIのトラブルについては、以下の関連記事を参照

boto3 AWS Glue API のトラブル ~ trigger全般 編 ~
https://dk521123.hatenablog.com/entry/2020/10/23/110821
boto3 AWS Glue API のトラブル ~ scheduled trigger編 ~
https://dk521123.hatenablog.com/entry/2020/01/16/205331

【1】create_Job()で例外「AccessDeniedException」が発生する

create_Job() を行った際に、以下のエラー内容の例外が発生して
ジョブが作成できなかった

エラー内容

An error occurred (AccessDeniedException) when calling the CreateJob operation: User : arn:aws... GlueJobSession is not authorized to perform: iam:PassRole on resource: arn:aws:iam ... AWSGlue

原因

https://docs.aws.amazon.com/ja_jp/glue/latest/dg/glue-troubleshooting-errors.html#error-assume-role-user-policy

より抜粋
~~~~
ジョブを定義するユーザーは
 AWS Glue の iam:PassRole のアクセス権限を
持っている必要がある
~~~~

解決案

 IAMロールに「iam:PassRole」を付与し、
Resourceは「Resource:*」か
「Resource : arn:aws:iam::*:role/AWSGlueServiceRole*」を指定する

参考文献

https://github.com/awsdocs/aws-glue-developer-guide/blob/master/doc_source/attach-policy-iam-user.md

【2】create_crawler() / update_crawler() で例外「InvalidInputException」が発生する

EC2内で、create_crawler() / update_crawler() を実行したところ、
以下の「エラー内容」の例外が発生した

エラー内容

An error occurred (InvalidInputException)
when calling the CreateCrawler operation :
Service is unable to assume role arn:aws:iam::xxxxxxxxx(IAM role ARN).
Please verify role's TrustPolicy

原因

対象のIAMロール(今回の場合は、EC2に付与されているIAMロール)において、
AWS Glueの信頼関係(Trust Relationship)が付与されていなかったため。

対応案

[1] AWS マネジメントコンソール にサインインし、
     IAM コンソールを開く
[2] IAM コンソールの [Navigation] ペインで [Roles] を選択
[3] アカウントのロールの一覧で、変更するロールの名前を選択
[4] [信頼関係] タブを選択してから、[信頼関係の編集] を選択
[5]  以下の「修正例」を参考に信頼ポリシーを編集する
[6]  [信頼ポリシーの更新] を選択して変更を保存

修正例

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": [
           "xxxxxxxxxxxxxxxxxxxx",
           "glue.amazonaws.com" <= これを追加
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
https://docs.aws.amazon.com/ja_jp/directoryservice/latest/admin-guide/edit_trust.html  

参考文献

https://github.com/terraform-providers/terraform-provider-aws/issues/3875

関連記事

boto3 AWS Glue API のトラブル ~ job編 ~
https://dk521123.hatenablog.com/entry/2020/01/16/205331
AWS Glue ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/10/01/221926
AWS Glue ~ Boto3 / 入門編 ~
https://dk521123.hatenablog.com/entry/2019/10/14/000000
AWS Glue ~ Boto3 / 基本編 ~
https://dk521123.hatenablog.com/entry/2021/04/17/001930
AWS Glue ~ Boto3 / クローラ編 ~
https://dk521123.hatenablog.com/entry/2021/04/16/135558
boto3 AWS Glue API のトラブル ~ trigger全般 編 ~
https://dk521123.hatenablog.com/entry/2020/10/23/110821
boto3 AWS Glue API のトラブル ~ scheduled trigger編 ~
https://dk521123.hatenablog.com/entry/2020/01/16/205331
AWS Glue のトラブル ~ job編 - [1] ~
https://dk521123.hatenablog.com/entry/2019/10/25/232155
AWS Glue のトラブル ~ job編 - [2] ~
https://dk521123.hatenablog.com/entry/2020/10/12/152659
AWS Glue のトラブル ~ job編 - [3] ~
https://dk521123.hatenablog.com/entry/2021/02/16/145848
AWS Glue のトラブル ~ crawler編 ~
https://dk521123.hatenablog.com/entry/2020/05/07/144132