工作群組政策範例 - Amazon Athena

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

工作群組政策範例

本節包含可讓您在工作群組上用來啟用各種動作的政策範例。每當您使用IAM原則時,請務必遵循IAM最佳做法。如需詳細資訊,請參閱《IAM使用指南》IAM中的「安全性最佳作法」。

工作群組是由 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:ListDataCatalogs", "athena:ListDatabases", "athena:GetDatabase", "athena:ListTableMetadata", "athena:GetTableMetadata" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "athena:BatchGetQueryExecution", "athena:GetQueryExecution", "athena:ListQueryExecutions", "athena:StartQueryExecution", "athena:StopQueryExecution", "athena:GetQueryResults", "athena:GetQueryResultsStream", "athena:CreateNamedQuery", "athena:GetNamedQuery", "athena:BatchGetNamedQuery", "athena:ListNamedQueries", "athena:DeleteNamedQuery", "athena:CreatePreparedStatement", "athena:GetPreparedStatement", "athena:ListPreparedStatements", "athena:UpdatePreparedStatement", "athena:DeletePreparedStatement" ], "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:ListEngineVersions", "athena:ListWorkGroups", "athena:ListDataCatalogs", "athena:ListDatabases", "athena:GetDatabase", "athena:ListTableMetadata", "athena:GetTableMetadata" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "athena:GetWorkGroup", "athena:BatchGetQueryExecution", "athena:GetQueryExecution", "athena:ListQueryExecutions", "athena:StartQueryExecution", "athena:StopQueryExecution", "athena:GetQueryResults", "athena:GetQueryResultsStream", "athena:CreateNamedQuery", "athena:GetNamedQuery", "athena:BatchGetNamedQuery", "athena:ListNamedQueries", "athena:DeleteNamedQuery", "athena:CreatePreparedStatement", "athena:GetPreparedStatement", "athena:ListPreparedStatements", "athena:UpdatePreparedStatement", "athena:DeletePreparedStatement" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/workgroupA" ] } ] }
範例
適用於在主要工作群組中執行查詢的政策範例

您可以修改上述範例,以允許特定使用者也在主要工作群組中執行查詢。

注意

對於以其他方式設定為在指定的工作群組中執行查詢的所有使用者,我們建議您新增主要工作群組資源。為了以防其指定的工作群組遭到刪除或停用,將此資源新增到其工作群組使用者政策非常有用。在這種情況下,他們可以在主要工作群組中繼續執行查詢。

若要允許您帳戶中的使用者在主要工作群組中執行查詢,請將包含主要工作群組ARN的行加入到的資源區段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" ] } ] }
範例
適用於列出工作群組的政策範例

以下政策可讓所有使用者列出所有工作群組:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:ListWorkGroups" ], "Resource": "*" } ] }
範例
適用於在特定工作群組中執行和停止查詢的政策範例

在這個政策中,允許使用者在工作群組中執行查詢:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:StartQueryExecution", "athena:StopQueryExecution" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/test_workgroup" ] } ] }
範例
適用於在特定工作群組中處理具名查詢的政策範例

在以下政策中,使用者有許可在指定的工作群組中建立、刪除具名查詢及取得其相關資訊:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:CreateNamedQuery", "athena:GetNamedQuery", "athena:DeleteNamedQuery" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/test_workgroup" ] } ] }
範例
使用 Athena 中的 Spark 筆記本的範例政策

使用類似下列所示的政策來使用 Athena 中的 Spark 筆記本。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowCreatingWorkGroupWithDefaults", "Action": [ "athena:CreateWorkGroup", "s3:CreateBucket", "iam:CreateRole", "iam:CreatePolicy", "iam:AttachRolePolicy", "s3:GetBucketLocation", "athena:ImportNotebook" ], "Effect": "Allow", "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/Demo*", "arn:aws:s3:::123456789012-us-east-1-athena-results-bucket-*", "arn:aws:iam::123456789012:role/service-role/AWSAthenaSparkExecutionRole-*", "arn:aws:iam::123456789012:policy/service-role/AWSAthenaSparkRolePolicy-*" ] }, { "Sid": "AllowRunningCalculations", "Action": [ "athena:ListWorkGroups", "athena:GetWorkGroup", "athena:StartSession", "athena:CreateNotebook", "athena:ListNotebookMetadata", "athena:ListNotebookSessions", "athena:GetSessionStatus", "athena:GetSession", "athena:GetNotebookMetadata", "athena:CreatePresignedNotebookUrl" ], "Effect": "Allow", "Resource": "arn:aws:athena:us-east-1:123456789012:workgroup/Demo*" }, { "Sid": "AllowListWorkGroupAndEngineVersions", "Action": [ "athena:ListWorkGroups", "athena:ListEngineVersions" ], "Effect": "Allow", "Resource": "*" } ] }