【トラブル】【AWS】boto3 AWS Glue API のトラブル ~ Connection編 ~

■ はじめに

https://dk521123.hatenablog.com/entry/2020/01/29/224525

で発生したトラブルについて、まとめる。

目次

【1】UpdateConnection を実行したら AccessDeniedExceptionが発生

【1】UpdateConnection を実行したら AccessDeniedExceptionが発生

 Glue connection を更新できるツールを
boto3 API 「UpdateConnection」を使って作成し、
それをAWS Lambda 上で実行したら、以下「1)エラー内容」が表示してしまった。

1)エラー内容

An error occured (AccessDeniedException)
 when calling the UpdateConnection operation:
 User: arn:aws:sts::xxxxxxxx:assumed-role/your-lambda-iam-role
 is not autorized to perform:
 glue:UpdateConnection on resource
 arn:aws:glue:ap-northeast-1:xxxxxx:connection:your-glue-connection-name"

2)原因

AWS Lambda に設定されていたロール(今回の場合「your-lambda-iam-role」)
に対して、UpdateConnection を実行する権限が指定されていたのだが、
更新対象のConnection名(今回の場合「your-glue-connection-name」)が
Resourceに追加されていなかったため。
 => 以下の「iam role の指定を一部抜粋 (修正前)」を参照

iam role の指定を一部抜粋 (修正前)

{
  "Effect": "Allow",
  "Action": [
    "glue:UpdateConnection"
  ],
  "Resource": [
    "arn:aws:glue:ap-northeast-1:xxxxxx:connection:different-glue-connection-1",
    "arn:aws:glue:ap-northeast-1:xxxxxx:connection:different-glue-connection-2",
    # ★ここに対象のGlue Connection名がない★
    ...
  ]
}

3)対応案

* Resouceに対象のGlue Connectionを追加してあげる
 => 以下「★Add」部分を参照。

修正後

  "Resource": [
    "arn:aws:glue:ap-northeast-1:xxxxxx:connection:different-glue-connection-1",
    "arn:aws:glue:ap-northeast-1:xxxxxx:connection:different-glue-connection-2",
    "arn:aws:glue:ap-northeast-1:xxxxxx:connection:your-glue-connection-name", # ★Add
    ...
  ]

関連記事

AWS Glue ~ Boto3 / Glue connection編 ~
https://dk521123.hatenablog.com/entry/2020/01/29/224525
AWS Glue ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/10/01/221926