omuronの備忘録

個人的な備忘録

Glue DataCatalog のクロスアカウント連携

Glue DataCatalog にクロスアカウントで連携する際にハマったので備忘録。
結論から言うと、Glue の DataCatalog に専用の設定があり、アクセス権限を追加できます。
( S3 のポリシー設定みたいな感じですね)

アクセスさせたい Glue DataCatalog 側の設定

{
  "Version" : "2012-10-17",
  "Statement" : [ {
    "Effect" : "Allow",
    "Principal" : {
      "AWS" : "arn:aws:iam::12456789012:role/xxx"
    },
    "Action" : "glue:*",
    "Resource" : [
        "arn:aws:glue:ap-northeast-1:12456789012:catalog",
        "arn:aws:glue:ap-northeast-1:12456789012:database/*",
        "arn:aws:glue:ap-northeast-1:12456789012:table/*" ]
  } ]
}

アクセス元の Role 設定

CloudWatch Logs から Firehose Delivery Stream を使って、別アカウントの Glue Table 情報を参照しようとしてうまくいきませんでした。
参照先の Glue DataCatalog で上記設定をして、アクセス元のロールを参照先の Pricinpal に設定することでクロスアカウントアクセスができました。
アクセス元が Firehose の場合のロール作成例です。

  AWSGlueServiceRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: role-name
      Policies:
        - PolicyName: policy-name
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action:
                  - glue:GetTable
                  - glue:GetTableVersion
                  - glue:GetTableVersions
                Resource:
                  - !Sub arn:aws:glue:ap-northeast-1:12456789012:catalog
                  - !Sub arn:aws:glue:ap-northeast-1:12456789012:database/*
                  - !Sub arn:aws:glue:ap-northeast-1:12456789012:table/*
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: firehose.amazonaws.com

最後に

ドキュメント探しても全然わからなくていつものブログに助けられました。

dev.classmethod.jp

CloudFormation 対応もしてなさそうで、CFn ドキュメント読んでてもそれっぽい設定もないし、このブログを見つけれなかったら解決できなかったのでとても感謝です!