本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
您可以 AWS Step Functions 與 Amazon Athena 整合,以啟動和停止查詢執行,並使用 Step Functions 取得查詢結果。使用 Step Functions,您可以執行臨機操作或排程的資料查詢,並擷取以 S3 資料湖為目標的結果。Athena 沒有伺服器,所以不需設定和管理基礎設施,而且您只需支付執行的查詢費用。此頁面列出支援的 Athena,APIs並提供啟動 Athena 查詢的範例Task
狀態。
若要了解如何在 Step Functions 中整合 AWS 服務,請參閱 整合 服務和 將參數傳遞至 Step Functions API中的服務。
Optimized Athena 整合的主要功能
-
支援執行任務 (.sync)整合模式。
-
請求回應 整合模式沒有最佳化。
-
不支援使用任務權杖等待回呼整合模式。
若要 AWS Step Functions 與 Amazon Athena 整合,您可以使用提供的 Athena 服務整合 APIs。
服務整合APIs與對應的 Athena 相同APIs。並非所有 都APIs支援所有整合模式,如下表所示。
API | 請求回應 | 執行任務 (.sync) |
---|---|---|
StartQueryExecution |
支援 | 支援 |
StopQueryExecution |
支援 | 不支援 |
GetQueryExecution |
支援 | 不支援 |
GetQueryResults |
支援 | 不支援 |
以下包含啟動 Athena 查詢的任務狀態。
"Start an Athena query": {
"Type": "Task",
"Resource": "arn:aws:states:::athena:startQueryExecution.sync",
"Parameters": {
"QueryString": "SELECT * FROM \"myDatabase\".\"myTable\" limit 1",
"WorkGroup": "primary",
"ResultConfiguration": {
"OutputLocation": "s3://amzn-s3-demo-bucket"
}
},
"Next": "Get results of the query"
}
支援的 Amazon AthenaAPIs:
注意
Step Functions 中任務的最大輸入或結果資料大小有配額。當您向另一個 服務傳送或接收資料時,這會限制您將 256 KiB 的資料做為 UTF-8 編碼字串。請參閱 狀態機器執行的相關配額。
IAM 用於呼叫 Amazon Athena 的政策
下列範例範本顯示 如何根據您狀態機器定義中的資源 AWS Step Functions 產生IAM政策。如需詳細資訊,請參閱 Step Functions 式如何為整合式服務產生IAM原則 和 探索 Step Functions 中的服務整合模式。
StartQueryExecution
靜態資源
{
"Version": "2012-10-17",
"Statement":[
{
"Effect": "Allow",
"Action": [
"athena:startQueryExecution",
"athena:stopQueryExecution",
"athena:getQueryExecution",
"athena:getDataCatalog"
],
"Resource": [
"arn:aws:athena:{{region}}:{{accountId}}:workgroup/[[workGroup]]",
"arn:aws:athena:{{region}}:{{accountId}}:datacatalog/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload",
"s3:CreateBucket",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::*"
]
},
{
"Effect": "Allow",
"Action": [
"glue:CreateDatabase",
"glue:GetDatabase",
"glue:GetDatabases",
"glue:UpdateDatabase",
"glue:DeleteDatabase",
"glue:CreateTable",
"glue:UpdateTable",
"glue:GetTable",
"glue:GetTables",
"glue:DeleteTable",
"glue:BatchDeleteTable",
"glue:BatchCreatePartition",
"glue:CreatePartition",
"glue:UpdatePartition",
"glue:GetPartition",
"glue:GetPartitions",
"glue:BatchGetPartition",
"glue:DeletePartition",
"glue:BatchDeletePartition"
],
"Resource": [
"arn:aws:glue:{{region}}:{{accountId}}:catalog",
"arn:aws:glue:{{region}}:{{accountId}}:database/*",
"arn:aws:glue:{{region}}:{{accountId}}:table/*",
"arn:aws:glue:{{region}}:{{accountId}}:userDefinedFunction/*"
]
},
{
"Effect": "Allow",
"Action": [
"lakeformation:GetDataAccess"
],
"Resource": [
"*"
]
}
]
}
動態資源
{
"Version": "2012-10-17",
"Statement":[
{
"Effect": "Allow",
"Action": [
"athena:startQueryExecution",
"athena:stopQueryExecution",
"athena:getQueryExecution",
"athena:getDataCatalog"
],
"Resource": [
"arn:aws:athena:{{region}}:{{accountId}}:workgroup/*",
"arn:aws:athena:{{region}}:{{accountId}}:datacatalog/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload",
"s3:CreateBucket",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::*"
]
},
{
"Effect": "Allow",
"Action": [
"glue:CreateDatabase",
"glue:GetDatabase",
"glue:GetDatabases",
"glue:UpdateDatabase",
"glue:DeleteDatabase",
"glue:CreateTable",
"glue:UpdateTable",
"glue:GetTable",
"glue:GetTables",
"glue:DeleteTable",
"glue:BatchDeleteTable",
"glue:BatchCreatePartition",
"glue:CreatePartition",
"glue:UpdatePartition",
"glue:GetPartition",
"glue:GetPartitions",
"glue:BatchGetPartition",
"glue:DeletePartition",
"glue:BatchDeletePartition"
],
"Resource": [
"arn:aws:glue:{{region}}:{{accountId}}:catalog",
"arn:aws:glue:{{region}}:{{accountId}}:database/*",
"arn:aws:glue:{{region}}:{{accountId}}:table/*",
"arn:aws:glue:{{region}}:{{accountId}}:userDefinedFunction/*"
]
},
{
"Effect": "Allow",
"Action": [
"lakeformation:GetDataAccess"
],
"Resource": [
"*"
]
}
]
}
StopQueryExecution
資源
{
"Version": "2012-10-17",
"Statement":[
{
"Effect": "Allow",
"Action": [
"athena:stopQueryExecution"
],
"Resource": [
"arn:aws:athena:{{region}}:{{accountId}}:workgroup/*"
]
}
]
}
GetQueryExecution
資源
{
"Version": "2012-10-17",
"Statement":[
{
"Effect": "Allow",
"Action": [
"athena:getQueryExecution"
],
"Resource": [
"arn:aws:athena:{{region}}:{{accountId}}:workgroup/*"
]
}
]
}
GetQueryResults
資源
{
"Version": "2012-10-17",
"Statement":[
{
"Effect": "Allow",
"Action": [
"athena:getQueryResults"
],
"Resource": [
"arn:aws:athena:{{region}}:{{accountId}}:workgroup/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::*"
]
}
]
}