本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
工作组策略示例
本节包含您可以用于启用对工作组执行各种操作的策略示例。
工作组是由 Athena 管理的 IAM 资源。因此,如果您的工作组策略使用获取 workgroup
作为输入的操作,您必须如下所示指定工作组的 ARN:
"Resource": [arn:aws:athena:<region>:<user-account>:workgroup/<workgroup-name>]
其中,<workgroup-name>
是工作组的名称。例如,对于名为 test_workgroup
的工作组,指定它作为资源,如下所示:
"Resource": [
"arn:aws:athena:us-east-1:123456789012:workgroup/test_workgroup"
]
有关 Amazon Athena 操作的完整列表,请参阅 Amazon Athena API 参考中的 API 操作名称。有关 IAM 策略的更多信息,请参阅 中的使用可视化编辑器创建策略。IAM 用户指南有关为工作组创建 IAM 策略的更多信息,请参阅工作组 IAM 策略。
以下策略可实现对账户中可能存在的所有工作组资源具有完全访问权限。对于必须为其他所有用户监督和管理工作组的那些用户,我们建议您使用此策略。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:*" ], "Resource": [ "*" ] } ] }
以下策略允许对单个名为 workgroupA
的特定工作组资源进行完全访问。 您可以对特定工作组拥有完全控制权限的用户使用此策略。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:ListEngineVersions", "athena:ListWorkGroups", "athena:GetExecutionEngine", "athena:GetExecutionEngines", "athena:GetNamespace", "athena:GetCatalogs", "athena:GetNamespaces", "athena:GetTables", "athena:GetTable" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "athena:StartQueryExecution", "athena:GetQueryResults", "athena:DeleteNamedQuery", "athena:GetNamedQuery", "athena:ListQueryExecutions", "athena:StopQueryExecution", "athena:GetQueryResultsStream", "athena:ListNamedQueries", "athena:CreateNamedQuery", "athena:GetQueryExecution", "athena:BatchGetNamedQuery", "athena:BatchGetQueryExecution" ], "Resource": [
"arn:aws:athena:us-east-1:123456789012:workgroup/workgroupA"
] }, { "Effect": "Allow", "Action": [ "athena:DeleteWorkGroup", "athena:UpdateWorkGroup", "athena:GetWorkGroup", "athena:CreateWorkGroup" ], "Resource": ["arn:aws:athena:us-east-1:123456789012:workgroup/workgroupA"
] } ] }
在以下策略中,允许用户运行指定 workgroupA
中的查询并查看它们。不允许用户对工作组本身执行管理任务,例如,更新或删除它。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:ListWorkGroups", "athena:GetExecutionEngine", "athena:GetExecutionEngines", "athena:GetNamespace", "athena:GetCatalogs", "athena:GetNamespaces", "athena:GetTables", "athena:GetTable" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "athena:StartQueryExecution", "athena:GetQueryResults", "athena:DeleteNamedQuery", "athena:GetNamedQuery", "athena:ListQueryExecutions", "athena:StopQueryExecution", "athena:GetQueryResultsStream", "athena:ListNamedQueries", "athena:CreateNamedQuery", "athena:GetQueryExecution", "athena:BatchGetNamedQuery", "athena:BatchGetQueryExecution", "athena:GetWorkGroup" ], "Resource": [
"arn:aws:athena:us-east-1:123456789012:workgroup/workgroupA"
] } ] }
在以下示例中,我们使用的策略是允许特定用户运行主工作组中的查询。
对于另行配置为运行指定工作组中查询的所有用户,我们建议您为其添加此策略。在用户的指定工作组已被删除或禁用的情况下,在工作组用户策略中添加此策略有用。在这种情况下,他们可以继续运行主工作组中的查询。
要允许您账户中的用户运行主工作组中的查询,请将以下策略添加到 Example Policy for Running Queries in a Specified Workgroup 的资源部分。
"arn:aws:athena:us-east-1:123456789012:workgroup/primary"
在以下策略中,允许用户创建、删除、获取详细信息并更新工作组的 test_workgroup
。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:ListEngineVersions" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "athena:CreateWorkGroup", "athena:GetWorkGroup", "athena:DeleteWorkGroup", "athena:UpdateWorkGroup" ], "Resource": [ "
arn:aws:athena:us-east-1:123456789012:workgroup/test_workgroup
" ] } ] }
以下策略允许所有用户列出所有工作组:
{ "Effect": "Allow", "Action": [ "athena:ListWorkGroups" ], "Resource": "*" }
在此策略中,允许用户运行工作组中的查询:
{ "Effect": "Allow", "Action": [ "athena:StartQueryExecution", "athena:StopQueryExecution" ], "Resource": [
"arn:aws:athena:us-east-1:123456789012:workgroup/test_workgroup"
] }
在以下策略中,用户具有在指定工作组中创建和删除命名查询以及获取其相关信息的权限:
{ "Effect": "Allow", "Action": [ "athena:CreateNamedQuery", "athena:GetNamedQuery", "athena:DeleteNamedQuery" ], "Resource": [
"arn:aws:athena:us-east-1:123456789012:workgroup/test_workgroup"
] }