Realizar consultas do Athena com o Step Functions - AWS Step Functions

Realizar consultas do Athena com o Step Functions

É possível integrar o AWS Step Functions ao Amazon Athena para iniciar e interromper a execução de consultas e receber resultados de consultas com o Step Functions. Usando o Step Functions, você pode executar consultas de dados específicas ou agendadas e recuperar os resultados direcionados aos data lakes do S3. Como o Athena não utiliza servidor, não há infraestrutura para configurar ou gerenciar, e você paga apenas pelas consultas executadas. Esta página lista as APIs do Athena compatíveis e fornece um exemplo de estado Task para iniciar uma consulta do Athena.

Para saber mais sobre a integração com serviços da AWS no Step Functions, consulte Integração de produtos da e Transmitir parâmetros a uma API de serviço no Step Functions.

Principais recursos da integração otimizada ao Athena

Para integrar o AWS Step Functions ao Amazon Athena, use as APIs de integração de serviço do Athena fornecidas.

As APIs de integração de serviços são iguais às APIs Athena correspondentes. Nem todas as APIs oferecem suporte a todos os padrões de integração, como mostrado na tabela a seguir.

API Resposta de solicitação Executar um trabalho (.sync)
StartQueryExecution Compatível Compatível
StopQueryExecution Compatível Não compatível
GetQueryExecution Compatível Não compatível
GetQueryResults Compatível Não compatível

Veja a seguir um estado de Tarefa que inicia uma consulta do Athena.

"Start an Athena query": { "Type": "Task", "Resource": "arn:aws:states:::athena:startQueryExecution.sync", "Arguments": { "QueryString": "SELECT * FROM \"myDatabase\".\"myTable\" limit 1", "WorkGroup": "primary", "ResultConfiguration": { "OutputLocation": "s3://amzn-s3-demo-bucket" } }, "Next": "Get results of the query" }

APIs otimizadas do Amazon Athena:

Cota para dados de entrada ou resultado

Ao enviar ou receber dados entre serviços, o máximo de entrada ou resultado de uma tarefa é 256 KiB de dados como uma string codificada em UTF-8. Consulte Cotas relacionadas a execuções de máquina de estado.

Políticas do IAM para chamar o Amazon Athena

Os modelos de exemplo a seguir mostram como o AWS Step Functions gera políticas do IAM com base nos recursos da definição da máquina de estado. Para obter mais informações, consulte Como o Step Functions gera políticas do IAM para serviços integrados e Descobrir padrões de integração de serviços no Step Functions.

nota

Além das políticas do IAM, talvez você precise usar o AWS Lake Formation para conceder acesso aos dados em serviços, como o Amazon S3 e o AWS Glue Data Catalog. Para obter informações, consulte Usar o Athena para consultar dados registrados no AWS Lake Formation.

StartQueryExecution

Recursos estáticos

Run a Job (.sync)
{ "Version":"2012-10-17", "Statement":[ { "Effect": "Allow", "Action": [ "athena:startQueryExecution", "athena:stopQueryExecution", "athena:getQueryExecution", "athena:getDataCatalog", "athena:GetWorkGroup", "athena:BatchGetQueryExecution", "athena:GetQueryResults", "athena:ListQueryExecutions" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/myWorkGroup", "arn:aws:athena:us-east-1:123456789012: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:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/*", "arn:aws:glue:us-east-1:123456789012:table/*", "arn:aws:glue:us-east-1:123456789012:userDefinedFunction/*" ] }, { "Effect": "Allow", "Action": [ "lakeformation:GetDataAccess" ], "Resource": [ "*" ] } ] }
Request Response
{ "Version":"2012-10-17", "Statement":[ { "Effect": "Allow", "Action": [ "athena:startQueryExecution", "athena:getDataCatalog" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/myWorkGroup", "arn:aws:athena:us-east-1:123456789012: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:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/*", "arn:aws:glue:us-east-1:123456789012:table/*", "arn:aws:glue:us-east-1:123456789012:userDefinedFunction/*" ] }, { "Effect": "Allow", "Action": [ "lakeformation:GetDataAccess" ], "Resource": [ "*" ] } ] }

Recursos dinâmicos

Run a Job (.sync)
{ "Version":"2012-10-17", "Statement":[ { "Effect": "Allow", "Action": [ "athena:startQueryExecution", "athena:stopQueryExecution", "athena:getQueryExecution", "athena:getDataCatalog", "athena:GetWorkGroup", "athena:BatchGetQueryExecution", "athena:GetQueryResults", "athena:ListQueryExecutions" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/*", "arn:aws:athena:us-east-1:123456789012: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:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/*", "arn:aws:glue:us-east-1:123456789012:table/*", "arn:aws:glue:us-east-1:123456789012:userDefinedFunction/*" ] }, { "Effect": "Allow", "Action": [ "lakeformation:GetDataAccess" ], "Resource": [ "*" ] } ] }
Request Response
{ "Version":"2012-10-17", "Statement":[ { "Effect": "Allow", "Action": [ "athena:startQueryExecution", "athena:getDataCatalog" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/*", "arn:aws:athena:us-east-1:123456789012: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:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/*", "arn:aws:glue:us-east-1:123456789012:table/*", "arn:aws:glue:us-east-1:123456789012:userDefinedFunction/*" ] }, { "Effect": "Allow", "Action": [ "lakeformation:GetDataAccess" ], "Resource": [ "*" ] } ] }

StopQueryExecution

Recursos

{ "Version":"2012-10-17", "Statement":[ { "Effect": "Allow", "Action": [ "athena:stopQueryExecution" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/*" ] } ] }

GetQueryExecution

Recursos

{ "Version":"2012-10-17", "Statement":[ { "Effect": "Allow", "Action": [ "athena:getQueryExecution" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/*" ] } ] }

GetQueryResults

Recursos

{ "Version":"2012-10-17", "Statement":[ { "Effect": "Allow", "Action": [ "athena:getQueryResults" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/*" ] }, { "Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": [ "arn:aws:s3:::*" ] } ] }