Amazon QuickSight で TIP を使った Athena ワークグループのデータセットを作成したときに遭遇したエラーたちと解決方法

Amazon QuickSight で TIP を使った Athena ワークグループのデータセットを作成したときに遭遇したエラーたちと解決方法

Clock Icon2025.07.18

いわさです。

先日、Amazon QuickSight が TIP を使った Athena ワークグループをサポートしたので使ってみました。

https://dev.classmethod.jp/articles/quicksight-trusted-identity-propagation/

実はこの設定の過程でかなりのトライ&エラーがあったので、私が遭遇した主要なエラー内容と対策をまとめておきます。
構成箇所が分散されておりはまりどころが多いので、同じようなエラーメッセージに遭遇した方の参考になれば良いなと思ってます。

カスタマーロールを引き受けることができません

まず最初に遭遇したのが、データソース作成時の検証フェーズで発生する以下のエラーです。

13BAAAAC-EAA8-41A8-9C7C-5326A00A2B9A.png

デフォルトの「aws-quicksight-service-role-v0」を使っている時に発生したので、私は次のドキュメントに従ってカスタムロールを作成し、セキュリティとアクセス許可の機能から割り当てを行うことで解決しました。

https://docs.aws.amazon.com/quicksight/latest/user/athena-trusted-identity-propagation.html

Unable to connect to Athena workgroup hoge0713athena. Please ensure your QuickSight account IAM role has athena:GetWorkGroup permission and your user identity has access to the workgroup's IAM Identity Center application

Unable to connect to Athena workgroup hoge0713wg2. Please ensure your QuickSight account IAM role has athena:GetWorkGroup permission and your user identity has access to the workgroup's IAM Identity Center application

接続検証時にワークグループ自体に接続できない場合があります。

image.png

QuickSight の共通設定の中でどの TIP 構成を許可するか事前に設定が必要です。
デフォルトでは次のように何も設定されていません。

% aws quicksight list-identity-propagation-configs --aws-account-id 123456789012 --region ap-northeast-1 --profile hogeadmin
{
    "Status": 200,
    "Services": [
        {
            "Service": "ATHENA",
            "AuthorizedTargets": []
        }
    ],
    "RequestId": "f8d8b21a-7eb3-46a4-92e5-d80d9530f3f6"
}

ここはコンソールからは本日時点では登録できず、API 経由で登録必要があります。
私は AWS CLI を使って登録を行いました。登録対象は対象ワークグループの IAM Identity Center アプリケーションです。(以下)

B576D6F9-FF45-4843-BE0C-F453C0D74A77_1_105_c.jpeg

% cat hoge.json 
{
    "AwsAccountId": "123456789012",
    "Service": "ATHENA",
    "AuthorizedTargets": [
        "arn:aws:sso::123456789012:application/ssoins-7758571eb0e448d1/apl-3eb41c1e843401e4"
    ]
}
% aws quicksight update-identity-propagation-config --cli-input-json file://hoge.json --profile hogeadmin
{
    "Status": 200,
    "RequestId": "aea3d401-3016-40b3-ae43-fece9dd0e750"
}

Connection test failed: Could not get query execution ID: Misconfigured service role. Make sure that athena.amazonaws.com has been allowed for sts:AssumeRole and sts:SetContext.

ドキュメントではサービスロールは QuickSight を信頼する必要がある内容になっているのですが、私が試した際にはこれだけだと足りていなくて、掲題のエラーが発生していました。

https://docs.aws.amazon.com/quicksight/latest/user/athena-trusted-identity-propagation.html

以下がドキュメント記載の信頼ポリシーです。

{ 
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "QuickSightandAthenaTrust",
            "Effect": "Allow",
            "Principal": {
                "Service": "quicksight.amazonaws.com"
            },
            "Action": [
                "sts:AssumeRole",
                "sts:SetContext"
            ]
        }
    ]
}

次のようにathena.amazonaws.comも信頼先に追加してみたところエラーが解消できました。

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "QuickSightandAthenaTrust",
			"Effect": "Allow",
			"Principal": {
				"Service": [
					"quicksight.amazonaws.com",
					"athena.amazonaws.com"
				]
			},
			"Action": [
				"sts:AssumeRole",
				"sts:SetContext"
			]
		}
	]
}

You do not have access to the Athena Identity Center enabled workgroup. Please contact your account administrator to verify your workgroup permissions

このエラーは対象ワークグループの IAM Identity Center アプリケーションに QuickSight サインイン中のユーザーが割り当てされていない場合に発生しました。

image.png

Athena ワークグループ上でユーザー割り当てが出来るので、ここから割り当てを行いましょう。

image.png

Query execution failed: Access denied when getting s3 access grants to location: s3://xxxxxx . Please ensure you are allowed to access the S3 bucket. If specifying an expected bucket owner, confirm the bucket is owned by the expected account

これはですね、おそらく複数要因によって発生しやすいエラーメッセージでピンポイントでこの変更をしましょう。という案内が難しいです。
私の場合は次のように S3 Access Grants の権限と Lake Formation の権限を設定することで解決出来ました。

1FE9FF03-1768-45E2-BF5F-6A4E84AD041D_1_105_c.jpeg

要は QuickSight サービスロールと認証ユーザー、Athena サービスロールが、クエリ結果保存先の S3 バケットに Access Grants の観点でアクセス可能かという観点で調べる必要があります。

さいごに

本日は Amazon QuickSight で TIP を使った Athena ワークグループのデータセットを作成したときに遭遇したエラーたちと解決方法を紹介しました。

QuickSight に限らず TIP は通常の権限管理よりもかなり管理が複雑になりますのでこういった初期構築時にエラーに遭遇しやすいです。
昨今は Amazon Q Developer が使えるのでトライ&エラーもしやすいですが、TIP や S3 Access Grants、Lake Formation の難易度の高さを再認識しました。

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.