要限制对保存查询的访问,您可以使用AWS Identity and Access Management(IAM)策略来控制用户对Athena查询的访问。
以下是一个示例IAM策略,该策略仅允许用户运行名为"my_saved_query"的保存查询。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"athena:GetQueryExecution",
"athena:ListNamedQueries",
"athena:GetNamedQuery"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "athena:StartQueryExecution",
"Resource": "arn:aws:athena:region:account-id:workgroup/default"
},
{
"Effect": "Allow",
"Action": "athena:GetQueryResults",
"Resource": "arn:aws:athena:region:account-id:workgroup/default/query-execution/*"
},
{
"Effect": "Allow",
"Action": "athena:GetQueryResultsStream",
"Resource": "arn:aws:athena:region:account-id:workgroup/default/query-execution/*"
},
{
"Effect": "Allow",
"Action": "athena:StartQueryExecution",
"Resource": "arn:aws:athena:region:account-id:workgroup/default/named_query/my_saved_query"
}
]
}
请确保将region和account-id替换为您的AWS区域和帐户ID。
在此策略中,我们允许用户执行查询和访问查询结果,但仅允许启动名为"my_saved_query"的保存查询。其他Athena操作(例如创建表、删除查询等)可能需要其他权限。
您可以将此策略附加到用户、组或角色,并根据需要进行调整以满足您的具体要求。