

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Esegui le query Athena con Step Functions
<a name="connect-athena"></a>

Puoi integrarti AWS Step Functions con Amazon Athena per avviare e interrompere l'esecuzione delle query e ottenere risultati delle query con Step Functions. Utilizzando Step Functions, puoi eseguire query di dati ad hoc o pianificate e recuperare risultati destinati ai tuoi data lake S3. Athena è un servizio serverless, perciò non occorre installare o gestire alcuna infrastruttura e vengono addebitati solo i costi relativi all'esecuzione delle query. Questa pagina elenca gli Athena supportati APIs e fornisce `Task` uno stato di esempio per avviare una query Athena.

Per ulteriori informazioni sull'integrazione con AWS i servizi in Step Functions, vedere [Integrazione dei servizi ](integrate-services.md) e[Passaggio di parametri a un'API di servizio in Step Functions](connect-parameters.md).

**Caratteristiche principali dell'integrazione con Optimized Athena**  
Il modello di [Esegui un processo (.sync)](connect-to-resource.md#connect-sync) integrazione è supportato.
Non esistono ottimizzazioni specifiche per il modello di [Richiesta e risposta](connect-to-resource.md#connect-default) integrazione.
Il modello di [Attendi una richiamata con Task Token](connect-to-resource.md#connect-wait-token) integrazione non è supportato.

Per l'integrazione AWS Step Functions con Amazon Athena, utilizzi l'integrazione del servizio Athena fornita. APIs

L'integrazione APIs del servizio è la stessa della corrispondente Athena APIs. Non tutti APIs supportano tutti i modelli di integrazione, come illustrato nella tabella seguente.


| "Hello, World\$1" | Richiesta e risposta | Esegui un processo (.sync) | 
| --- | --- | --- | 
| StartQueryExecution | Supportata | Supportato | 
| StopQueryExecution | Supportata | Non supportato | 
| GetQueryExecution | Supportata | Non supportato | 
| GetQueryResults | Supportata | Non supportato | 

Quanto segue include uno stato Task che avvia una query 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"
}
```

## Amazon APIs Athena ottimizzato:
<a name="connect-athena-api"></a>
+ [https://docs.aws.amazon.com/athena/latest/APIReference/API_StartQueryExecution.html](https://docs.aws.amazon.com/athena/latest/APIReference/API_StartQueryExecution.html)
+ [https://docs.aws.amazon.com/athena/latest/APIReference/API_StopQueryExecution.html](https://docs.aws.amazon.com/athena/latest/APIReference/API_StopQueryExecution.html)
+ [https://docs.aws.amazon.com/athena/latest/APIReference/API_GetQueryExecution.html](https://docs.aws.amazon.com/athena/latest/APIReference/API_GetQueryExecution.html)
+ [https://docs.aws.amazon.com/athena/latest/APIReference/API_GetQueryResults.html](https://docs.aws.amazon.com/athena/latest/APIReference/API_GetQueryResults.html)

**Quota per i dati di input o di risultato**  
Quando si inviano o si ricevono dati tra servizi, l'input o il risultato massimo per un'attività è di 256 KB di dati come stringa con codifica UTF-8. Per informazioni, consulta [Quote relative alle esecuzioni di macchine a stati](service-quotas.md#service-limits-state-machine-executions).

## Politiche IAM per le chiamate ad Amazon Athena
<a name="athena-iam"></a>

I seguenti modelli di esempio mostrano come AWS Step Functions generare le politiche IAM in base alle risorse nella definizione della macchina a stati. Per ulteriori informazioni, consultare [In che modo Step Functions genera policy IAM per servizi integrati](service-integration-iam-templates.md) e [Scopri i modelli di integrazione dei servizi in Step Functions](connect-to-resource.md).

**Nota**  
Oltre alle policy IAM, potresti dover utilizzare per AWS Lake Formation concedere l'accesso ai dati in servizi, come Amazon S3 e. AWS Glue Data Catalog Per ulteriori informazioni, consulta [Utilizzare Athena per interrogare i dati registrati con](https://docs.aws.amazon.com/athena/latest/ug/security-athena-lake-formation.html). AWS Lake Formation 

### `StartQueryExecution`
<a name="athena-iam-startqueryexecution"></a>

*Risorse statiche*

------
#### [ 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": [
            "*"
        ]
    }
]
}
```

------

*Risorse dinamiche*

------
#### [ 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`
<a name="athena-iam-stopqueryexecution"></a>

*Risorse*

****  

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

### `GetQueryExecution`
<a name="athena-iam-getqueryexecution"></a>

*Risorse*

****  

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

### `GetQueryResults`
<a name="athena-iam-getqueryresults"></a>

*Risorse*

****  

```
{
    "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:::*"
        ]
    }
    ]
}
```