

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Step Functions で Athena クエリを実行する
<a name="connect-athena"></a>

Amazon Athena AWS Step Functionsと統合して、クエリの実行を開始および停止し、Step Functions でクエリ結果を取得できます。Step Functions を使用して、アドホックまたはスケジュールされたデータクエリを実行し、S3 データレイクを対象とした結果を取得できます。Athena はサーバーレスであるため、インフラストラクチャの設定や管理は不要です。また、実行したクエリにのみ課金されます。このページでは、サポートされている Athena API を一覧表示し、Athena クエリを開始するための `Task` 状態の例を示します。

Step Functions での AWSサービスとの統合については、[ サービスとの統合](integrate-services.md)「」および「」を参照してください[Step Functions でサービス API にパラメータを渡す](connect-parameters.md)。

**最適化された Athena 統合の主な機能**  
[ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) 統合パターンがサポートされています。
[レスポンスのリクエスト](connect-to-resource.md#connect-default) 統合パターンに固有の最適化はありません。
[タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token) 統合パターンはサポートされていません。

Amazon Athena AWS Step Functionsと統合するには、提供されている Athena サービス統合 APIs を使用します。

サービス統合 API は、対応する Athena API と同じです。次の表に示すとおり、すべての API がすべての統合パターンをサポートしているわけではありません。


| API | レスポンスのリクエスト | ジョブの実行 (.sync) | 
| --- | --- | --- | 
| StartQueryExecution | サポート対象 | サポート対象 | 
| StopQueryExecution | サポート | サポートされません | 
| GetQueryExecution | サポート | サポートされません | 
| GetQueryResults | サポート | サポートされません | 

以下には、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 Athena API:
<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)

**入力または結果データのクォータ**  
サービス間でデータを送受信する際、タスクの入力または結果の最大サイズは、UTF-8 でエンコードされた文字列で 256 KiB です。「[ステートマシンの実行に関連するクォータ](service-quotas.md#service-limits-state-machine-executions)」を参照してください。

## Amazon Athena を呼び出すための IAM ポリシー
<a name="athena-iam"></a>

次のサンプルテンプレートは、 がステートマシン定義のリソースに基づいて IAM ポリシーAWS Step Functionsを生成する方法を示しています。詳細については、「[Step Functions が統合サービスの IAM ポリシーを生成する方法](service-integration-iam-templates.md)」および「[Step Functions でサービス統合パターンを検出する](connect-to-resource.md)」を参照してください。

**注記**  
IAM ポリシーに加えて、 AWS Lake Formationを使用して Amazon S3 や などの サービスのデータへのアクセスを許可する必要がある場合がありますAWS Glue Data Catalog。詳細については、[「Athena を使用して に登録されたデータをクエリするAWS Lake Formation](https://docs.aws.amazon.com/athena/latest/ug/security-athena-lake-formation.html)」を参照してください。

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

静的リソース**

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

------

動的リソース**

------
#### [ 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>

*リソース*

****  

```
{
    "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>

*リソース*

****  

```
{
    "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>

*リソース*

****  

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