

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

# 最適化されたサービスと Step Functions の統合
<a name="integrate-optimized"></a>

ワークフローは、`Task` ステートの `Resource` フィールドを使用して、最適化サービスを直接呼び出すことができます。以下のトピックでは、AWSサービスを調整するために Amazon States Language でサポートされている APIs、パラメータ、およびリクエスト/レスポンス構文について説明します。

ワークフローのタイプと可用性に応じて、ワークフローは 3 つのサービス統合パターンのいずれかを使用してサービスを呼び出します。
+ [レスポンスのリクエスト (デフォルト)](connect-to-resource.md#connect-default) - HTTP レスポンスを待ってから次の状態に進みます。
+ [ジョブの実行 (`.sync`)](connect-to-resource.md#connect-sync) - ジョブが完了するまで待ちます。
+ [コールバックの待機 (`.waitForTaskToken`)](connect-to-resource.md#connect-wait-token) - タスクトークンが返されるまでワークフローを一時停止します。

Standard ワークフローと Express ワークフローは、同じ**統合**をサポートしますが、同じ**統合パターン**はサポートしていません。
+  **Standard ワークフロー**は、*リクエストのレスポンス*の統合をサポートします。特定のサービスでは、*ジョブの実行 (.sync)* または*コールバックの待機 (.waitForTaskToken)*、および場合によってはその両方をサポートしています。詳細については、次の最適化された統合テーブルを参照してください。
+  **Express ワークフロー**は、*リクエストのレスポンス*の統合のみをサポートします。

 2 つのタイプ間の決定については、「[Step Functions でワークフロータイプを選択する](choosing-workflow-type.md)」を参照してください。



**AWSStep Functions での SDK 統合**


| 統合された サービス | レスポンスのリクエスト | ジョブの実行 - *.sync* | コールバックの待機 - *.waitForTaskToken* | 
| --- | --- | --- | --- | 
| [200 を超えるサービス](supported-services-awssdk.md#supported-services-awssdk-list) | Standard と Express | サポートされません | Standard | 

**Step Functions での統合最適化**


| 統合された サービス | レスポンスのリクエスト | ジョブの実行 - *.sync* | コールバックの待機 - *.waitForTaskToken* | 
| --- | --- | --- | --- | 
| [Amazon API Gateway](connect-api-gateway.md) | Standard と Express | サポートされません | Standard | 
| [Amazon Athena](connect-athena.md) | Standard と Express | Standard | サポートされません | 
| [AWS Batch](connect-batch.md) | Standard と Express | Standard | サポートされません | 
| [Amazon Bedrock](connect-bedrock.md) | Standard と Express | Standard | Standard | 
| [AWS CodeBuild](connect-codebuild.md) | Standard と Express | Standard | サポートされません | 
| [Amazon DynamoDB](connect-ddb.md) | Standard と Express | サポートされません | サポートされません | 
| [Amazon ECS/Fargate](connect-ecs.md) | Standard と Express | Standard | Standard | 
| [Amazon EKS](connect-eks.md) | Standard と Express | Standard | Standard | 
| [Amazon EMR](connect-emr.md) | Standard と Express | Standard | サポートされません | 
| [Amazon EMR on EKS](connect-emr-eks.md) | Standard と Express | Standard | サポートされません | 
| [Amazon EMR Serverless](connect-emr-serverless.md) | Standard と Express | Standard | サポートされません | 
| [Amazon EventBridge](connect-eventbridge.md) | Standard と Express | サポートされません | Standard | 
| [AWS Glue](connect-glue.md) | Standard と Express | Standard | サポートされません | 
| [AWS Glue DataBrew](connect-databrew.md) | Standard と Express | Standard | サポートされません | 
| [AWS Lambda](connect-lambda.md) | Standard と Express | サポートされません | Standard | 
| [AWS Elemental MediaConvert](connect-mediaconvert.md) | Standard と Express | Standard | サポートされません | 
| [Amazon SageMaker AI](connect-sagemaker.md) | Standard と Express | Standard | サポートされません | 
| [Amazon SNS](connect-sns.md) | Standard と Express | サポートされません | Standard | 
| [Amazon SQS](connect-sqs.md) | Standard と Express | サポートされません | Standard | 
| [AWS Step Functions](connect-stepfunctions.md) | Standard と Express | Standard | Standard | 

# Step Functions を使用して API Gateway REST API を作成する
<a name="connect-api-gateway"></a>

Amazon API Gateway を使用して、Step Functions で HTTP と REST API を作成、発行、管理、モニタリングする方法について説明します。API Gateway と統合するには、コードを記述したり、他のインフラストラクチャに依存したりすることなく、API Gateway HTTP または API Gateway REST エンドポイントを直接呼び出す Step Functions 内の `Task` 状態を定義します。`Task` 状態定義には、API コールに必要なすべての情報が含まれます。別の認可方法を選択することもできます。

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

**最適化された API Gateway 統合の主な機能**  
`apigateway:invoke:` には、 AWS SDK サービス統合で同等のものはありません。代わりに、最適化 API Gateway サービスは API Gateway エンドポイントを直接呼び出します。

## API Gateway 特徴のサポート
<a name="connect-api-gateway-support"></a>

Step Functions API Gateway 統合は、一部の API Gateway 機能をサポートしますが、すべてはサポートしていません。サポートされている特徴の詳細なリストについては、以下を参照してください。
+ 以下は、Step Functions API Gateway REST API と API Gateway HTTP API 統合の両方でサポートされています。
  + **オーソライザー**: IAM ([署名バージョン 4](https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html)を使用)、認証なし、Lambda Authorizers (カスタムヘッダーを使用したリクエストパラメータベースおよびトークンベース)
  + **API タイプ**: リージョン
  + **API 管理**: API Gateway API ドメイン名、API ステージ、パス、クエリパラメータ、リクエストボディ
+ Step Functions API Gateway HTTP API 統合でサポートされています。エッジ最適化 API のオプションを提供する Step Functions API Gateway REST API 統合はサポートされていません。
+ Step Functions API Gateway 統合ではサポートされていません。
  +  **オーソライザー**: Amazon Cognito、ネイティブオープン ID Connect/OAuth 2.0、トークンベースの Lambda オーソライザーの認可ヘッダー 
  +  **API タイプ**: プライベート 
  +  **API 管理**: カスタムドメイン名 

API Gateway と HTTP および REST API の詳細については、以下を参照してください。
+  [Amazon API Gateway の概念](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-basic-concept.html)ページ。
+  API Gateway デベロッパーガイドの [HTTP API と REST API 間で選択します](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html)。

## リクエストの形式
<a name="connect-api-gateway-requests"></a>

`Task` 状態定義を作成するとき、Step Functions はパラメータを検証し、呼び出しを実行するのに必要な URL を構築し、API を呼び出します。レスポンスには、HTTP ステータスコード、ヘッダー、およびレスポンス本文が含まれます。リクエスト形式には、必須およびオプションのパラメータがあります。

### 必須リクエストパラメータ
<a name="connect-api-gateway-requests-required"></a>
+ `ApiEndpoint`
  + 型: `String`
  + API Gateway URL のホスト名。形式は `<API ID>.execute-api.region.amazonaws.com` です。

    API ID には、次の英数字の組み合わせのみを使用できます: `0123456789abcdefghijklmnopqrstuvwxyz`
+ `Method`
  + 型: `Enum`
  + HTTP メソッド。次のいずれかとなる必要があります。
    + `GET`
    + `POST`
    + `PUT`
    + `DELETE`
    + `PATCH`
    + `HEAD`
    + `OPTIONS`

### オプションのリクエストパラメータ
<a name="connect-api-gateway-requests-optional"></a>
+ `Headers`
  + 型: `JSON`
  + HTTP ヘッダーは、同じキーに関連付けられた値のリストを許可します。
+ `Stage`
  + 型: `String`
  + API Gateway で API がデプロイされるステージの名前。`$default` ステージを使用する HTTP API のオプションとなっています。
+ `Path`
  + 型: `String`
  + API エンドポイントの後に追加されるパスパラメータ。
+ `QueryParameters`
  + 型: `JSON`
  + クエリ文字列では、同じキーに関連付けられた値のリストのみが許可されます。
+ `RequestBody`
  + タイプ: `JSON` または `String`
  + HTTP リクエストボディ。そのタイプは、`JSON` オブジェクトまたは `String` です。`RequestBody` は、`PATCH`、`POST`、および `PUT` HTTP メソッドに対してのみサポートされています。
+ `AllowNullValues`
  + タイプ: `BOOLEAN` - デフォルト値: `false`
  + デフォルト設定では、リクエスト入力状態の **null** 値は API に送信**されません**。次の例では、ステートマシン定義で `AllowNullValues` が `true` に設定されていない限り、`category` フィールドはリクエストに**含まれません**。

    ```
    {
        "NewPet": {
            "type": "turtle",
            "price": 123,
            "category": null
        }
    }
    ```
**注記**  
デフォルトでは、リクエスト入力状態の **null** 値を持つフィールドは API に送信**されません**。ステートマシン定義で `AllowNullValues` を `true` に設定することで、null 値を強制的に API に送信できます。
+ `AuthType`
  + 型: `JSON`
  + 認証方法。デフォルトの方法は `NO_AUTH` です。指定できる値は次のとおりです。
    + `NO_AUTH`
    + `IAM_ROLE`
    + `RESOURCE_POLICY`

    詳細については、「**認証および認可**」を参照してください。

**注記**  
セキュリティを考慮して、以下の HTTP ヘッダーキーは現在、許可されていません。  
`X-Forwarded`、`X-Amz`、または `X-Amzn` のプレフィックスが付いているキー。
`Authorization`
`Connection`
`Content-md5`
`Expect`
`Host`
`Max-Forwards`
`Proxy-Authenticate`
`Server`
`TE`
`Transfer-Encoding`
`Trailer`
`Upgrade`
`Via`
`Www-Authenticate`

次のコード例は、Step Functions を使用して API Gateway を呼び出す方法を示しています。

```
{
    "Type": "Task", 
    "Resource":"arn:aws:states:::apigateway:invoke", 
    "Arguments": {
        "ApiEndpoint": "example.execute-api.us-east-1.amazonaws.com",
        "Method": "GET", 
        "Headers": { 
            "key": ["value1", "value2"] 
        },
        "Stage": "prod",
        "Path": "bills",
        "QueryParameters": {
            "billId": ["123456"]
        },
        "RequestBody": {},
        "AuthType": "NO_AUTH"
    } 
}
```

## 認証と認可
<a name="connect-api-gateway-auth"></a>

次の認証方法を使用できます。
+ **認可なし**: 認可メソッドなしで API を直接呼び出します。
+ **IAM ロール**: この方法では、Step Functions はステートマシンのロールを引き受けて、[署名バージョン 4](https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html) (SigV4) を使ってリクエストに署名した後、API を呼び出します。
+ **リソースポリシー**: Step Functions はリクエストを認証し、API を呼び出します。API に以下を指定するリソースポリシーをアタッチする必要があります。

  1. API Gateway を呼び出すステートマシン。
**重要**  
アクセスを制限するため、ステートマシンを指定する必要があります。そうしない場合は、API への**リソースポリシー**認証を使って API Gateway リクエストを認証するステートマシンにアクセスが付与されます。

  1. そのStep Functions は、API Gateway を呼び出すサービスです: `"Service": "states.amazonaws.com"`。

  1. アクセス対象のリソースには、以下が含まれます。
     + *region*。
     + 指定されたリージョンの *account-id*。
     + *api-id*。
     + *stage-name*。
     + *HTTP-VERB* (メソッド)。
     + *resource-path-specifier*。

  リソースポリシーの例については、[Step Functions と API Gateway 用 IAM ポリシー](#api-gateway-iam)を参照してください。

  リソース形式の詳細については、API Gateway デベロッパーガイドの [API Gateway における API 実行許可のリソース形式](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html#api-gateway-iam-policy-resource-format-for-executing-api)を参照してください。
**注記**  
リソースポリシーは REST API の場合に限り、サポートされます。

## サービス統合パターン
<a name="connect-api-gateway-patterns"></a>

API Gateway 統合では、次の 2 つのサービス統合パターンがサポートされています。
+ [レスポンスのリクエスト](connect-to-resource.md#connect-default)。デフォルトの統合パターンです。このおかげで、TTP レスポンスを受信した直後に Step Functions が H次のステップに進むことができます。
+ [タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token) (`.waitForTaskToken`) は、タスクトークンがペイロードとともに返されるまで待機します。以下の例に示す通り、`.waitForTaskToken` パターンを使うため、タスク定義の **[Resource]** (リソース) フィールドの末尾に .waitForTaskToken を追加します。

  ```
  {
      "Type": "Task", 
      "Resource":"arn:aws:states:::apigateway:invoke.waitForTaskToken", 
      "Arguments": {
          "ApiEndpoint": "example.execute-api.us-east-1.amazonaws.com",
          "Method": "POST", 
          "Headers": { 
              "TaskToken": "{% $states.context.Task.Token %}"
          },
          "Stage": "prod",
          "Path": "bills/add",
          "QueryParameters": {},
          "RequestBody": {
              "billId": "my-new-bill"
          },
          "AuthType": "IAM_ROLE"
      } 
  }
  ```

## 出力形式
<a name="connect-api-gateway-output"></a>

次の出力パラメータが提供されます。


| 名前 | 型 | 説明 | 
| --- | --- | --- | 
| ResponseBody | JSON または String | API コールのレスポンスの本文。 | 
| Headers | JSON | レスポンスヘッダー | 
| StatusCode | Integer | レスポンスの HTTP ステータスコード。 | 
| StatusText | String | レスポンスのステータステキスト。 | 

レスポンスの例:

```
{
    "ResponseBody": {
        "myBills": []
    },
    "Headers": { 
        "key": ["value1", "value2"]
    }, 
    "StatusCode": 200,
    "StatusText": "OK" 
}
```

## エラー処理
<a name="connect-api-gateway-errors"></a>

エラーが発生した場合、`error` そして `cause` は次のように返されます。
+ HTTP ステータスコードが使用可能な場合、エラーは `ApiGateway.<HTTP Status Code>` 形式で返されます。
+ HTTP ステータスコードが使用できない場合、エラーは `ApiGateway.<Exception>` 形式で返されます。

いずれの場合も、`cause` は文字列として返されます。

以下は、エラーが発生したレスポンスの例です。

```
{
    "error": "ApiGateway.403", 
    "cause": "{\"message\":\"Missing Authentication Token\"}"
}
```

**注記**  
`2XX` のステータスコードは成功を示し、エラーは返されません。他のすべてのステータスコードまたはスローされた例外は、エラーになります。

## Amazon API Gateway への呼び出しの IAM ポリシー
<a name="api-gateway-iam"></a>

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

*リソース*:

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Action": [
                "execute-api:Invoke"
            ],
            "Resource": [
                "arn:aws:execute-api:us-east-1:123456789012:ENDPOINT/STAGE/GET/pets",
                "arn:aws:execute-api:us-east-1:123456789012:ENDPOINT/STAGE/POST/pets"
            ],
            "Effect": "Allow"
        }
    ]
}
```

次のコード例では、API Gateway を呼び出すためのリソースポリシーを示しています。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "states.amazonaws.com"
            },
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:us-east-1:123456789012:myApi-id/stage-name/HTTP-VERB/resource-path-specifier",
            "Condition": {
                "StringEquals": {
                    "aws:SourceArn": [
                        "<SourceStateMachineArn>"
                    ]
                }
            }
        }
    ]
}
```

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

# Step Functions を使用してAWS Batchワークロードを実行する
<a name="connect-batch"></a>

Step Functions を と統合AWS Batchして、AWSクラウドでバッチコンピューティングワークロードを実行できます。このページでは、サポートされている AWS Batch API を一覧表示し、バッチ処理タスクを実行するための `Task` 状態の例を示します。

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

**最適化AWS Batch統合の主な機能**  
[ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) 統合パターンが利用可能です。
[レスポンスのリクエスト](connect-to-resource.md#connect-default) または [タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token) 統合パターンに固有の最適化はないことに注意してください。

AWS Batchジョブを送信し、完了するまで待機する`Task`状態の例を次に示します。ここで示している引数の多くはオプションです。

```
"Submit Batch Job": {
    "Type": "Task",
    "Resource": "arn:aws:states:::batch:submitJob.sync",
    "Arguments": {
        "JobName": "BATCH_NAME",
        "JobQueue": "BATCH_QUEUE_ARN",
        "JobDefinition": "BATCH_JOB_DEFINITION_ARN",
        "ArrayProperties": {
        "Size": 10
        },
        "ContainerOverrides": {
        "ResourceRequirements": [
            {
            "Type": "VCPU",
            "Value": "4"
            }
        ]
        },
        "DependsOn": [
        {
            "JobId": "myJobId",
            "Type": "SEQUENTIAL"
        }
        ],
        "PropagateTags": true,
        "Arguments": {
        "Key1": "value1",
        "Key2": 100
        },
        "RetryStrategy": {
        "Attempts": 1
        },
        "Tags": {
        "Tag": "TAG"
        },
        "Timeout": {
        "AttemptDurationSeconds": 10
        }
    }
}
```

## AWS BatchAPIs
<a name="connect-batch-api"></a>
+ [https://docs.aws.amazon.com/batch/latest/APIReference/API_SubmitJob.html](https://docs.aws.amazon.com/batch/latest/APIReference/API_SubmitJob.html)

**Step Functions のパラメータは PascalCase で表されます。**  
ネイティブサービス API が、API アクション `startSyncExecution` などの camelCase である場合でも、`StateMachineArn` などの PascalCase でパラメータを指定します。

## を呼び出すための IAM ポリシーAWS Batch
<a name="batch-iam"></a>

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

`SubmitJob` および `TerminateJob` のジョブ ID は実行時に生成されるため、特定のリソースに基づいてアクセスを制限するポリシーを作成することはできません。

**きめ細かなアクセスコントロールのためのヒント**  
`SubmitJob` と `TerminateJob` に対するきめ細かなアクセスコントロールを追加するには、ジョブにタグを付け、そのタグに基づいてアクセスを制限するポリシーを作成することを検討してください。さらに、`SubmitJob` に対しては、既知のリソースを使用してジョブキュー、定義、消費可能なリソースを制限できます。

------
#### [ Run a Job (.sync) ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "batch:SubmitJob",
                "batch:DescribeJobs",
                "batch:TerminateJob"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
               "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForBatchJobsRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "batch:SubmitJob"
            ],
            "Resource": "*"
        }
    ]
}
```

------

# Step Functions を使用した Amazon Bedrock モデルの呼び出しとカスタマイズ
<a name="connect-bedrock"></a>

Step Functions を Amazon Bedrock と統合すると、指定された Amazon Bedrock モデルを呼び出し、モデルをカスタマイズするためのファインチューニングジョブを作成できます。このページでは、最適化された Amazon Bedrock API のリストと、モデル呼び出しの結果を抽出する `Task` ステートの例を示しています。

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

**ヒント**  
Amazon Bedrock と統合するワークフローの例をデプロイするには、「[Amazon Bedrock で AI プロンプトチェイニングを実行する](sample-bedrock-prompt-chaining.md)」を参照してください。

## Amazon Bedrock サービス統合 API
<a name="connect-bedrock-custom-apis"></a>

AWS Step Functions を Amazon Bedrock と統合するために、以下の API を使用できます。これらの API は対応する Amazon Bedrock API に似ていますが、*InvokeModel* には追加のリクエストフィールドがあります。

**Amazon Bedrock API - [CreateModelCustomizationJob](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelCustomizationJob.html)**  
ベースモデルをカスタマイズするためのファインチューニングジョブを作成します。Step Functions 統合 API を **CreateModelCustomizationJob** *(Request Response 向け)* または **CreateModelCustomizationJob.sync** *(ジョブの実行 (.sync) 向け)* 統合パターンで呼び出すことができます。API コールのフィールドには違いはありません。

**Amazon Bedrock API - [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)**  
リクエスト本文に指定された入力を使って推論を実行するために、指定された Amazon Bedrock モデルを呼び出します。テキストモデル、画像モデル、埋め込みモデルの推論を実行するために、`InvokeModel` を使用します。

*InvokeModel* 向けの Amazon Bedrock サービス統合 API のリクエスト本文には、以下の追加パラメータが含まれます。
+ `Body` — コンテンツタイプのリクエストヘッダーで指定された形式で入力データを指定します。`Body` には、ターゲットモデル固有のパラメータが含まれます。

  `InvokeModel` API を使用する場合は、`Body` パラメータを指定する必要があります。Step Functions では、`Body` で入力した内容は検証されません。

  Amazon Bedrock 最適化統合を使用して `Body` を指定する場合、最大 256 KiB のペイロードを指定できます。ペイロードが 256 KiB を超える場合は、`Input` を使用することをお勧めします。
+ `Input` — 入力データを取得するソースを指定します。このオプションフィールドは、Step Functions に最適化された Amazon Bedrock 統合に固有のものです。このフィールドでは、`S3Uri` を指定できます。

  パラメータ または `Input` に `Body` を指定できますが、両方に指定することはできません。

  `ContentType` を指定せずに `Input` を指定すると、入力データソースのコンテンツタイプが `ContentType` の値になります。
+ `Output` — API レスポンスの記述先を指定します。このオプションフィールドは、Step Functions に最適化された Amazon Bedrock 統合に固有のものです。このフィールドでは、`S3Uri` を指定できます。

  このフィールドを指定すると、API レスポンス本文は元の出力の Amazon S3 ロケーションへの参照に置き換えられます。

次の例は、Amazon Bedrock 統合用の InvokeModel API の構文を示しています。

```
{
    "ModelId": String,  // required
    "Accept": String,  // default: application/json
    "ContentType": String,  // default: application/json
    "Input": {  // not from Bedrock API
        "S3Uri": String
    },  
    "Output": {  // not from Bedrock API
        "S3Uri": String
    } 
}
```

## Amazon Bedrock 統合のタスクステート定義
<a name="connect-bedrock-task-definition"></a>

以下のタスクステート定義は、ステートマシンで Amazon Bedrock とどのように統合できるかを示しています。この例は、パス (`result_one`) で指定されたモデル呼び出しの結果をすべて抽出するタスクステートを示しています。これは[基盤モデルの推論パラメータ](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html)に基づいています。この例では、Cohere Command 大規模言語モデル (LLM) を使用しています。

```
{
  "Type": "Task",
  "Resource": "arn:aws:states:::bedrock:invokeModel",
  "Arguments": {
    "ModelId": "cohere.command-text-v14",
    "Body": {
      "prompt": "{% states.input.prompt_one %}",
      "max_tokens": 20
    },
    "ContentType": "application/json",
    "Accept": "*/*"
  },
  "End": true
}
```

## IAM policies for calling Amazon Bedrock
<a name="bedrock-iam"></a>

コンソールを使用してステートマシンを作成すると、必要な最小特権を持つステートマシンの実行ロールがStep Functions によって自動的に作成されます。これらの自動生成されたIAMロールは、ステートマシンを作成する AWS リージョンで有効です。

IAM ポリシーを作成するときは、ポリシーにワイルドカードを含めないことをお勧めします。セキュリティのベストプラクティスとして、ポリシーの範囲をできるだけ絞り込む必要があります。動的ポリシーは、ランタイム中に特定の入力パラメータが不明な場合にのみ使用してください。

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

### Amazon Bedrock 統合の IAM ポリシー例
<a name="bedrock-iam-policy-eg"></a>

次のセクションでは、特定の基盤モデルまたはプロビジョニングされたモデルに使用する Amazon Bedrock API に基づいて必要な IAM アクセス許可について説明します。このセクションには、フルアクセスを許可するポリシーの例も含まれています。

*イタリック体*のテキストを、リソース固有の情報に必ず置き換えてください。
+ [InvokeModel を使用して特定の基盤モデルにアクセスする IAM ポリシーの例](#bedrock-policy-invoke-foundation-model)
+ [InvokeModel を使用して特定のプロビジョニング済みモデルにアクセスする IAM ポリシーの例](#bedrock-policy-invoke-provisioned-model)
+ [InvokeModel を使用するフルアクセス IAM ポリシーの例](#bedrock-policy-invokemodel-full-access)
+ [特定の基盤モデルに基本モデルとしてアクセスする IAM ポリシーの例](#bedrock-policy-foundation-model)
+ [特定のカスタムモデルに基本モデルとしてアクセスする IAM ポリシーの例](#bedrock-policy-custom-model)
+ [CreateModelCustomizationJob.sync を使用するフルアクセス IAM ポリシーの例](#bedrock-policy-createmodel-full-access)
+ [CreateModelCustomizationJob.sync を使用して特定の基盤モデルにアクセスする IAM ポリシーの例](#bedrock-policy-createmodel-sync-foundation-model)
+ [CreateModelCustomizationJob.sync を使用してカスタムモデルにアクセスする IAM ポリシーの例](#bedrock-policy-createmodel-sync-custom-model)
+ [CreateModelCustomizationJob.sync を使用するフルアクセス IAM ポリシーの例](#bedrock-policy-createmodel-sync-full-access)

#### InvokeModel を使用して特定の基盤モデルにアクセスする IAM ポリシーの例
<a name="bedrock-policy-invoke-foundation-model"></a>

以下は、[InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) API アクションを使用して指定された特定の基盤モデル `amazon.titan-text-express-v1` にアクセスするステートマシンの IAM ポリシーの例です。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "InvokeModel1",
            "Action": [
                "bedrock:InvokeModel"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-text-express-v1"
            ]
        }
    ]
}
```

#### InvokeModel を使用して特定のプロビジョニング済みモデルにアクセスする IAM ポリシーの例
<a name="bedrock-policy-invoke-provisioned-model"></a>

以下は、[InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) API アクションを使用して指定された特定のプロビジョニング済みモデル `c2oi931ulksx` にアクセスするステートマシンの IAM ポリシーの例です。

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Sid": "InvokeModel1",
      "Action": [
        "bedrock:InvokeModel"
      ],
      "Resource": [
        "arn:aws:bedrock:us-east-1:123456789012:provisioned-model/c2oi931ulksx"
      ]
    }
  ]
}
```

#### InvokeModel を使用するフルアクセス IAM ポリシーの例
<a name="bedrock-policy-invokemodel-full-access"></a>

以下は、[InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) API アクションを使用するときにフルアクセスを提供するステートマシンの IAM ポリシーの例です。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "InvokeModel1",
            "Action": [
                "bedrock:InvokeModel"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1::foundation-model/*",
                "arn:aws:bedrock:us-east-1:123456789012:provisioned-model/*"
            ]
        }
    ]
}
```

#### 特定の基盤モデルに基本モデルとしてアクセスする IAM ポリシーの例
<a name="bedrock-policy-foundation-model"></a>

以下は、[CreateModelCustomizationJob](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelCustomizationJob.html) API アクションを使用して、ベースモデルとして指定された特定の基盤モデル `amazon.titan-text-express-v1` にステートマシンがアクセスするための IAM ポリシーの例です。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob1",
            "Action": [
                "bedrock:CreateModelCustomizationJob"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-text-express-v1",
                "arn:aws:bedrock:us-east-1:123456789012:custom-model/*",
                "arn:aws:bedrock:us-east-1:123456789012:model-customization-job/*"
            ]
        },
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob2",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "arn:aws:iam::123456789012:role/myRole"            
            ]
        }
    ] 
}
```

#### 特定のカスタムモデルに基本モデルとしてアクセスする IAM ポリシーの例
<a name="bedrock-policy-custom-model"></a>

以下は、[CreateModelCustomizationJob](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelCustomizationJob.html) API アクションを使用して特定のカスタムモデルに基本モデルとしてアクセスするステートマシンの IAM ポリシーの例です。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob1",
            "Action": [
                "bedrock:CreateModelCustomizationJob"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1:123456789012:custom-model/*",
                "arn:aws:bedrock:us-east-1:123456789012:model-customization-job/*"
            ]
        },
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob2",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "arn:aws:iam::123456789012:role/myRoleName"            
            ]
        }
    ] 
}
```

#### CreateModelCustomizationJob.sync を使用するフルアクセス IAM ポリシーの例
<a name="bedrock-policy-createmodel-full-access"></a>

[CreateModelCustomizationJob](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelCustomizationJob.html) API アクションを使用するときに、フルアクセスを提供するステートマシンの IAM ポリシー例を以下に示します。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob1",
            "Action": [
                "bedrock:CreateModelCustomizationJob"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1::foundation-model/*",
                "arn:aws:bedrock:us-east-1:123456789012:custom-model/*",
                "arn:aws:bedrock:us-east-1:123456789012:model-customization-job/*"
            ]
        },
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob2",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "arn:aws:iam::123456789012:role/myRole"            
            ]
        }
    ] 
}
```

#### CreateModelCustomizationJob.sync を使用して特定の基盤モデルにアクセスする IAM ポリシーの例
<a name="bedrock-policy-createmodel-sync-foundation-model"></a>

以下は、[CreateModelCustomizationJob.sync](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelCustomizationJob.html) API アクションを使用して指定された特定の基盤モデル `amazon.titan-text-express-v1` にアクセスするステートマシン用の IAM ポリシーの例です。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob1",
            "Action": [
                "bedrock:CreateModelCustomizationJob"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-text-express-v1",
                "arn:aws:bedrock:us-east-1:123456789012:custom-model/*",
                "arn:aws:bedrock:us-east-1:123456789012:model-customization-job/*"
            ]
        },
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob2",
            "Action": [
                "bedrock:GetModelCustomizationJob",
                "bedrock:StopModelCustomizationJob"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1:123456789012:model-customization-job/*"
            ]
        },
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob3",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "arn:aws:iam::123456789012:role/myRole"            
            ]
        }
    ]
}
```

#### CreateModelCustomizationJob.sync を使用してカスタムモデルにアクセスする IAM ポリシーの例
<a name="bedrock-policy-createmodel-sync-custom-model"></a>

以下は、[CreateModelCustomizationJob.sync](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelCustomizationJob.html) API アクションを使用してカスタムモデルにアクセスするステートマシン用の IAM ポリシーの例です。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob1",
            "Action": [
                "bedrock:CreateModelCustomizationJob"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1:123456789012:custom-model/*",
                "arn:aws:bedrock:us-east-1:123456789012:model-customization-job/*"
            ]
        },
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob2",
            "Action": [
                "bedrock:GetModelCustomizationJob",
                "bedrock:StopModelCustomizationJob"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1:123456789012:model-customization-job/*"
            ]
        },
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob3",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "arn:aws:iam::123456789012:role/myRole"            
            ]
        }
    ]
}
```

#### CreateModelCustomizationJob.sync を使用するフルアクセス IAM ポリシーの例
<a name="bedrock-policy-createmodel-sync-full-access"></a>

[CreateModelCustomizationJob.sync](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelCustomizationJob.html) API アクションを使用するときに、フルアクセスを提供するステートマシンの IAM ポリシー例を以下に示します。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob1",
            "Action": [
                "bedrock:CreateModelCustomizationJob"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1::foundation-model/*",
                "arn:aws:bedrock:us-east-1:123456789012:custom-model/*",
                "arn:aws:bedrock:us-east-1:123456789012:model-customization-job/*"
            ]
        },
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob2",
            "Action": [
                "bedrock:GetModelCustomizationJob",
                "bedrock:StopModelCustomizationJob"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1:123456789012:model-customization-job/*"
            ]
        },
        {
            "Effect": "Allow",
            "Sid": "CreateModelCustomizationJob3",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "arn:aws:iam::123456789012:role/myRole"            
            ]
        }
    ]
}
```

# Step Functions を使用して AWS CodeBuild ビルドを管理する
<a name="connect-codebuild"></a>

Step Functions を と統合 AWS CodeBuild して、ビルドを開始、停止、管理できます。このページには、Step Functions で使用できるサポートされている CodeBuild API が一覧表示されています。

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

Step Functions と の統合 AWS CodeBuild により、Step Functions を使用してビルドをトリガー、停止、管理し、ビルドレポートを共有できます。Step Functions を使用すると、アプリケーションのソフトウェア変更を検証するための継続的統合パイプラインを設計および実行できます。

**最適化された CodeBuild 統合の主な機能**  
[ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) 統合パターンがサポートされています。
`StopBuild` または `StopBuildBatch` を呼び出した後、単複かかわらず構築のバッチは、構築の状態を確定するために CodeBuild 内で内部作業が完了するまで、すぐに削除されません。  
この期間中に `BatchDeleteBuilds` または `DeleteBuildBatch` を使おうとすると、構築または構築バッチは削除されない場合があります。  
`BatchDeleteBuilds` と `DeleteBuildBatch` のために最適化されたサービス統合には、内部再試行が含まれており、停止直後に削除するというユースケースを簡素化します。

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


| API | レスポンスのリクエスト | ジョブの実行 (.sync) | 
| --- | --- | --- | 
| StartBuild | サポート対象 | サポート | 
| StopBuild | サポート | サポートされません | 
| BatchDeleteBuilds | サポート | サポートされません | 
| BatchGetReports | サポート | サポートされません | 
| StartBuildBatch | サポート対象 | サポート | 
| StopBuildBatch | サポート | サポートされません | 
| RetryBuildBatch | サポート対象 | サポート | 
| DeleteBuildBatch | サポート | サポートされません | 

**Step Functions のパラメータは PascalCase で表されます。**  
ネイティブサービス API が、API アクション `startSyncExecution` などの camelCase である場合でも、`StateMachineArn` などの PascalCase でパラメータを指定します。

## 最適化された CodeBuild API
<a name="connect-codebuild-api"></a>
+ [https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuild.html#API_StartBuild_RequestSyntax](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuild.html#API_StartBuild_RequestSyntax)
+ [https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StopBuild.html](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StopBuild.html)
+ [https://docs.aws.amazon.com/codebuild/latest/APIReference/API_BatchDeleteBuilds.html](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_BatchDeleteBuilds.html)
+ [https://docs.aws.amazon.com/codebuild/latest/APIReference/API_BatchGetReports.html](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_BatchGetReports.html)
+ [https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuildBatch.html](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuildBatch.html)
+ [https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StopBuildBatch.html](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StopBuildBatch.html)
+ [https://docs.aws.amazon.com/codebuild/latest/APIReference/API_RetryBuildBatch.html](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_RetryBuildBatch.html)
+ [https://docs.aws.amazon.com/codebuild/latest/APIReference/API_DeleteBuildBatch.html](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_DeleteBuildBatch.html)

**注記**  
JSONPath を使用する場合は、再帰降下演算子 (`..`) を使用して `BatchDeleteBuilds` にパラメータを指定できます。配列が返されることで、次の例に示すように、`Arn` フィールドを `StartBuild` から複数形の `Ids` パラメータに変換できます。  

```
"BatchDeleteBuilds": {
    "Type": "Task",
    "Resource": "arn:aws:states:::codebuild:batchDeleteBuilds",
    "Arguments": {
        "Ids.$": "$.Build..Arn"
    },
    "Next": "MyNextState"
},
```

## を呼び出すための IAM ポリシー AWS CodeBuild
<a name="codebuild-iam"></a>

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

*リソース*:

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Action": [
                "sns:Publish"
            ],
            "Resource": [
                "arn:aws:sns:us-east-1:123456789012:StepFunctionsSample-CodeBuildExecution1111-2222-3333-wJalrXUtnFEMI-SNSTopic-bPxRfiCYEXAMPLEKEY"
            ],
            "Effect": "Allow"
        },
        {
            "Action": [
                "codebuild:StartBuild",
                "codebuild:StopBuild",
                "codebuild:BatchGetBuilds",
                "codebuild:BatchGetReports"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventForCodeBuildStartBuildRule"
            ],
            "Effect": "Allow"
        }
    ]
}
```

### `StartBuild`
<a name="codebuild-iam-startbuild"></a>

静的リソース**

------
#### [ Run a Job (.sync) ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:StartBuild",
        "codebuild:StopBuild",
        "codebuild:BatchGetBuilds"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "events:PutTargets",
        "events:PutRule",
        "events:DescribeRule"
      ],
      "Resource": [
        "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventForCodeBuildStartBuildRule"
      ]
    }
  ]
}
```

------
#### [ Request Response ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:StartBuild"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
      ]
    }
  ]
}
```

------

動的リソース**

------
#### [ Run a Job (.sync) ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:StartBuild",
        "codebuild:StopBuild",
        "codebuild:BatchGetBuilds"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:*:project/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "events:PutTargets",
        "events:PutRule",
        "events:DescribeRule"
      ],
      "Resource": [
        "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventForCodeBuildStartBuildRule"
      ]
    }
  ]
}
```

------
#### [ Request Response ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:StartBuild"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:*:project/*"
      ]
    }
  ]
}
```

------

### `StopBuild`
<a name="codebuild-iam-stopbuild"></a>

静的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:StopBuild"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
      ]
    }
  ]
}
```

動的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:StopBuild"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:*:project/*"
      ]
    }
  ]
}
```

### `BatchDeleteBuilds`
<a name="codebuild-iam-batchdeletebuilds"></a>

静的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:BatchDeleteBuilds"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
      ]
    }
  ]
}
```

動的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:BatchDeleteBuilds"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:*:project/*"
      ]
    }
  ]
}
```

### `BatchGetReports`
<a name="codebuild-iam-batchgetreports"></a>

静的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:BatchGetReports"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:123456789012:report-group/myReportName"
      ]
    }
  ]
}
```

動的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "codebuild:BatchGetReports"
      ],
      "Resource": [
        "arn:aws:codebuild:us-east-1:*:report-group/*"
      ]
    }
  ]
}
```

### `StartBuildBatch`
<a name="codebuild-iam-startbuildbatch"></a>

静的リソース**

------
#### [ Run a Job (.sync) ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codebuild:StartBuildBatch",
                "codebuild:StopBuildBatch",
                "codebuild:BatchGetBuildBatches"
            ],
            "Resource": [
                "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventForCodeBuildStartBuildBatchRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codebuild:StartBuildBatch"
            ],
            "Resource": [
                "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
            ]
        }
    ]
}
```

------

動的リソース**

------
#### [ Run a Job (.sync) ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codebuild:StartBuildBatch",
                "codebuild:StopBuildBatch",
                "codebuild:BatchGetBuildBatches"
            ],
            "Resource": [
                "arn:aws:codebuild:us-east-1:123456789012:project/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventForCodeBuildStartBuildBatchRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

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

------

### `StopBuildBatch`
<a name="codebuild-iam-stopbuildbatch"></a>

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codebuild:StopBuildBatch"
            ],
            "Resource": [
                "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
            ]
        }
    ]
}
```

動的リソース**

****  

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

### `RetryBuildBatch`
<a name="codebuild-iam-retrybuildbatch"></a>

静的リソース**

------
#### [ Run a Job (.sync) ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codebuild:RetryBuildBatch",
                "codebuild:StopBuildBatch",
                "codebuild:BatchGetBuildBatches"
            ],
            "Resource": [
                "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codebuild:RetryBuildBatch"
            ],
            "Resource": [
                "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
            ]
        }
    ]
}
```

------

動的リソース**

------
#### [ Run a Job (.sync) ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codebuild:RetryBuildBatch",
                "codebuild:StopBuildBatch",
                "codebuild:BatchGetBuildBatches"
            ],
            "Resource": [
                "arn:aws:codebuild:us-east-1:123456789012:project/*"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

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

------

### `DeleteBuildBatch`
<a name="codebuild-iam-deletebuildbatch"></a>

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codebuild:DeleteBuildBatch"
            ],
            "Resource": [
                "arn:aws:codebuild:us-east-1:123456789012:project/myProjectName"
            ]
        }
    ]
}
```

動的リソース**

****  

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

# Step Functions を使用して DynamoDB CRUD オペレーションを実行する
<a name="connect-ddb"></a>

Step Functions を DynamoDB と統合すると、DynamoDB テーブルで CRUD オペレーションを実行できます。このページでは、サポートされている DynamoDB API を一覧表示し、DynamoDB から項目を取得するための `Task` 状態の例を示します。

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

**最適化された DynamoDB 統合の主な機能**  
[レスポンスのリクエスト](connect-to-resource.md#connect-default) 統合パターンに固有の最適化はありません。
[タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token) 統合パターンはサポートされていません。
最適化された統合では、[https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html)、[https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html)、[https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html)、および [https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html) API アクションのみを使用できます。などの他の API アクション[https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html)は、DynamoDBAWS SDK 統合を使用して使用できます。

次に示しているのは、DynamoDB からメッセージを取得する `Task` ステートの例です。

```
"Read next Message from DynamoDB": {
    "Type": "Task",
    "Resource": "arn:aws:states:::dynamodb:getItem",
    "Arguments": {
        "TableName": "DYNAMO_DB_TABLE_NAME",
        "Key": {
            "MessageId": {"S": "{% $List[0] %}"}
        }
    }
```

実際の例でこのステートを確認するには、[Lambda、DynamoDB、および Amazon SQS を使用してデータレコードを転送する](sample-project-transfer-data-sqs.md) スターターテンプレートを参照してください。

**例外プレフィックスの違い**  
標準の DynamoDB 接続でエラーが発生した場合、例外プレフィックスは `DynamoDb` (大文字と小文字の混在) になります。  
最適化統合の場合、例外プレフィックスは `DynamoDB` (すべて大文字の `DB`) になります。

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

## 最適化された DynamoDB API
<a name="connect-dynamodb-api"></a>
+ [https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html)
+ [https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html)
+ [https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html)
+ [https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html)

**Step Functions のパラメータは PascalCase で表されます。**  
ネイティブサービス API が、API アクション `startSyncExecution` などの camelCase である場合でも、`StateMachineArn` などの PascalCase でパラメータを指定します。

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

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

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:GetItem",
                "dynamodb:PutItem",
                "dynamodb:UpdateItem",
                "dynamodb:DeleteItem"
            ],
            "Resource": [
                "arn:aws:dynamodb:us-east-1:123456789012:table/myTableName"
            ]
        }
    ]
}
```

動的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:GetItem",
                "dynamodb:PutItem",
                "dynamodb:UpdateItem",
                "dynamodb:DeleteItem"
            ],
            "Resource": "*"
        }
    ]
}
```

すべての DynamoDB API アクションの IAM ポリシーの詳細については、「*Amazon DynamoDB デベロッパーガイド*」の「[DynamoDB での IAM ポリシー](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/using-identity-based-policies.html)」を参照してください。さらに、DynamoDB 用 PartiQL の IAM ポリシーについては、「*Amazon DynamoDB DynamoDB デベロッパーガイド*」の「[DynamoDB 用 PartiQL の IAM ポリシー](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-iam.html)」を参照してください。

# Step Functions で Amazon ECS または Fargate タスクを実行する
<a name="connect-ecs"></a>

Step Functions を Amazon ECS または Fargate と統合してタスクを実行および管理する方法を説明します。Amazon ECS では、タスクは計算の基本的な単位です。タスクは、コンテナイメージ、CPU とメモリの制限、ネットワーク設定、その他のパラメータなど、Docker コンテナの実行方法を指定するタスク定義によって定義されます。このページでは、使用可能な Amazon ECS API アクションが一覧表示され、Step Functions を使用して Amazon ECS タスクにデータを渡す方法に関する手順が提供されます。

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

**最適化された Amazon ECS/Fargate 統合の主な機能**  
[ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) 統合パターンがサポートされています。
`ecs:runTask` は、HTTP 200 のレスポンスを返すことができますが、次のように、空でない `Failures` フィールドがあります。  
**リクエストレスポンス**: レスポンスを返し、タスクは失敗しません。これは、非最適化統合と同じです。
**[ジョブを実行する]**: 空でない `Failures` フィールドが検出された場合、`AmazonECS.Unknown` エラーが発生し、タスクは失敗します。

## 最適化された Amazon ECS/Fargate API
<a name="connect-ecs-api"></a>
+ [https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html) は、指定されたタスク定義を使用して新しいタスクを開始します。

**Step Functions のパラメータは PascalCase で表されます。**  
ネイティブサービス API が、API アクション `startSyncExecution` などの camelCase である場合でも、`StateMachineArn` などの PascalCase でパラメータを指定します。

## Amazon ECS タスクにデータを渡す
<a name="connect-ecs-pass-to"></a>

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

`overrides` を使用することで、コンテナのデフォルトコマンドを上書きし、入力を Amazon ECS タスクに渡すことができます。[https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerOverride.html](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerOverride.html) を参照してください。この例では、JsonPath を使用して、入力の `Task` の値を `Task` 状態に渡します。

以下には、Amazon ECS タスクを実行し、完了するまで待機する `Task` 状態が含まれます。

```
{
 "StartAt": "Run an ECS Task and wait for it to complete",
 "States": {
   "Run an ECS Task and wait for it to complete": {
     "Type": "Task",
     "Resource": "arn:aws:states:::ecs:runTask.sync",
     "Arguments": {
                "Cluster": "cluster-arn",
                "TaskDefinition": "job-id",
                "Overrides": {
                    "ContainerOverrides": [
                        {
                            "Name": "container-name",
                            "Command": "{% $state.input.commands %}" 
                        }
                    ]
                }
            },
     "End": true
    }
  }
}
```

`ContainerOverrides` の `Command` 行は状態の入力からコンテナにコマンドを渡します。​

前述のステートマシンの例では、次の入力が与えられた場合、各コマンドはコンテナのオーバーライドとして渡されます。

```
{
  "commands": [
    "test command 1",
    "test command 2",
    "test command 3"
  ]
}
```

以下には Amazon ECS タスクを実行する `Task` 状態が含まれ、その後タスクトークンが返されるまで待機します。「[タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token)」を参照してください。

```
{  
   "StartAt":"Manage ECS task",
   "States":{  
      "Manage ECS task":{  
         "Type":"Task",
         "Resource":"arn:aws:states:::ecs:runTask.waitForTaskToken",
         "Arguments":{  
            "LaunchType":"FARGATE",
            "Cluster":"cluster-arn",
            "TaskDefinition":"job-id",
            "Overrides":{  
               "ContainerOverrides":[  
                  {  
                     "Name":"container-name",
                     "Environment":[  
                        {  
                           "Name" : "TASK_TOKEN_ENV_VARIABLE",
                           "Value" : "{% $states.context.Task.Token %}"
                        }
                     ]
                  }
               ]
            }
         },
         "End":true
      }
   }
}
```

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

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

`TaskId` の値は、タスクが送信されるまで不明なため、Step Functions は、権限の高い `"Resource": "*"` ポリシーを作成します。

**注記**  
`"*"` IAM ポリシーにもかかわらず、Step Functions によってスタートした Amazon Elastic Container Service (Amazon ECS) タスクを停止できるだけです。

------
#### [ Run a Job (.sync) ]

静的リソース**

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ecs:RunTask"
            ],
            "Resource": [
                "arn:aws:ecs:region:
account-id:task-definition/taskDefinition:revisionNumber"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "ecs:StopTask",
                "ecs:DescribeTasks"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
               "arn:aws:events:region:
account-id:rule/StepFunctionsGetEventsForECSTaskRule"
            ]
        }
    ]
}
```

動的リソース**

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ecs:RunTask",
                "ecs:StopTask",
                "ecs:DescribeTasks"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
               "arn:aws:events:region:
account-id:rule/StepFunctionsGetEventsForECSTaskRule"
            ]
        }
    ]
}
```

------
#### [ Request Response and Callback (.waitForTaskToken) ]

静的リソース**

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ecs:RunTask"
            ],
            "Resource": [
                "arn:aws:ecs:region:
account-id:task-definition/taskDefinition:revisionNumber"
            ]
        }
    ]
}
```

動的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ecs:RunTask"
            ],
            "Resource": "*"
        }
    ]
}
```

------

スケジュールされた Amazon ECS タスクでタスク実行ロールの使用、タスクロール、またはタスクロールの上書きが必要な場合、タスク実行ロール、タスクロール、またはタスクロール上書きごとに `iam:PassRole` アクセス許可を、呼び出すエンティティ、この場合は Step Functions の CloudWatch Events IAM ロールに追加する必要があります。

# Step Functions を使用した Amazon EKS クラスターの作成と管理
<a name="connect-eks"></a>

Step Functions を Amazon EKS と統合して Kubernetes クラスターを管理する方法について説明します。Step Functions は、Amazon Elastic Kubernetes Service と統合するため、2 種類のサービス統合 API を提供します。1 種類では、Amazon EKS API を使用して Amazon EKS クラスターを作成および管理できます。もう一方では、Kubernetes API を使用してクラスターと対話し、アプリケーションのワークフローの一部としてジョブを実行できるようにします。

 **eksctl** ツールまたは [Amazon EKS コンソール](https://console.aws.amazon.com/eks/home)、または同様の方法によって作成した Amazon EKS クラスターで Step Functions を使って作成した Amazon EKS クラスターとの Kubernetes API 統合を使用できます。詳細については、Amazon EKS ユーザーガイドの [Amazon EKS クラスターを作成](https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html)を参照してください。

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

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

**注記**  
Step Functions EKS 統合は、公開エンドポイントにアクセスできる Kubernetes API だけをサポートします。デフォルトでは、EKS クラスター API サーバーエンドポイントはパブリックアクセスが可能です。詳細については、「**Amazon EKS ユーザーガイド**」の 「[Amazon EKS クラスターエンドポイントアクセスコントロール](https://docs.aws.amazon.com/eks/latest/userguide/cluster-endpoint.html)」を参照してください。

Step Functions は、実行が停止しても、Amazon EKS クラスターを自動的に終了しません。Amazon EKS クラスターが終了する前にステートマシンが停止した場合、クラスターは無期限に実行され、追加料金が発生する可能性があります。これを回避するには、作成した Amazon EKS クラスターが正しく終了するようにしてください。詳細については、以下を参照してください。
+ Amazon EKS ユーザーガイドの[クラスターを削除](https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html)。
+ サービス統合パターンの [ジョブの実行 (.sync)](connect-to-resource.md#connect-sync)。

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

## Kubernetes API 統合
<a name="connect-eks-kubernetes-apis"></a>

Step Functions は、次の Kubernetes API をサポートしています。

### RunJob
<a name="connect-eks-kubernetes-apis-runjob"></a>

`eks:runJob` サービス統合によって、Amazon EKS クラスターでのジョブ実行が許可されます。`eks:runJob.sync` バリアントによって、ジョブの完了までの待機とオプションでのログ取得が許可されます。

Kubernetes API サーバーは、ステートマシンで使用される IAM ロールにアクセス権限を付与する必要があります。詳細については、「[アクセス許可](#connect-eks-permissions)」を参照してください。

**ジョブを実行する** (`.sync`) パターンの場合、ジョブの状態はポーリングによって決定されます。Step Functions は、最初は 1 分あたり約 1 ポーリングの割合でポーリングします。このレートは低速になり、最終的には 5 分ごとに約 1 ポーリングとなります。ポーリングの頻度を増やす必要がある場合、またはこれまでよりもポーリング戦略の制御を行う必要がある場合は、`eks:call` 統合を使って、ジョブの状態のクエリを出すことができます。

`eks:runJob` 統合は、`batch/v1` Kubernetes ジョブ固有のものです。詳細については、Kubernetes ドキュメントの[ジョブ](https://kubernetes.io/docs/concepts/workloads/controllers/job/)を参照してください。カスタムリソースを含む他の Kubernetes リソースを管理する場合は、`eks:call` サービス統合を使用します。[Lambda および AWS Batch でのジョブステータスのポーリング](sample-project-job-poller.md) サンプルプロジェクトで示すように、Step Functions を使用してポーリングループを構築できます。

サポートされるパラメータには次のものが含まれます。
+ `ClusterName`: コールしたい Amazon EKS クラスター名。
  + `Type`: `String`
  + 必須: はい
+ `CertificateAuthority`: ご自分のクラスターとの通信に必要な Base64 でエンコードされた証明書データ。この値は、[Amazon EKS コンソール](https://console.aws.amazon.com/eks/home)から、または Amazon EKS [DescribeCluster](https://docs.aws.amazon.com/eks/latest/APIReference/API_DescribeCluster.html) API を使用して取得できます。
  + `Type`: `String`
  + 必須: はい
+ `Endpoint`: Kubernetes API サーバーのエンドポイント。この値は、[Amazon EKS コンソール](https://console.aws.amazon.com/eks/home)から、または Amazon EKS [DescribeCluster](https://docs.aws.amazon.com/eks/latest/APIReference/API_DescribeCluster.html) API を使用して取得できます。
  + `Type`: `String`
  + 必須: はい
+ `Namespace`: ジョブを実行する名前空間。提供されない場合は、名前空間 `default` が用いられる。
  + `Type`: `String`
  + 必須: いいえ
+ `Job`: Kubernetes Job の定義。Kubernetes ドキュメントの[ジョブ](https://kubernetes.io/docs/concepts/workloads/controllers/job/)を参照してください。
  + `Type`: `JSON` または `String`
  + 必須: はい
+ `LogOptions`: ログのオプションの取得を制御するオプションのセット。[Run a Job] (ジョブの実行) (.sync) サービス統合パターンを使用してジョブの完了を待機するために使われるのが唯一適切です。
  + `Type`: `JSON`
  + 必須: いいえ
  + ログはキー `logs` の下のレスポンスに含まれます。ジョブ内には複数のポッドがあり、それぞれに複数のコンテナがあります。

    ```
    { 
      ...
      "logs": { 
        "pods": { 
          "pod1": { 
            "containers": { 
              "container1": { 
                "log": <log> 
              },
              ...
            }
          },
          ...
        }
      }
    ```
  + ログの取得は、ベストエフォートベースで実行されます。ログの取得エラーが発生した場合は、`log` フィールドの代わりに、`error` および `cause` フィールドが存在します。
+ `LogOptions.RetrieveLogs`: ジョブの完了後にログの取得を有効にします。デフォルトでは、ログは取得されません。
  + `Type`: `Boolean`
  + 必須: いいえ
+ `LogOptions.RawLogs`: `RawLogs` が true に設定されている場合、ログは JSON に解析しようとせずに生文字列として返されます。デフォルトでは、可能であれば、ログは JSON に逆シリアル化されます。場合によっては、このような解析によって、多くの桁数を含む数値の精度を制限するなど、望ましくない変更を導入しかねません。
  + `Type`: `Boolean`
  + 必須: いいえ
+ `LogOptions.LogParameters`: Kubernetes API のログ読み取り API は、ログの取得を制御するクエリパラメータをサポートしています。例えば、`tailLines` または `limitBytes` を使用して、取得したログのサイズを制限し、Step Functions のデータサイズクォータ内に留まります。詳細については、SDK for Go API リファレンスの[ログを読み取り](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#read-log-pod-v1-core)セクションを参照してください。
  + `List of Strings` への `String` の `Type: ` マッピング
  + 必須: いいえ
  + 例:

    ```
    "LogParameters": {
      "tailLines": [ "6" ]
    }
    ```

次の例には、ジョブを実行し、完了を待ってから、ジョブのログを取得する `Task` 状態が含まれます。

```
{
  "StartAt": "Run a job on EKS",
  "States": {
    "Run a job on EKS": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:runJob.sync",
      "Arguments": {
        "ClusterName": "MyCluster",
        "CertificateAuthority": "ANPAJ2UCCR6DPCEXAMPLE",
        "Endpoint": "https://AKIAIOSFODNN7EXAMPLE.yl4.us-east-1.eks.amazonaws.com",
        "LogOptions": {
          "RetrieveLogs": true
        },
        "Job": {
          "apiVersion": "batch/v1",
          "kind": "Job",
          "metadata": {
            "name": "example-job"
          },
          "spec": {
            "backoffLimit": 0,
            "template": {
              "metadata": {
                "name": "example-job"
              },
              "spec": {
                "containers": [
                  {
                    "name": "pi-2000",
                    "image": "perl",
                    "command": [ "perl" ],
                    "args": [
                      "-Mbignum=bpi",
                      "-wle",
                      "print bpi(2000)"
                    ]
                  }
                ],
                "restartPolicy": "Never"
              }
            }
          }
        }
      },
      "End": true
    }
  }
}
```

### `Call`
<a name="connect-eks-kubernetes-apis-call"></a>

`eks:call` サービス統合は、Kubernetes API の使用を許可し、Kubernetes API エンドポイントを経由して Kubernetes リソースオブジェクトを読み取り書き込みます。

Kubernetes API サーバーは、ステートマシンで使用される IAM ロールにアクセス権限を付与する必要があります。詳細については、「[アクセス許可](#connect-eks-permissions)」を参照してください。

使用できる操作の詳細については、[Kubernetes API リファレンス](https://kubernetes.io/docs/reference/kubernetes-api/)を参照してください。

`Call` 用にサポートされているパラメータには以下が含まれます。
+ `ClusterName`: コールしたい Amazon EKS クラスター名。
  + `Type`: 文字列
  + 必須: はい
+ `CertificateAuthority`: ご自分のクラスターとの通信に必要な Base64 でエンコードされた証明書データ。この値は、[Amazon EKS コンソール](https://console.aws.amazon.com/eks/home)から、または Amazon EKS [DescribeCluster](https://docs.aws.amazon.com/eks/latest/APIReference/API_DescribeCluster.html) API を使用して取得できます。
  + `Type`: `String`
  + 必須: はい
+ `Endpoint`: Kubernetes API サーバーのエンドポイント。この値は、[Amazon EKS コンソール](https://console.aws.amazon.com/eks/home)または、Amazon EKS の DescribeCluster API を使用して見つけることができます。
  + `Type`: `String`
  + 必須: はい
+ `Method`: リクエストの HTTP メソッド。`GET`、`POST`、`PUT`、`DELETE`、`HEAD`、`PATCH` のいずれかです。
  + `Type`: `String`
  + 必須: はい
+ `Path`: Kubernetes REST API オペレーションの HTTP パス。
  + `Type`: `String`
  + 必須: はい
+ `QueryParameters`: Kubernetes REST API オペレーションの HTTP クエリパラメーター。
  + `List of Strings` への `String` の `Type: ` マッピング
  + 必須: いいえ
  + 例:

    ```
    "QueryParameters": {
      "labelSelector": [ "job-name=example-job" ]
    }
    ```
+ `RequestBody`: Kubernetes REST API オペレーションの HTTP メッセージ本文。
  + `Type`: `JSON` または `String`
  + 必須: いいえ

以下には、`eks:call` を使用して、ジョブ `example-job` に所属するポッドをリストする `Task` 状態が含まれます。

```
{
  "StartAt": "Call EKS",
  "States": {
    "Call EKS": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:call",
      "Arguments": {
        "ClusterName": "MyCluster",
        "CertificateAuthority": "ANPAJ2UCCR6DPCEXAMPLE",
        "Endpoint": "https://444455556666.yl4.us-east-1.eks.amazonaws.com",
        "Method": "GET",
        "Path": "/api/v1/namespaces/default/pods",
        "QueryParameters": {
          "labelSelector": [
            "job-name=example-job"
          ]
        }
      },
      "End": true
    }
  }
}
```

以下には、`eks:call` を使用して、ジョブ `example-job` を削除する `Task` 状態が含まれ、`propagationPolicy` をジョブのポッドも確実に削除されるよう設定します。

```
{
  "StartAt": "Call EKS",
  "States": {
    "Call EKS": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:call",
      "Arguments": {
        "ClusterName": "MyCluster",
        "CertificateAuthority": "ANPAJ2UCCR6DPCEXAMPLE",
        "Endpoint": "https://444455556666.yl4.us-east-1.eks.amazonaws.com",
        "Method": "DELETE",
        "Path": "/apis/batch/v1/namespaces/default/jobs/example-job",
        "QueryParameters": {
          "propagationPolicy": [
            "Foreground"
          ]
        }
      },
      "End": true
    }
  }
}
```

## 最適化された Amazon EKS API
<a name="connect-eks-apis"></a>

サポートされている Amazon EKS API と構文には次のものが含まれます。
+ [https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateCluster.html](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateCluster.html)
  +  [リクエストの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateCluster.html#API_CreateCluster_RequestSyntax) 
  +  [レスポンスの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateCluster.html#API_CreateCluster_ResponseSyntax) 

    `eks:createCluster` サービス統合を使って Amazon EKS クラスターが作成され時点で、IAM ロールが Kubernetes RBAC 認可テーブルに (システム: マスター許可のある) 管理者として追加されます。初期状態では、その IAM エンティティのみが、Kubernetes API サーバーを呼び出すことができます。詳細については、以下を参照してください。
    + *Amazon EKS ユーザーガイド*の[クラスターのユーザーまたは IAM ロールの管理](https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html) 
    + [アクセス許可](#connect-eks-permissions) セクション 

    Amazon EKS は、ユーザーに代わって他のサービスを呼び出すために Amazon EKS が必要な許可を含むサービスにリンクされたロールを使用します。これらのサービスにリンクされたロールがアカウントにまだ存在しない場合は、Step Functions で使用される IAM ロールに対する `iam:CreateServiceLinkedRole` 許可を追加する必要があります。詳細については、*Amazon EKS ユーザーガイド*の[サーバーがリンクしたロールを使用](https://docs.aws.amazon.com/eks/latest/userguide/using-service-linked-roles.html)を参照してください。

    Step Functions が使用する IAM ロールには、クラスタ IAM ロールを Amazon EKS に渡す `iam:PassRole` 許可がおりている必要があります。詳細については、*Amazon EKS ユーザーガイド*の [Amazon EKS クラスターの IAM ロール](https://docs.aws.amazon.com/eks/latest/userguide/service_IAM_role.html)を参照してください。
+ [https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteCluster.html](https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteCluster.html)
  +  [リクエストの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteCluster.html#API_DeleteCluster_RequestSyntax) 
  +  [レスポンスの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteCluster.html#API_DeleteCluster_ResponseSyntax) 

    クラスターを削除する前に、Fargate プロファイルまたはノードグループを削除する必要があります。
+ [https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateFargateProfile.html](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateFargateProfile.html)
  +  [リクエストの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateFargateProfile.html#API_CreateFargateProfile_RequestSyntax) 
  +  [レスポンスの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateFargateProfile.html#API_CreateFargateProfile_ResponseSyntax) 

    Amazon EKS は、ユーザーに代わって他のサービスを呼び出すために Amazon EKS が必要な許可を含むサービスにリンクされたロールを使用します。これらのサービスにリンクされたロールがアカウントにまだ存在しない場合は、Step Functions で使用される IAM ロールに対する `iam:CreateServiceLinkedRole` 許可を追加する必要があります。詳細については、*Amazon EKS ユーザーガイド*の[サーバーがリンクしたロールを使用](https://docs.aws.amazon.com/eks/latest/userguide/using-service-linked-roles.html)を参照してください。

    Fargate 上の Amazon EKS はすべてのリージョンで利用可能なわけではありません。リージョンの可用性の詳細については、[Fargate](https://docs.aws.amazon.com/eks/latest/userguide/fargate.html) の *Amazon EKS ユーザーガイド*の Fargate に関するセクションを参照してください。

    Step Functions で使用されている IAM ロールには、ポッド実行 IAM ロールを Amazon EKS に渡す `iam:PassRole` 許可が必要です。詳細については、*Amazon EKS ユーザーガイド*の[ポッド実行ロール](https://docs.aws.amazon.com/eks/latest/userguide/pod-execution-role.html)を参照してください。
+ [https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteFargateProfile.html](https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteFargateProfile.html)
  +  [リクエストの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteFargateProfile.html#API_DeleteFargateProfile_RequestSyntax) 
  +  [レスポンスの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteFargateProfile.html#API_DeleteFargateProfile_ResponseSyntax) 
+ [https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateNodegroup.html](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateNodegroup.html)
  +  [リクエストの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateNodegroup.html#API_CreateNodegroup_RequestSyntax) 
  +  [レスポンスの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateNodegroup.html#API_CreateNodegroup_ResponseSyntax) 

    Amazon EKS は、ユーザーに代わって他のサービスを呼び出すために Amazon EKS が必要な許可を含むサービスにリンクされたロールを使用します。これらのサービスにリンクされたロールがアカウントにまだ存在しない場合は、Step Functions で使用される IAM ロールに対する `iam:CreateServiceLinkedRole` 許可を追加する必要があります。詳細については、*Amazon EKS ユーザーガイド*の[サーバーがリンクしたロールを使用](https://docs.aws.amazon.com/eks/latest/userguide/using-service-linked-roles.html)を参照してください。

    Step Functions で使用される IAM ロールには、ノード IAM ロールを Amazon EKS に渡すため `iam:PassRole` 許可が必要です。詳細については、*Amazon EKS ユーザーガイド*の[サーバーがリンクしたロールを使用](https://docs.aws.amazon.com/eks/latest/userguide/create-node-role.html)を参照してください。
+ [https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteNodegroup.html](https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteNodegroup.html)
  +  [リクエストの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteNodegroup.html#API_DeleteNodegroup_RequestSyntax) 
  +  [レスポンスの構文](https://docs.aws.amazon.com/eks/latest/APIReference/API_DeleteNodegroup.html#API_DeleteNodegroup_ResponseSyntax) 

以下には Amazon EKS クラスターを作成する `Task` が含まれています。

```
{
  "StartAt": "CreateCluster.sync",
  "States": {
    "CreateCluster.sync": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:createCluster.sync",
      "Arguments": {
        "Name": "MyCluster",
        "ResourcesVpcConfig": {
          "SubnetIds": [
            "subnet-053e7c47012341234",
            "subnet-027cfea4b12341234"
          ]
        },
        "RoleArn": "arn:aws:iam::account-id:role/MyEKSClusterRole"
      },
      "End": true
    }
  }
}
```

以下には Amazon EKS クラスターを削除する `Task` 状態が含まれています。

```
{
  "StartAt": "DeleteCluster.sync",
  "States": {
    "DeleteCluster.sync": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:deleteCluster.sync",
      "Arguments": {
        "Name": "MyCluster"
      },
      "End": true
    }
  }
}
```

以下には Fargate プロファイルを作成する `Task` 状態が含まれています。

```
{
  "StartAt": "CreateFargateProfile.sync",
  "States": {
    "CreateFargateProfile.sync": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:createFargateProfile.sync",
      "Arguments": {
        "ClusterName": "MyCluster",
        "FargateProfileName": "MyFargateProfile",
        "PodExecutionRoleArn": "arn:aws:iam::account-id:role/MyFargatePodExecutionRole",
        "Selectors": [{
            "Namespace": "my-namespace",
            "Labels": { "my-label": "my-value" }
          }]
      },
      "End": true
    }
  }
}
```

以下には Fargate プロファイルを削除する `Task` 状態が含まれています。

```
{
  "StartAt": "DeleteFargateProfile.sync",
  "States": {
    "DeleteFargateProfile.sync": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:deleteFargateProfile.sync",
      "Arguments": {
        "ClusterName": "MyCluster",
        "FargateProfileName": "MyFargateProfile"
      },
      "End": true
    }
  }
}
```

以下にはノードグループを作成する `Task` 状態が含まれています。

```
{
  "StartAt": "CreateNodegroup.sync",
  "States": {
    "CreateNodegroup.sync": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:createNodegroup.sync",
      "Arguments": {
        "ClusterName": "MyCluster",
        "NodegroupName": "MyNodegroup",
        "NodeRole": "arn:aws:iam::account-id:role/MyNodeInstanceRole",
        "Subnets": ["subnet-09fb51df01234", "subnet-027cfea4b1234"] 
      },
      "End": true
    }
  }
}
```

以下にはノードグループを削除する `Task` 状態が含まれています。

```
{
  "StartAt": "DeleteNodegroup.sync",
  "States": {
    "DeleteNodegroup.sync": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:deleteNodegroup.sync",
      "Arguments": {
        "ClusterName": "MyCluster",
        "NodegroupName": "MyNodegroup"
      },
      "End": true
    }
  }
}
```

## アクセス許可
<a name="connect-eks-permissions"></a>

`eks:createCluster` サービス統合を使って Amazon EKS クラスターが作成され時点で、IAM ロールを `system:masters` 許可を受けた管理者として、Kubernetes RBAC 認可テーブルに追加されています。初期状態では、その IAM エンティティのみが、Kubernetes API サーバーを呼び出すことができます。例えば、Step Functions ステートマシンと同じロールを引き受けるのでなければ、または追加の IAM エンティティに許可を付与するように Kubernetes を構成している場合は、**kubectl** を使用して、Kubernetes API と対話することはできません。詳細については、*Amazon EKS ユーザーガイド*の[クラスター用ユーザーまたは IAM ロールを管理](https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html)を参照してください。

kube-system 名前空間の中の `aws-auth` `ConfigMap` に追加して、ユーザーまたはロールなど、追加 IAM エンティティの許可を追加できます。Step Functions からクラスターを作成する場合は、`eks:call` サービス統合を使用します。

以下には、`aws-auth` `ConfigMap` を作成し、ユーザー `arn:aws:iam::account-id:user/my-user` と IAM ロール `arn:aws:iam::account-id:role/my-role` に `system:masters` 許可を付与する `Task` 状態が含まれます。

```
{
  "StartAt": "Add authorized user",
  "States": {
    "Add authorized user": {
      "Type": "Task",
      "Resource": "arn:aws:states:::eks:call",
      "Arguments": {
        "ClusterName": "MyCluster",
        "CertificateAuthority": "LS0tLS1CRUd...UtLS0tLQo=",
        "Endpoint": "https://444455556666.yl4.region.eks.amazonaws.com",
        "Method": "POST",
        "Path": "/api/v1/namespaces/kube-system/configmaps",
        "RequestBody": {
           "apiVersion": "v1",
           "kind": "ConfigMap",
           "metadata": {
              "name": "aws-auth",
              "namespace": "kube-system"
           },
           "data": {
             "mapUsers": "[{ \"userarn\": \"arn:aws:iam::account-id:user/my-user\", \"username\": \"my-user\", \"groups\": [ \"system:masters\" ] } ]",
             "mapRoles": "[{ \"rolearn\": \"arn:aws:iam::account-id:role/my-role\", \"username\": \"my-role\", \"groups\": [ \"system:masters\" ] } ]"
           }
        }
      },
      "End": true
    }
  }
```

**注記**  
IAM ロールの ARN が、`arn:aws:iam::account-id:role/service-role/my-role` などのパス **/service-role/** を含む形式で表示されるのをご覧になるかもしれません。`aws-auth` でロールを一覧表示するときは、この **service-role** パストークンを含めないでください。

クラスターが最初に作成されるときは、`aws-auth` `ConfigMap` は存在しませんが、Fargate プロファイルを作成すると、自動的に追加されます。`aws-auth` の現在の値を取得し、追加許可を追加し、新しいバージョンを `PUT` します。通常、Fargate プロファイルの前に `aws-auth` を作成するほうが簡単です。

Step Functions の外部でクラスターが作成された場合は、**kubectl** を設定して、Kubernetes API サーバーと通信します。次に、`kubectl apply -f aws-auth.yaml` を使って新しい `aws-auth` `ConfigMap` を作成します。または、`kubectl edit -n kube-system configmap/aws-auth` を使用して既に存在するものを編集します。詳細については、以下を参照してください。
+  *Amazon EKS ユーザーガイド*の [Amazon EKS](https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html) 用 kubeconfig を作成します。
+  *Amazon EKS ユーザーガイド*の[クラスターのユーザーまたは IAM ロールを管理](https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html)。

Kubernetes で IAM ロールに十分な許可がない場合、`eks:call` または `eks:runJob` のサービス統合は、次のエラーで失敗します。

```
Error:
EKS.401

Cause:
{
  "ResponseBody": {
    "kind": "Status",
    "apiVersion": "v1",
    "metadata": {},
    "status": "Failure",
    "message": "Unauthorized",
    "reason": "Unauthorized",
    "code": 401
  },
  "StatusCode": 401,
  "StatusText": "Unauthorized"
}
```

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

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

### `CreateCluster`
<a name="eks-iam-createcluster"></a>

*リソース*

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "eks:CreateCluster"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "eks:DescribeCluster",
                "eks:DeleteCluster"
            ],
            "Resource": "arn:aws:eks:us-east-1:444455556666:cluster/*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "arn:aws:iam::444455556666:role/StepFunctionsSample-EKSClusterManag-EKSServiceRole-ANPAJ2UCCR6DPCEXAMPLE"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "eks.amazonaws.com"
                }
            }
        }
    ]
}
```

```


```

### `CreateNodeGroup`
<a name="eks-iam-createnodegroup"></a>

*リソース*

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeSubnets",
                "eks:CreateNodegroup"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "eks:DescribeNodegroup",
                "eks:DeleteNodegroup"
            ],
            "Resource": "arn:aws:eks:us-east-1:444455556666:nodegroup/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "iam:GetRole",
                "iam:ListAttachedRolePolicies"
            ],
            "Resource": "arn:aws:iam::444455556666:role/*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "arn:aws:iam::444455556666:role/StepFunctionsSample-EKSClusterMan-NodeInstanceRole-ANPAJ2UCCR6DPCEXAMPLE"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "eks.amazonaws.com"
                }
            }
        }
    ]
}
```

### `DeleteCluster`
<a name="eks-iam-deletecluster"></a>

*リソース*

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "eks:DeleteCluster",
                "eks:DescribeCluster"
            ],
            "Resource": [
                "arn:aws:eks:us-east-1:444455556666:cluster/ExampleCluster"
            ]
        }
    ]
}
```

### `DeleteNodegroup`
<a name="eks-iam-deletenodegroup"></a>

*リソース*

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "eks:DeleteNodegroup",
                "eks:DescribeNodegroup"
            ],
            "Resource": [
                "arn:aws:eks:us-east-1:444455556666:nodegroup/ExampleCluster/ExampleNodegroup/*"
            ]
        }
    ]
}
```

Step Functions での Amazon EKS の使用の詳細については、[Step Functions を使用した Amazon EKS クラスターの作成と管理](#connect-eks) を参照してください。

# Step Functions を使用した Amazon EMR クラスターの作成と管理
<a name="connect-emr"></a>

が提供する Amazon EMR サービス統合 APIs を使用して Amazon EMR AWS Step Functionsと を統合する方法について説明します。サービス統合 API は対応する Amazon EMR API に似ていますが、渡されるフィールドと返される応答にいくつかの違いがあります。

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

**最適化された Amazon EMR 統合の主な機能**  
最適化された Amazon EMR サービス統合には、以下で説明するような基になる Amazon EMR API をラップするカスタマイズされた一連の API があります。このため、Amazon EMR AWSSDK サービス統合とは大きく異なります。
[ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) 統合パターンがサポートされています。

Step Functions は、実行が停止しても Amazon EMR クラスターを自動的に終了しません。Amazon EMR クラスターが終了する前にステートマシンが停止した場合、クラスターは無期限に実行され、追加料金が発生する可能性があります。これを回避するには、作成した Amazon EMR クラスターが正しく終了していることを確認してください。詳細については、以下を参照してください。
+ Amazon EMR ユーザーガイド の[クラスター終了コントロール](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-plan-termination.html)。
+ サービス統合パターン [ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) セクション。

**注記**  
`emr-5.28.0` の時点で、クラスターの作成時に `StepConcurrencyLevel` パラメータを指定して、単一のクラスターで複数のステップを並行して実行することを許可します。Step Functions `Map` および `Parallel` 状態を使用して、並行して作業をクラスターに送信できます。

Amazon EMR サービス統合の可用性は、Amazon EMR API の可用性により決定します。特別なリージョンにおける制限については、[Amazon EMR](https://docs.aws.amazon.com//govcloud-us/latest/UserGuide/govcloud-emr.html) のドキュメントを参照してください。

**注記**  
Amazon EMR との統合のため、Step Functions は最初の 10 分とその後の 300 秒間、ジョブポーリング頻度をハードコーディングして 60 秒に設定しています。

## 最適化された Amazon EMR API
<a name="connect-emr-api"></a>

各 Amazon EMR サービス統合 API および対応する Amazon EMR API の違いを次の表に示します。


| Amazon EMR サービス統合 API | 対応する EMR API | 相違点 | 
| --- | --- | --- | 
| createCluster 新しいクラスター (ジョブフロー) を作成して実行を開始します。 Amazon EMR はサービスリンクロールとして知られる IAM ロールの一意のタイプに直接リンクされています。`createCluster` と `createCluster.sync` が機能するには、サービスリンクロール `AWSServiceRoleForEMRCleanup` を作成するために必要なアクセス許可が設定されている必要があります。IAM 許可ポリシーに追加できるステートメントなど、この詳細については、[Amazon EMR のサービスリンクロールを使用する](https://docs.aws.amazon.com/emr/latest/ManagementGuide/using-service-linked-roles.html)を参照してください。 | [runJobFlow](https://docs.aws.amazon.com/emr/latest/APIReference/API_RunJobFlow.html) | createCluster は次の場合を除き、[runJobFlow](https://docs.aws.amazon.com/emr/latest/APIReference/API_RunJobFlow.html) と同じリクエスト構文を使用します。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/connect-emr.html)レスポンスは次のとおりです。<pre>{<br />  "ClusterId": "string"<br />}</pre> Amazon EMR は以下を使用します。<pre>{<br />  "JobFlowId": "string"<br />}</pre>  | 
| createCluster.sync 新しいクラスター (ジョブフロー) を作成して実行を開始します。 | [runJobFlow](https://docs.aws.amazon.com/emr/latest/APIReference/API_RunJobFlow.html) | createCluster と同じですが、クラスターが WAITING 状態になるまで待機します。 | 
| setClusterTerminationProtection クラスター (ジョブフロー) をロックして、クラスター内の EC2 インスタンスをユーザーの介入、API コール、またはジョブフローエラーが発生した場合に終了できないようにします。 | [setTerminationProtection](https://docs.aws.amazon.com/emr/latest/APIReference/API_SetTerminationProtection.html) | リクエストは以下を使用します。<pre>{<br />  "ClusterId": "string"<br />}</pre> Amazon EMR は以下を使用します。<pre>{<br />  "JobFlowIds": ["string"]<br />}</pre>  | 
| terminateCluster クラスター (ジョブフロー) をシャットダウンします。  | [terminateJobFlows](https://docs.aws.amazon.com/emr/latest/APIReference/API_TerminateJobFlows.html) | リクエストは以下を使用します。<pre>{<br />  "ClusterId": "string"<br />}</pre> Amazon EMR は以下を使用します。<pre>{<br />  "JobFlowIds": ["string"]<br />}</pre> | 
| terminateCluster.syncクラスター (ジョブフロー) をシャットダウンします。 | [terminateJobFlows](https://docs.aws.amazon.com/emr/latest/APIReference/API_TerminateJobFlows.html) | terminateCluster と同じですが、クラスターが終了するまで待機します。 | 
| addStep 実行中のクラスターに新しいステップを追加します。 オプションで、この API `[ExecutionRoleArn](https://docs.aws.amazon.com/emr/latest/APIReference/API_AddJobFlowSteps.html#EMR-AddJobFlowSteps-request-ExecutionRoleArn)` を使用する際に パラメータを指定することもできます。 | [addJobFlowSteps](https://docs.aws.amazon.com/emr/latest/APIReference/API_AddJobFlowSteps.html) | リクエストはキー "ClusterId" を使用します。Amazon EMR は "JobFlowId" を使用します。リクエストは 1 つのステップを使用します。<pre>{<br />  "Step": <"StepConfig object"><br />}</pre> Amazon EMR は以下を使用します。<pre>{<br />  "Steps": [<StepConfig objects>]<br />}</pre> レスポンスは次のとおりです。<pre>{<br />  "StepId": "string"<br />}</pre> Amazon EMR はこれを返します。<pre>{<br />  "StepIds": [<strings>]<br />}</pre>  | 
| addStep.sync 実行中のクラスターに新しいステップを追加します。 オプションで、この API `[ExecutionRoleArn](https://docs.aws.amazon.com/emr/latest/APIReference/API_AddJobFlowSteps.html#EMR-AddJobFlowSteps-request-ExecutionRoleArn)` を使用する際に パラメータを指定することもできます。 | [addJobFlowSteps](https://docs.aws.amazon.com/emr/latest/APIReference/API_AddJobFlowSteps.html) | addStep と同じですが、ステップが完了するまで待機します。 | 
| cancelStep 実行中のクラスターで保留中のステップを取り消します。 | [cancelSteps](https://docs.aws.amazon.com/emr/latest/APIReference/API_CancelSteps.html) |  リクエストは以下を使用します。<pre>{<br />  "StepId": "string"<br />}</pre> Amazon EMR は以下を使用します。<pre>{<br />  "StepIds": [<strings>]<br />}</pre> レスポンスは次のとおりです。<pre>{<br />  "CancelStepsInfo": <CancelStepsInfo object><br />}</pre> Amazon EMR は以下を使用します。<pre>{<br />  "CancelStepsInfoList": [<CancelStepsInfo objects>]<br />}</pre>  | 
| modifyInstanceFleetByName 指定された `InstanceFleetName` を使用して、インスタンスフリートのターゲットオンデマンドおよびターゲットスポット容量を変更します。 | [modifyInstanceFleet](https://docs.aws.amazon.com/emr/latest/APIReference/API_ModifyInstanceFleet.html) | リクエストは modifyInstanceFleet の場合と同じですが、以下が異なります。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/connect-emr.html)  | 
| modifyInstanceGroupByName インスタンスグループのノード数と構成設定を変更します。 | [modifyInstanceGroups](https://docs.aws.amazon.com/emr/latest/APIReference/API_ModifyInstanceGroups.html) | リクエストは次のとおりです。<pre>{<br />  "ClusterId": "string",<br />  "InstanceGroup": <InstanceGroupModifyConfig object><br />}</pre> Amazon EMR は以下のリストを使用します。<pre>{<br />  "ClusterId": ["string"],<br />  "InstanceGroups": [<InstanceGroupModifyConfig objects>]<br />}</pre> `InstanceGroupModifyConfig` オブジェクト内では、フィールド `InstanceGroupId` は使用できません。 新しいフィールド `InstanceGroupName` が追加されました。実行時に、`InstanceGroupId` は `ListInstanceGroups` を呼び出して結果を解析することにより、サービス統合によって自動的に決定されます。  | 

## ワークフローの例
<a name="connect-emr-api-examples"></a>

以下にはクラスターを作成する `Task` 状態が含まれています。

```
"Create_Cluster": {
    "Type": "Task",
    "Resource": "arn:aws:states:::elasticmapreduce:createCluster.sync",
    "Arguments": {
        "Name": "MyWorkflowCluster",
        "VisibleToAllUsers": true,
        "ReleaseLabel": "emr-5.28.0",
        "Applications": [
            {
                "Name": "Hive"
            }
        ],
        "ServiceRole": "EMR_DefaultRole",
        "JobFlowRole": "EMR_EC2_DefaultRole",
        "LogUri": "s3n://aws-logs-account-id-us-east-1/elasticmapreduce/",
        "Instances": {
            "KeepJobFlowAliveWhenNoSteps": true,
            "InstanceFleets": [
                {
                    "InstanceFleetType": "MASTER",
                    "Name": "MASTER",   
                    "TargetOnDemandCapacity": 1,
                    "InstanceTypeConfigs": [
                        {
                            "InstanceType": "m4.xlarge"
                        }
                    ]
                },
                {
                    "InstanceFleetType": "CORE",
                    "Name": "CORE",
                    "TargetOnDemandCapacity": 1,
                    "InstanceTypeConfigs": [
                        {
                            "InstanceType": "m4.xlarge"
                        }
                    ]
                }
            ]
        }
    },
    "End": true
}
```

以下には終了保護を有効にする `Task` 状態が含まれています。

```
"Enable_Termination_Protection": {
    "Type": "Task",
    "Resource": "arn:aws:states:::elasticmapreduce:setClusterTerminationProtection",
    "Arguments": {
        "ClusterId": "{% $ClusterId %}",
        "TerminationProtected": true
    },
    "End": true
}
```

以下にはクラスターにステップを送信する `Task` 状態が含まれています。

```
"Step_One": {
    "Type": "Task",
    "Resource": "arn:aws:states:::elasticmapreduce:addStep.sync",
    "Arguments": {
        "ClusterId": "{% $ClusterId %}",
        "ExecutionRoleArn": "arn:aws:iam::account-id:role/myEMR-execution-role",
        "Step": {
            "Name": "The first step",
            "ActionOnFailure": "TERMINATE_CLUSTER",
            "HadoopJarStep": {
                "Jar": "command-runner.jar",
                "Args": [
                    "hive-script",
                    "--run-hive-script",
                    "--args",
                    "-f",
                    "s3://region.elasticmapreduce.samples/cloudfront/code/Hive_CloudFront.q",
                    "-d",
                    "INPUT=s3://region.elasticmapreduce.samples",
                    "-d",
                    "OUTPUT=s3://<amzn-s3-demo-bucket>/MyHiveQueryResults/"
                ]
            }
        }
    },
    "End": true
}
```

以下には、ステップをキャンセルする `Task` 状態が含まれます。

```
"Cancel_Step_One": {
    "Type": "Task",
    "Resource": "arn:aws:states:::elasticmapreduce:cancelStep",
    "Arguments": {
        "ClusterId": "{% $ClusterId %}",
        "StepId": "{% $AddStepsResult.StepId %}"
    },
    "End": true
}
```

以下には、クラスターを終了する `Task` 状態を示します。

```
"Terminate_Cluster": {
    "Type": "Task",
    "Resource": "arn:aws:states:::elasticmapreduce:terminateCluster.sync",
    "Arguments": {
        "ClusterId": "{% $ClusterId %}",
    },
    "End": true
}
```

以下には、インスタンスグループに合わせてクラスターをスケールアップまたはスケールダウンする `Task` 状態が含まれています。

```
"ModifyInstanceGroupByName": {
    "Type": "Task",
    "Resource": "arn:aws:states:::elasticmapreduce:modifyInstanceGroupByName",
    "Arguments": {
        "ClusterId": "j-account-id3",
        "InstanceGroupName": "MyCoreGroup",
        "InstanceGroup": {
            "InstanceCount": 8
        }
    },
    "End": true
}
```

以下には、インスタンスフリートに合わせてクラスターをスケールアップまたはスケールダウンする `Task` 状態が含まれています。

```
"ModifyInstanceFleetByName": {
    "Type": "Task",
    "Resource": "arn:aws:states:::elasticmapreduce:modifyInstanceFleetByName",
    "Arguments": {
        "ClusterId": "j-account-id3",
        "InstanceFleetName": "MyCoreFleet",
        "InstanceFleet": {
            "TargetOnDemandCapacity": 8,
            "TargetSpotCapacity": 0
        }
    },
    "End": true
}
```

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

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

### `addStep`
<a name="emr-iam-addstep"></a>

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticmapreduce:AddJobFlowSteps",
                "elasticmapreduce:DescribeStep",
                "elasticmapreduce:CancelSteps"
            ],
            "Resource": [
                "arn:aws:elasticmapreduce:us-east-1:123456789012:cluster/clusterId"
            ]
        }
    ]
}
```

動的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "elasticmapreduce:AddJobFlowSteps",
        "elasticmapreduce:DescribeStep",
        "elasticmapreduce:CancelSteps"
      ],
      "Resource": "arn:aws:elasticmapreduce:*:*:cluster/*"
    }
  ]
}
```

### `cancelStep`
<a name="emr-iam-cancelstep"></a>

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "elasticmapreduce:CancelSteps",
            "Resource": [
                "arn:aws:elasticmapreduce:us-east-1:123456789012:cluster/myCluster-id"
            ]
        }
    ]
}
```

動的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "elasticmapreduce:CancelSteps",
            "Resource": "arn:aws:elasticmapreduce:*:*:cluster/*"
        }
    ]
}
```

### `createCluster`
<a name="emr-iam-createcluster"></a>

静的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "elasticmapreduce:RunJobFlow",
        "elasticmapreduce:DescribeCluster",
        "elasticmapreduce:TerminateJobFlows"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "iam:PassRole",
      "Resource": [
        "arn:aws:iam::123456789012:role/myRoleName"
      ]
    }
  ]
}
```

### `setClusterTerminationProtection`
<a name="emr-iam-clusterterminationprotection"></a>

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "elasticmapreduce:SetTerminationProtection",
            "Resource": [
                "arn:aws:elasticmapreduce:us-east-1:123456789012:cluster/myCluster-id"
            ]
        }
    ]
}
```

動的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "elasticmapreduce:SetTerminationProtection",
            "Resource": "arn:aws:elasticmapreduce:*:*:cluster/*"
        }
    ]
}
```

### `modifyInstanceFleetByName`
<a name="emr-iam-modifyinstancefleetbyname"></a>

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticmapreduce:ModifyInstanceFleet",
                "elasticmapreduce:ListInstanceFleets"
            ],
            "Resource": [
                "arn:aws:elasticmapreduce:us-east-1:123456789012:cluster/myCluster-id"
            ]
        }
    ]
}
```

動的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticmapreduce:ModifyInstanceFleet",
                "elasticmapreduce:ListInstanceFleets"
            ],
            "Resource": "arn:aws:elasticmapreduce:*:*:cluster/*"
        }
    ]
}
```

### `modifyInstanceGroupByName`
<a name="emr-iam-modifyinstancegroupbyname"></a>

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticmapreduce:ModifyInstanceGroups",
                "elasticmapreduce:ListInstanceGroups"
            ],
            "Resource": [
                "arn:aws:elasticmapreduce:us-east-1:123456789012:cluster/myCluster-id"
            ]
        }
    ]
}
```

動的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticmapreduce:ModifyInstanceGroups",
                "elasticmapreduce:ListInstanceGroups"
            ],
            "Resource": "*"
        }
    ]
}
```

### `terminateCluster`
<a name="emr-iam-terminatecluster"></a>

静的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "elasticmapreduce:TerminateJobFlows",
        "elasticmapreduce:DescribeCluster"
      ],
      "Resource": [
        "arn:aws:elasticmapreduce:us-east-1:123456789012:cluster/myCluster-id"
      ]
    }
  ]
}
```

動的リソース**

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "elasticmapreduce:TerminateJobFlows",
        "elasticmapreduce:DescribeCluster"
      ],
      "Resource": "arn:aws:elasticmapreduce:*:*:cluster/*"
    }
  ]
}
```

# を使用した EKS での Amazon EMR クラスターの作成と管理 AWS Step Functions
<a name="connect-emr-eks"></a>

Amazon EMR on EKS サービス統合 APIs を使用して Amazon EMR on EKS AWS Step Functions と を統合する方法について説明します。サービス統合 API は EKS API の対応する Amazon EMR と同じですが、次の表で示すとおり、すべての API があらゆる統合パターンをサポートしているわけではありません。

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

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

**注記**  
Amazon EMR との統合のため、Step Functions は最初の 10 分とその後の 300 秒間、ジョブポーリング頻度をハードコーディングして 60 秒に設定しています。


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

EKS API 上でサポートされる Amazon EMR は次のとおりです。

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


+ [https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_CreateVirtualCluster.html](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_CreateVirtualCluster.html)
  + [リクエストの構文](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_CreateVirtualCluster.html#API_CreateVirtualCluster_RequestSyntax)
  + [サポートされているパラメータ](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_CreateVirtualCluster.html#API_CreateVirtualCluster_RequestBody)
  + [レスポンスの構文](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_CreateVirtualCluster.html#API_CreateVirtualCluster_ResponseSyntax)
+ [https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_DeleteVirtualCluster.html](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_DeleteVirtualCluster.html)
  + [リクエストの構文](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_DeleteVirtualCluster.html#API_DeleteVirtualCluster_RequestSyntax)
  + [サポートされているパラメータ](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_DeleteVirtualCluster.html#API_DeleteVirtualCluster_RequestParameters)
  + [レスポンスの構文](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_CreateVirtualCluster.html#API_CreateVirtualCluster_ResponseSyntax)
+ [https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_StartJobRun.html](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_StartJobRun.html)
  + [リクエストの構文](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_StartJobRun.html#API_StartJobRun_RequestSyntax)
  + [サポートされているパラメータ](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_StartJobRun.html#API_StartJobRun_RequestParameters)
  + [レスポンスの構文](https://docs.aws.amazon.com/emr-on-eks/latest/APIReference/API_StartJobRun.html#API_StartJobRun_ResponseSyntax)

以下には仮想クラスターを作成する `Task` 状態が含まれています。

```
"Create_Virtual_Cluster": {
  "Type": "Task",
  "Resource": "arn:aws:states:::emr-containers:createVirtualCluster",
  "Arguments": {
    "Name": "MyVirtualCluster",
    "ContainerProvider": {
      "Id": "EKSClusterName",
      "Type": "EKS",
      "Info": {
        "EksInfo": {
          "Namespace": "Namespace"
        }
      }
    }
  },
  "End": true
}
```

以下には、 ジョブを仮想クラスターに送信し、完了するまで待機する `Task` 状態が含まれます。

```
"Submit_Job": {
    "Type": "Task",
    "Resource": "arn:aws:states:::emr-containers:startJobRun.sync",
    "Arguments": {
      "Name": "MyJobName",
      "VirtualClusterId": "{% $VirtualClusterId %}",
      "ExecutionRoleArn": "arn:aws:iam::<accountId>:role/job-execution-role",
      "ReleaseLabel": "emr-6.2.0-latest",
      "JobDriver": {
        "SparkSubmitJobDriver": {
          "EntryPoint": "s3://<amzn-s3-demo-bucket>/jobs/trip-count.py",
          "EntryPointArguments": [
            "60"
          ],
          "SparkSubmitParameters": "--conf spark.driver.cores=2 --conf spark.executor.instances=10 --conf spark.kubernetes.pyspark.pythonVersion=3 --conf spark.executor.memory=10G --conf spark.driver.memory=10G --conf spark.executor.cores=1 --conf spark.dynamicAllocation.enabled=false"
        }
      },
      "ConfigurationOverrides": {
        "ApplicationConfiguration": [
          {
            "Classification": "spark-defaults",
            "Properties": {
              "spark.executor.instances": "2",
              "spark.executor.memory": "2G"
            }
          }
        ],
        "MonitoringConfiguration": {
          "PersistentAppUI": "ENABLED",
          "CloudWatchMonitoringConfiguration": {
            "LogGroupName": "MyLogGroupName",
            "LogStreamNamePrefix": "MyLogStreamNamePrefix"
          },
          "S3MonitoringConfiguration": {
            "LogUri": "s3://<amzn-s3-demo-logging-bucket1>"
          }
        }
      },
      "Tags": {
        "taskType": "jobName"
      }
    },
    "End": true
}
```

以下には、仮想クラスターを削除し、削除が完了するまで待機する `Task` 状態が含まれます。

```
"Delete_Virtual_Cluster": {
  "Type": "Task",
  "Resource": "arn:aws:states:::emr-containers:deleteVirtualCluster.sync",
  "Arguments": {
    "Id": "{% $states.input.VirtualClusterId %}",
  },
  "End": true
}
```

を他の AWS サービスStep Functionsで使用する際のIAMアクセス許可の設定については、「」を参照してください[Step Functions が統合サービスの IAM ポリシーを生成する方法](service-integration-iam-templates.md)。

# Step Functions で Amazon EMR Serverless アプリケーションを作成および管理する
<a name="connect-emr-serverless"></a>

Step Functions を使用して EMR Serverless でアプリケーションを作成、開始、停止、削除する方法について説明します。このページでは、サポートされている API を一覧表示し、一般的なユースケースを実行するための `Task` 状態の例を示します。

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

**最適化された EMR Serverless 統合の主な機能**  
 最適化された EMR Serverless サービス統合には、基になる EMR Serverless API をラップする [API](#connect-emr-serverless-custom-apis) のカスタマイズされたセットがあります。このカスタマイズにより、最適化されたEMR Serverless統合は AWSSDK サービス統合とは大きく異なります。
さらに、最適化された EMR Serverless 統合は [ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) 統合パターンをサポートします。
[タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token) 統合パターンは**サポートされていません**。

## EMR Serverless サービス統合 API
<a name="connect-emr-serverless-custom-apis"></a>

AWS Step Functions を EMR Serverless と統合するために、以下の 6 つの EMR Serverless サービス統合 API を使用できます。これらのサービス統合 API は、対応する EMR Serverless API に似ていますが、渡されるフィールドと返される応答にいくつかの違いがあります。

各 EMR Serverless サービス統合 API と対応する EMR Serverless API の違いを次の表に示します。


| EMR Serverless サービス統合 API | 対応する EMR Serverless API | 相違点 | 
| --- | --- | --- | 
|  *createApplication*  アプリケーションを作成します。 EMR Serverless はサービスリンクロールとして知られる IAM ロールの一意のタイプにリンクされています。`createApplication` と `createApplication.sync` が機能するには、サービスリンクロール `AWSServiceRoleForAmazonEMRServerless` を作成するために必要なアクセス許可が設定されている必要があります。IAM アクセス許可ポリシーに追加できるステートメントなど、詳細については、「[EMR Serverless のサービスにリンクされたロールの使用](https://docs.aws.amazon.com/emr/latest/EMR-Serverless-UserGuide/using-service-linked-roles.html)」を参照してください。  |  [CreateApplication](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_CreateApplication.html)  | なし | 
|  *createApplication.sync*  アプリケーションを作成します。  |  [CreateApplication](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_CreateApplication.html)  |  EMR Serverless API と EMR Serverless サービス統合 API のリクエストとレスポンスには違いはありません。ただし、*createApplication.sync* はアプリケーションが `CREATED` 状態に達するまで待機します。  | 
|  *startApplication* 指定されたアプリケーションを起動し、設定されている場合はアプリケーションの初期容量を初期化します。  |  [StartApplication](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_StartApplication.html)  |  EMR Serverless API レスポンスにはデータは含まれませんが、EMR Serverless サービス統合 API レスポンスには以下のデータが含まれます。 <pre>{<br />  "ApplicationId": "string"<br />}</pre>  | 
|  *startApplication.sync* 指定されたアプリケーションを起動し、設定されている場合は初期容量を初期化します。  |  [StartApplication](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_StartApplication.html)  |  EMR Serverless API レスポンスにはデータは含まれませんが、EMR Serverless サービス統合 API レスポンスには以下のデータが含まれます。 <pre>{<br />  "ApplicationId": "string"<br />}</pre> また、*startApplication.sync* はアプリケーションが `STARTED` 状態に達するまで待機します。  | 
|  *stopApplication* 指定されたアプリケーションを停止し、設定されている場合は初期容量を解放します。アプリケーションを停止する前に、スケジュールされたジョブと実行中のジョブをすべて完了またはキャンセルする必要があります。  |  [StopApplication](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_StopApplication.html)  |  EMR Serverless API レスポンスにはデータは含まれませんが、EMR Serverless サービス統合 API レスポンスには以下のデータが含まれます。 <pre>{<br />  "ApplicationId": "string"<br />}</pre>  | 
|  *stopApplication.sync* 指定されたアプリケーションを停止し、設定されている場合は初期容量を解放します。アプリケーションを停止する前に、スケジュールされたジョブと実行中のジョブをすべて完了またはキャンセルする必要があります。  |  [StopApplication](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_StopApplication.html)  |  EMR Serverless API レスポンスにはデータは含まれませんが、EMR Serverless サービス統合 API レスポンスには以下のデータが含まれます。 <pre>{<br />  "ApplicationId": "string"<br />}</pre> また、*stopApplication.sync* はアプリケーションが `STOPPED` 状態に達するまで待機します。  | 
|  *DeleteApplication* アプリケーションを削除します アプリケーションを削除するには、そのアプリケーションが `STOPPED` または `CREATED` 状態になっている必要があります。  |  [DeleteApplication](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_DeleteApplication.html)  |  EMR Serverless API レスポンスにはデータは含まれませんが、EMR Serverless サービス統合 API レスポンスには以下のデータが含まれます。 <pre>{<br />  "ApplicationId": "string"<br />}</pre>  | 
|  *deleteApplication.sync* アプリケーションを削除します アプリケーションを削除するには、そのアプリケーションが `STOPPED` または `CREATED` 状態になっている必要があります。  |  [DeleteApplication](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_DeleteApplication.html)  |  EMR Serverless API レスポンスにはデータは含まれませんが、EMR Serverless サービス統合 API レスポンスには以下のデータが含まれます。 <pre>{<br />  "ApplicationId": "string"<br />}</pre> また、*stopApplication.sync* はアプリケーションが `TERMINATED` 状態に達するまで待機します。  | 
|  *startJobRun* ジョブ実行を開始します。  |  [StartJobRun](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_StartJobRun.html)  | なし | 
|  *startJobRun.sync* ジョブ実行を開始します。  |  [StartJobRun](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_StartJobRun.html)  |  EMR Serverless API と EMR Serverless サービス統合 API のリクエストとレスポンスには違いはありません。ただし、*startJobRun.sync* はアプリケーションが `SUCCESS` 状態に達するまで待機します。  | 
|  *cancelJobRun* ジョブ実行をキャンセルします。  |  [CancelJobRun](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_CancelJobRun.html)  | なし | 
|  *cancelJobRun.sync* ジョブ実行をキャンセルします。  |  [CancelJobRun](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_CancelJobRun.html)  |  EMR Serverless API と EMR Serverless サービス統合 API のリクエストとレスポンスには違いはありません。ただし、*cancelJobRun.sync* はアプリケーションが `CANCELLED` 状態に達するまで待機します。  | 

## EMR サーバーレス統合のユースケース
<a name="connect-emr-serverless-use-cases"></a>

最適化された EMR Serverless サービス統合では、アプリケーションを 1 つ作成して、そのアプリケーションを使用して複数のジョブを実行することをお勧めします。例えば、1 つのステートマシンに、同じアプリケーションを使用する複数の [startJobRun](https://docs.aws.amazon.com/emr-serverless/latest/APIReference/API_StartJobRun.html) リクエストを含めることができます。以下の [Task ワークフロー状態](state-task.md) 状態の例は、API EMR Serverless を Step Functions と統合するユースケースを示しています。EMR Serverless のその他のユースケースの情報については、「[Amazon EMR Serverless とは](https://docs.aws.amazon.com/emr/latest/EMR-Serverless-UserGuide/emr-serverless.html)」を参照してください。

**ヒント**  
EMR Serverless と統合して複数のジョブを実行するステートマシンの例をデプロイするには、「[EMR Serverless ジョブを実行する](sample-emr-serverless-job.md)」を参照してください。
+ [アプリケーションの作成](#connect-emr-serverless-task-state-createapp)
+ [アプリケーションの起動](#connect-emr-serverless-task-state-startapp)
+ [アプリケーションの停止](#connect-emr-serverless-task-state-stopapp)
+ [アプリケーションの削除](#connect-emr-serverless-task-state-deleteapp)
+ [アプリケーションでのジョブの開始](#connect-emr-serverless-task-state-startjobrun)
+ [アプリケーションでのジョブのキャンセル](#connect-emr-serverless-task-state-canceljobrun)

を他の AWSサービスStep Functionsで使用する際のIAMアクセス許可の設定については、「」を参照してください[Step Functions が統合サービスの IAM ポリシーを生成する方法](service-integration-iam-templates.md)。

以下のユースケースの例で*斜体で示されている*テキストを、リソース固有の情報に置き換えてください。例えば、*yourApplicationId* を EMR Serverless アプリケーションの ID (`00yv7iv71inak893` など) に置き換えてください。

### アプリケーションの作成
<a name="connect-emr-serverless-task-state-createapp"></a>

次のタスクステートの例では、*createApplication.sync* サービス統合 API を使用してアプリケーションを作成しています。

```
"Create_Application": {
    "Type": "Task",
    "Resource": "arn:aws:states:::emr-serverless:createApplication.sync",
    "Arguments": {
        "Name": "MyApplication",
        "ReleaseLabel": "emr-6.9.0",
        "Type": "SPARK"
    },
    "End": true
}
```

### アプリケーションの起動
<a name="connect-emr-serverless-task-state-startapp"></a>

次のタスク状態の例では、*startApplication.sync* サービス統合 API を使用してアプリケーションを起動します。

```
"Start_Application": {
    "Type": "Task",
    "Resource": "arn:aws:states:::emr-serverless:startApplication.sync",
    "Arguments": {
        "ApplicationId": "yourApplicationId"
    },
    "End": true
}
```

### アプリケーションの停止
<a name="connect-emr-serverless-task-state-stopapp"></a>

次のタスク状態の例では、*stopApplication.sync* サービス統合 API を使用してアプリケーションを停止します。

```
"Stop_Application": {
    "Type": "Task",
    "Resource": "arn:aws:states:::emr-serverless:stopApplication.sync",
    "Arguments": {
        "ApplicationId": "yourApplicationId"
    },
    "End": true
}
```

### アプリケーションの削除
<a name="connect-emr-serverless-task-state-deleteapp"></a>

次のタスク状態の例では、*deleteApplication.sync* サービス統合 API を使用してアプリケーションを削除します。

```
"Delete_Application": {
    "Type": "Task",
    "Resource": "arn:aws:states:::emr-serverless:deleteApplication.sync",
    "Arguments": {
        "ApplicationId": "yourApplicationId"
    },
    "End": true
}
```

### アプリケーションでのジョブの開始
<a name="connect-emr-serverless-task-state-startjobrun"></a>

次のタスク状態の例では、*startJobRun.sync* サービス統合 API を使用してアプリケーションでジョブを開始します。

```
"Start_Job": {
    "Type": "Task",
    "Resource": "arn:aws:states:::emr-serverless:startJobRun.sync",
    "Arguments": {
        "ApplicationId": "yourApplicationId",
        "ExecutionRoleArn": "arn:aws:iam::account-id:role/myEMRServerless-execution-role",
        "JobDriver": {
            "SparkSubmit": {
                "EntryPoint": "s3://<amzn-s3-demo-bucket>/sample.py",
                "EntryPointArguments": ["1"],
                "SparkSubmitParameters": "--conf spark.executor.cores=4 --conf spark.executor.memory=4g --conf spark.driver.cores=2 --conf spark.driver.memory=4g --conf spark.executor.instances=1"
            }
        }
    },
    "End": true
}
```

### アプリケーションでのジョブのキャンセル
<a name="connect-emr-serverless-task-state-canceljobrun"></a>

次のタスク状態の例では、*cancelJobRun.sync* サービス統合 API を使用してアプリケーション内のジョブをキャンセルします。

```
"Cancel_Job": {
    "Type": "Task",
    "Resource": "arn:aws:states:::emr-serverless:cancelJobRun.sync",
    "Arguments": {
        "ApplicationId": "{% $states.input.ApplicationId %}",
        "JobRunId": "{% $states.input.JobRunId %}"
    },
    "End": true
}
```

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

コンソールを使用してステートマシンを作成すると、必要な最小特権を持つステートマシンの実行ロールがStep Functions によって自動的に作成されます。これらの自動生成されたIAMロールは、ステートマシンを作成する AWS リージョンで有効です。

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

IAM ポリシーを作成するときは、ポリシーにワイルドカードを含めないことをお勧めします。セキュリティのベストプラクティスとして、ポリシーの範囲をできるだけ絞り込む必要があります。動的ポリシーは、ランタイム中に特定の入力パラメータが不明な場合にのみ使用してください。

さらに、管理者ユーザーが非管理者ユーザーに、ステートマシンを実行するための実行ロールを付与する場合には注意が必要です。自分でポリシーを作成する場合は、実行ロールに PassRole ポリシーを含めることをお勧めします。また、実行ロールには `aws:SourceARN` および `aws:SourceAccount` のコンテキストキーを追加することをお勧めします。

### EMR Serverless と Step Functions の統合の場合の IAM ポリシーの例
<a name="emr-serverless-iam-policy-eg"></a>
+ [CreateApplication の IAM ポリシーの例](#emr-serverless-policy-createapp)
+ [StartApplication の IAM ポリシーの例](#emr-serverless-policy-startapp)
+ [StopApplication の IAM ポリシーの例](#emr-serverless-policy-stopapp)
+ [DeleteApplication の IAM ポリシーの例](#emr-serverless-policy-deleteapp)
+ [StartJobRun の IAM ポリシーの例](#emr-serverless-policy-startjobrun)
+ [CancelJobRun の IAM ポリシーの例](#emr-serverless-policy-canceljobrun)

#### CreateApplication の IAM ポリシーの例
<a name="emr-serverless-policy-createapp"></a>

以下は、CreateApplication が [Task ワークフロー状態](state-task.md) 状態でのステートマシンの IAM ポリシーの例です。

**注記**  
アカウントで初めてアプリケーションを作成するときには、IAM ポリシーで CreateServiceLinkedRole 許可を指定する必要があります。それ以降、この許可を追加する必要はありません。CreateServiceLinkedRole の詳細については、https://docs.aws.amazon.com/IAM/latest/APIReference/ の「[CreateServiceLinkedRole](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateServiceLinkedRole.html)」を参照してください。

以下のポリシーは、静的リソースと動的リソースで同じです。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "emr-serverless:CreateApplication"
            ],
            "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "emr-serverless:GetApplication",
                "emr-serverless:DeleteApplication"
            ],
            "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessApplicationRule"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "iam:CreateServiceLinkedRole",
            "Resource": "arn:aws:iam::123456789012:role/aws-service-role/ops.emr-serverless.amazonaws.com/AWSServiceRoleForAmazonEMRServerless*",
            "Condition": {
                "StringLike": {
                    "iam:AWSServiceName": "ops.emr-serverless.amazonaws.com"
                }
            }
        }
   ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   
   "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "emr-serverless:CreateApplication"
            ],
            "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "iam:CreateServiceLinkedRole",
            "Resource": "arn:aws:iam::123456789012:role/aws-service-role/ops.emr-serverless.amazonaws.com/AWSServiceRoleForAmazonEMRServerless*",
            "Condition": {
                "StringLike": {
                    "iam:AWSServiceName": "ops.emr-serverless.amazonaws.com"
                }
            }
        }
    ]
}
```

------

#### StartApplication の IAM ポリシーの例
<a name="emr-serverless-policy-startapp"></a>

**静的リソース**  
以下は、StartApplication が [Task ワークフロー状態](state-task.md) 状態で、ステートマシンを使用する場合の静的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StartApplication",
               "emr-serverless:GetApplication",
               "emr-serverless:StopApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessApplicationRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StartApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId"
            ]
        }
    ]
}
```

------

**動的リソース**  
以下は、StartApplication が[Task ワークフロー状態](state-task.md) 状態で、ステートマシンを使用する場合の動的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StartApplication",
               "emr-serverless:GetApplication",
               "emr-serverless:StopApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessApplicationRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StartApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        }
    ]
}
```

------

#### StopApplication の IAM ポリシーの例
<a name="emr-serverless-policy-stopapp"></a>

**静的リソース**  
以下は、StopApplication が [Task ワークフロー状態](state-task.md) 状態で、ステートマシンを使用する場合の静的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StopApplication",
               "emr-serverless:GetApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessApplicationRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StopApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId"
            ]
        }
    ]
}
```

------

**動的リソース**  
以下は、StopApplication が [Task ワークフロー状態](state-task.md) 状態で、ステートマシンを使用する場合の動的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StopApplication",
               "emr-serverless:GetApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessApplicationRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StopApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        }
    ]
}
```

------

#### DeleteApplication の IAM ポリシーの例
<a name="emr-serverless-policy-deleteapp"></a>

**静的リソース**  
以下は、DeleteApplication が [Task ワークフロー状態](state-task.md) 状態で、ステートマシンを使用する場合の静的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:DeleteApplication",
               "emr-serverless:GetApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessApplicationRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:DeleteApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId"
            ]
        }
    ]
}
```

------

**動的リソース**  
以下は、DeleteApplication が [Task ワークフロー状態](state-task.md) 状態でステートマシンを使用する場合の動的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:DeleteApplication",
               "emr-serverless:GetApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessApplicationRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:DeleteApplication"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        }
    ]
}
```

------

#### StartJobRun の IAM ポリシーの例
<a name="emr-serverless-policy-startjobrun"></a>

**静的リソース**  
以下は、StartJobRun が [Task ワークフロー状態](state-task.md) 状態で、ステートマシンを使用する場合の静的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StartJobRun"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "arn:aws:iam::123456789012:role/jobExecutionRoleArn"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "emr-serverless.amazonaws.com"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "emr-serverless:GetJobRun",
                "emr-serverless:CancelJobRun"
            ],
            "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId/jobruns/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessJobRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StartJobRun"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "arn:aws:iam::123456789012:role/jobExecutionRoleArn"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "emr-serverless.amazonaws.com"
                }
            }
        }
    ]
}
```

------

**動的リソース**  
以下は、StartJobRun が[Task ワークフロー状態](state-task.md) 状態で、ステートマシンを使用する場合の動的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StartJobRun",
               "emr-serverless:GetJobRun",
               "emr-serverless:CancelJobRun"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "arn:aws:iam::123456789012:role/jobExecutionRoleArn"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "emr-serverless.amazonaws.com"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessJobRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:StartJobRun"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "arn:aws:iam::123456789012:role/jobExecutionRoleArn"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": "emr-serverless.amazonaws.com"
                }
            }
        }
    ]
}
```

------

#### CancelJobRun の IAM ポリシーの例
<a name="emr-serverless-policy-canceljobrun"></a>

**静的リソース**  
以下は、CancelJobRun が [Task ワークフロー状態](state-task.md) 状態で、ステートマシンを使用する場合の静的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:CancelJobRun",
               "emr-serverless:GetJobRun"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId/jobruns/jobRunId"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessJobRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:CancelJobRun"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/applicationId/jobruns/jobRunId"
            ]
        }
    ]
}
```

------

**動的リソース**  
以下は、CancelJobRun が [Task ワークフロー状態](state-task.md) 状態で、ステートマシンを使用する場合の動的リソースの IAM ポリシーの例です。

------
#### [ Run a Job (.sync) ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:CancelJobRun",
               "emr-serverless:GetJobRun"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForEMRServerlessJobRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
        {
           "Effect": "Allow",
           "Action": [
               "emr-serverless:CancelJobRun"
            ],
           "Resource": [
                "arn:aws:emr-serverless:us-east-1:123456789012:/applications/*"
            ]
        }
    ]
}
```

------

# Step Functions で EventBridge イベントを追加する
<a name="connect-eventbridge"></a>

Step Functions は、Amazon EventBridge と統合するため、サービス統合 API を提供します。Step Functions ワークフローから直接カスタムイベントを送信して、イベント駆動型アプリケーションを構築する方法について説明します。

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

**最適化された EventBridge 統合の主な機能**  
実行 ARN とステートマシン ARN は、各 `PutEventsRequestEntry` の `Resources` フィールドに自動的に追加されます。
`PutEvents` からのレスポンスにゼロ以外の `FailedEntryCount` が含まれるのであれば、`Task` 状態はエラー `EventBridge.FailedEntry` で失敗します。

 `PutEvents` API を使用する場合、送信するイベントの特定のパターンに一致する EventBridge ルールをアカウント内に作成する必要があります。例えば、次のことができます。
+ EventBridge ルールに一致するイベントを受信して印刷する Lambda 関数をアカウントに作成します。
+  特定のイベントパターンに一致し、Lambda 関数をターゲットとする、デフォルトのイベントバスで EventBridge ルールをアカウントで作成します。

 詳細については、以下を参照してください。
+ EventBridge ユーザーガイドの [PutEvents を使って Amazon EventBridge イベントを追加](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-putevents.html)。
+ サービス統合パターンの [タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token)。

以下には、カスタムイベントを送信する `Task` が含まれます。

```
{
  "Type": "Task",
  "Resource": "arn:aws:states:::events:putEvents",
  "Arguments": {
    "Entries": [
      {
        "Detail": {
          "Message": "MyMessage"
        },
        "DetailType": "MyDetailType",
        "EventBusName": "MyEventBus",
        "Source": "my.source"
      }
    ]
  },
  "End": true
}
```

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

## 最適化された EventBridge API
<a name="connect-eventbridge-apis"></a>

サポートされている EventBridge API と構文には次のものが含まれます。
+ [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutEvents.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutEvents.html)

## エラー処理
<a name="connect-eventbridge-error"></a>

`PutEvents` API はエントリの配列を入力として受け取り、結果エントリの配列を返します。`PutEvents` アクションが成功する限り、`PutEvents` は、1 つ以上のエントリが失敗した場合でも、HTTP 200 レスポンスを返します。`PutEvents` は `FailedEntryCount` フィールドの失敗したエントリの数を返します。

Step Functions、`FailedEntryCount` がゼロより大きいかどうかをチェックします。0 より大きい場合、Step Functions はエラー `EventBridge.FailedEntry` を使って状態を失敗させます。こうして、エントリに失敗した場合、キャッチまたは再試行のため、タスクの状態で Step Functions の組み込みエラー処理を使用できます。レスポンスから `FailedEntryCount` を分析する追加状態を使う必要はありません。

**注記**  
べき等を実装し、すべてのエントリで安全に再試行できる場合は、Step Functions の再試行ロジックを使用できます。Step Functions は、再試行する前に、`PutEvents` 入力配列から成功したエントリを削除しません。代わりに、元のエントリの配列を使って再試行します。

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

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

### `PutEvents`
<a name="eventbridge-iam-listconnections"></a>

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Action": [
                "events:PutEvents"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:event-bus/my-project-eventbus"
            ],
            "Effect": "Allow"
        }
    ]
}
```

動的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "events:PutEvents"
            ],
            "Resource": "arn:aws:events:*:*:event-bus/*"
        }
    ]
}
```

# Step Functions で AWS Glueジョブを開始する
<a name="connect-glue"></a>

Step Functions を使用して AWS Glue でジョブの実行を開始する方法について説明します。このページでは、サポートされている API アクションを一覧表示し、AWS Glueジョブを開始するための`Task`状態の例を示します。

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

**最適化AWS Glue統合の主な機能**  
[ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) 統合パターンが利用可能です。
`JobName` フィールドがリクエストから抽出され、レスポンスに挿入されます。通常は `JobRunID` のみが含まれます。

以下には、 AWS Glueジョブを開始する`Task`状態が含まれます。

```
"Glue StartJobRun": {
      "Type": "Task",
      "Resource": "arn:aws:states:::glue:startJobRun.sync",
      "Arguments": {
        "JobName": "GlueJob-JTrRO5l98qMG"
      },
      "Next": "ValidateOutput"
    },
```

**Step Functions のパラメータは PascalCase で表されます。**  
ネイティブサービス API が、API アクション `startSyncExecution` などの camelCase である場合でも、`StateMachineArn` などの PascalCase でパラメータを指定します。

## AWS GlueAPIs
<a name="connect-glue-api"></a>
+ [https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-jobs-runs.html#aws-glue-api-jobs-runs-StartJobRun](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-jobs-runs.html#aws-glue-api-jobs-runs-StartJobRun)

## を呼び出すための IAM ポリシーAWS Glue
<a name="glue-iam"></a>

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

AWS Glueにはリソースベースのコントロールはありません。

------
#### [ Run a Job (.sync) ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "glue:StartJobRun",
                "glue:GetJobRun",
                "glue:GetJobRuns",
                "glue:BatchStopJobRun"
            ],
            "Resource": "*"
        }
    ]
}
```

------
#### [ Request Response and Callback (.waitForTaskToken) ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "glue:StartJobRun"
            ],
            "Resource": "*"
        }
    ]
}
```

------

# Step Functions で AWS Glue DataBrew ジョブを開始する
<a name="connect-databrew"></a>

DataBrew 統合を使用して、Step Functions で分析および機械学習のワークフローにデータのクリーニングとデータの正規化手順を追加する方法について説明します。

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

以下には、リクエスト/レスポンス DataBrew ジョブがスタートする `Task` 状態が含まれます。

```
"DataBrew StartJobRun": {
            "Type": "Task",
            "Resource": "arn:aws:states:::databrew:startJobRun",
            "Arguments": {
               "Name": "sample-proj-job-1"
            },
            "Next": "NEXT_STATE"
          },
```

以下には、DataBrew ジョブをスタートする `Task` 状態が含まれます。

```
"DataBrew StartJobRun": {
           "Type": "Task",
           "Resource": "arn:aws:states:::databrew:startJobRun.sync",
           "Arguments": {
              "Name": "sample-proj-job-1"
           },
           "Next": "NEXT_STATE"
          },
```

**Step Functions のパラメータは PascalCase で表されます。**  
ネイティブサービス API が、API アクション `startSyncExecution` などの camelCase である場合でも、`StateMachineArn` などの PascalCase でパラメータを指定します。

## サポートされている DataBrew API
<a name="connect-databrew-api"></a>
+ `[https://docs.aws.amazon.com/databrew/latest/dg/API_StartJobRun.html](https://docs.aws.amazon.com/databrew/latest/dg/API_StartJobRun.html)`

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

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

------
#### [ Run a Job (.sync) ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "databrew:startJobRun",
                "databrew:listJobRuns",
                "databrew:stopJobRun"
            ],
            "Resource": [
                "arn:aws:databrew:us-east-1:123456789012:job/*"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

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

------

# Step Functions を使用して AWS Lambda関数を呼び出す
<a name="connect-lambda"></a>

Step Functions を使用して、イベント駆動型サーバーレスアプリケーションの一部として同期的にまたは非同期的に Lambda 関数を呼び出す方法について説明します。

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

**最適化された Lambda 統合の主な機能**  
レスポンスの `Payload` フィールドは、エスケープされた Json から Json に解析されます。
Lambda 関数内で例外がスローされた場合、タスクは失敗します。実用的な例については、「[Step Functions ステートマシンでのエラー条件の処理](tutorial-handling-error-conditions.md)」を参照してください。

## 最適化された Lambda API
<a name="connect-lambda-api"></a>
+ [https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html)

## ワークフローの例
<a name="connect-lambda-api-examples"></a>

以下には、Lambda 関数を呼び出す `Task` 状態が含まれます。

```
{  
   "StartAt":"CallLambda",
   "States":{  
      "CallLambda":{  
         "Type":"Task",
         "Resource":"arn:aws:states:::lambda:invoke",
         "Arguments":{  
            "FunctionName":"arn:aws:lambda:region:account-id:function:MyFunction"
         },
         "End":true
      }
   }
}
```

以下には、[コールバック](connect-to-resource.md#connect-wait-token)サービス統合パターンを実行する `Task` の状態が含まれます。

```
{  
   "StartAt":"GetManualReview",
   "States":{  
      "GetManualReview":{  
         "Type":"Task",
         "Resource":"arn:aws:states:::lambda:invoke.waitForTaskToken",
         "Arguments":{  
            "FunctionName":"arn:aws:lambda:region:account-id:function:get-model-review-decision",
            "Payload":{  
               "model":"{% $states.input.my-model %}",
               "TaskToken": "{% $states.context.Task.Token %}"
            },
            "Qualifier":"prod-v1"
         },
         "End":true
      }
   }
}
```

Lambda 関数を呼び出すと、実行は関数の完了を待ちます。コールバックタスクで Lambda 関数を呼び出す場合、Lambda 関数の実行が完了して結果を返すまで、ハートビートタイムアウトのカウントは開始されません。Lambda 関数が実行されている限り、ハートビートタイムアウトは適用されません。

ただし、次の例に示されているとおり、`InvocationType` パラメータを使って非同期で Lambda を呼び出すこともできます。

```
{

  "Comment": "A Hello World example of the Amazon States Language using Pass states",
  "StartAt": "Hello",
  "States": {
    "Hello": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Arguments": {
        "FunctionName": "arn:aws:lambda:region:account-id:function:echo",
        "InvocationType": "Event"
      },
      "End": true
    }
  }
}
```

**注記**  
Lambda 関数の非同期呼び出しでは、ハートビートタイムアウト期間がすぐに開始されます。

 ときに `Task` の結果が返されると、関数の出力はメタデータのディクショナリ内にネストされます。例えば、次のようになります。

```
{

   "ExecutedVersion":"$LATEST",
   "Payload":"FUNCTION OUTPUT",
   "SdkHttpMetadata":{
      "HttpHeaders":{
         "Connection":"keep-alive",
         "Content-Length":"4",
         "Content-Type":"application/json",
         "Date":"Fri, 26 Mar 2021 07:42:02 GMT",
         "X-Amz-Executed-Version":"$LATEST",
         "x-amzn-Remapped-Content-Length":"0",
         "x-amzn-RequestId":"0101aa0101-1111-111a-aa55-1010aaa1010",
         "X-Amzn-Trace-Id":"root=1-1a1a000a2a2-fe0101aa10ab;sampled=0"
      },
      "HttpStatusCode":200
   },
   "SdkResponseMetadata":{
      "RequestId":"6b3bebdb-9251-453a-ae45-512d9e2bf4d3"
   },
   "StatusCode":200
}
```

## 直接指定された関数リソース
<a name="w2aac33c40c13"></a>

または、「リソース」フィールドに関数 ARN を直接指定して Lambda 関数を呼び出せます。この方法で Lambda 関数を呼び出す場合、`.waitForTaskToken` を指定することはできず、タスク結果には関数の出力のみが含まれます。

```
{  
   "StartAt":"CallFunction",
   "States":{  
      "CallFunction": {  
         "Type":"Task",
         "Resource":"arn:aws:lambda:region:account-id:function:HelloFunction",
         "End": true
      }
   }
}
```

この形式の統合では、関数は成功しても、`FunctionError` フィールドを含むレスポンスを返すことがあります。このシナリオでは、ワークフロータスクは失敗します。

Lambda 関数の特定バージョンまたはエイリアスを呼び出すには、`Resource` フィールドの ARN でそれらのオプションを指定します。Lambda ドキュメントで以下を参照してください。
+ [AWS Lambda バージョニング](https://docs.aws.amazon.com/lambda/latest/dg/versioning-intro.html)
+ [AWS Lambdaエイリアス](https://docs.aws.amazon.com/lambda/latest/dg/aliases-intro.html)

## を呼び出すための IAM ポリシーAWS Lambda
<a name="lambda-iam"></a>

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

次の例では、2 つのAWS Lambdaタスクを持つステートマシンが `function1`と を呼び出すと`function2`、自動生成されたポリシーには両方の関数に対する`lambda:Invoke`アクセス許可が含まれます。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "lambda:InvokeFunction"
            ],
            "Resource": [
                "arn:aws:lambda:us-east-1:123456789012:function:myFn1",
                "arn:aws:lambda:us-east-1:123456789012:function:myFn2"
            ]
        }
    ]
}
```

# Step Functions を使用して AWS Elemental MediaConvertジョブを作成する
<a name="connect-mediaconvert"></a>

Step Functions を使用して [https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobspost](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobspost) API を使用して AWS Elemental MediaConvertジョブを作成する方法について説明します。

**Step Functions と MediaConvert を試す**  
長さが不明な SMTPE カラーバーを検出して動画クリップの先頭から削除するワークフローで MediaConvert 最適化統合を使用する方法について説明します。2024 年 4 月 12 日のブログ記事を読む: [https://aws.amazon.com/blogs/media/low-code-workflows-with-aws-elemental-mediaconvert/](https://aws.amazon.com/blogs/media/low-code-workflows-with-aws-elemental-mediaconvert/)

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

**最適化された MediaConvert 統合の主な機能**  
[ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) と [レスポンスのリクエスト](connect-to-resource.md#connect-default) の統合パターンがサポートされています。
Step Functions は MediaConvert ジョブに次のカスタムタグを追加します。`ManagedByService: AWSStepFunctions`
[タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token) 統合パターンに固有の最適化はありません。

次に示しているのは、MediaConvert ジョブを送信し、完了するまで待機する `Task` ステートです。

```
{
    "StartAt": "MediaConvert_CreateJob",
    "States": {
        "MediaConvert_CreateJob": {
        "Type": "Task",
        "Resource": "arn:aws:states:::mediaconvert:createJob.sync",
        "Arguments": {
            "Role": "arn:aws:iam::111122223333:role/Admin",
            "Settings": {
            "OutputGroups": [
                {
                "Outputs": [
                    {
                    "ContainerSettings": {
                        "Container": "MP4"
                    },
                    "VideoDescription": {
                        "CodecSettings": {
                        "Codec": "H_264",
                        "H264Settings": {
                            "MaxBitrate": 1000,
                            "RateControlMode": "QVBR",
                            "SceneChangeDetect": "TRANSITION_DETECTION"
                        }
                        }
                    },
                    "AudioDescriptions": [
                        {
                        "CodecSettings": {
                            "Codec": "AAC",
                            "AacSettings": {
                            "Bitrate": 96000,
                            "CodingMode": "CODING_MODE_2_0",
                            "SampleRate": 48000
                            }
                        }
                        }
                    ]
                    }
                ],
                "OutputGroupSettings": {
                    "Type": "FILE_GROUP_SETTINGS",
                    "FileGroupSettings": {
                    "Destination": "s3://amzn-s3-demo-destination-bucket/"
                    }
                }
                }
            ],
            "Inputs": [
                {
                "AudioSelectors": {
                    "Audio Selector 1": {
                    "DefaultSelection": "DEFAULT"
                    }
                },
                "FileInput": "s3://amzn-s3-demo-bucket/DOC-EXAMPLE-SOURCE_FILE"
                }
            ]
            }
        },
        "End": true
        }
    }
}
```

**Step Functions のパラメータは PascalCase で表されます。**  
ネイティブサービス API が、API アクション `startSyncExecution` などの camelCase である場合でも、`StateMachineArn` などの PascalCase でパラメータを指定します。

## 最適化された MediaConvert API
<a name="connect-mediaconvert-api"></a>
+ [https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobspost](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobspost)
  + [リクエストの構文](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-request-body-post-example)
  + サポートされているパラメータ:
    + [https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-prop-createjobrequest-role](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-prop-createjobrequest-role) (必須)
    + [https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-prop-createjobrequest-settings](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-prop-createjobrequest-settings) (必須)
    + [https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-model-createjobrequest](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-model-createjobrequest) (オプション)
  + [レスポンス構文](https://docs.aws.amazon.com/mediaconvert/latest/apireference/jobs.html#jobs-response-examples) - 「**CreateJobResponse スキーマ**」を参照してください。

## を呼び出すための IAM ポリシーAWS Elemental MediaConvert
<a name="mediaconvert-iam"></a>

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

`GetJob` および `CancelJob` アクションに関する IAM ポリシーは、`ManagedByService: AWSStepFunctions` タグ付きのジョブへのアクセスのみを許可するようにスコープ設定されています。

**タグベースのポリシー**  
自動生成された `ManagedByService: AWSStepFunctions` タグを変更すると、ステートマシンの実行は失敗します。

------
#### [ Run a Job (.sync) ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "MediaConvertCreateJob",
            "Effect": "Allow",
            "Action": [
                "mediaconvert:CreateJob"
            ],
            "Resource": [
                "arn:aws:mediaconvert:us-east-1:123456789012:queues/*",
                "arn:aws:mediaconvert:us-east-1:123456789012:jobTemplates/*",
                "arn:aws:mediaconvert:us-east-1:123456789012:presets/*"
            ]
        },
        {
            "Sid": "MediaConvertManageJob",
            "Effect": "Allow",
            "Action": [
                "mediaconvert:GetJob",
                "mediaconvert:CancelJob"
            ],
            "Resource": "arn:aws:mediaconvert:us-east-1:123456789012:jobs/*",
            "Condition": {
                "StringEquals": {
                    "aws:ResourceTag/ManagedByService": "AWSStepFunctions"
                }
            }
        },
        {
            "Sid": "IamPassRole",
            "Effect": "Allow",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "arn:aws:iam::123456789012:role/myRoleName"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": [
                        "mediaconvert.amazonaws.com"
                    ]
                }
            }
        }, 
        {
            "Sid": "EventBridgeManageRule",
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForMediaConvertJobRule"
            ]
        }
    ]
}
```

------
#### [ Request Response ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "MediaConvertCreateJob",
            "Effect": "Allow",
            "Action": [
                "mediaconvert:CreateJob"
            ],
            "Resource": [
                "arn:aws:mediaconvert:us-east-1:123456789012:queues/*",
                "arn:aws:mediaconvert:us-east-1:123456789012:jobTemplates/*",
                "arn:aws:mediaconvert:us-east-1:123456789012:presets/*"
            ]
        },
        {
            "Sid": "IamPassRole",
            "Effect": "Allow",
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "arn:aws:iam::123456789012:role/myRoleName"
            ],
            "Condition": {
                "StringEquals": {
                    "iam:PassedToService": [
                        "mediaconvert.amazonaws.com"
                    ]
                }
            }
        }
    ]
}
```

------

# Step Functions を使用して Amazon SageMaker AI ジョブを作成および管理する
<a name="connect-sagemaker"></a>

Step Functions を使用して SageMaker AI でジョブを作成および管理する方法について説明します。このページでは、サポートされている SageMaker API アクションのリストと、SageMaker AI の変換、トレーニング、ラベル付け、および処理ジョブを作成する `Task` ステート例を示しています。

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

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

## 最適化された SageMaker AI API
<a name="connect-sagemaker-api"></a>
+ [https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateEndpoint.html](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateEndpoint.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateEndpointConfig.html](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateEndpointConfig.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateHyperParameterTuningJob.html](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateHyperParameterTuningJob.html) - `.sync` 統合パターンをサポートします。
+ [https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateLabelingJob.html) - `.sync` 統合パターンをサポートします。
+ [https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateModel.html](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateModel.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateProcessingJob.html](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateProcessingJob.html) - `.sync` 統合パターンをサポートします。
+ [https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateTrainingJob.html](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateTrainingJob.html) - `.sync` 統合パターンをサポートします。
+ [https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateTransformJob.html](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateTransformJob.html) - `.sync` 統合パターンをサポートします。
+ [https://docs.aws.amazon.com/sagemaker/latest/dg/API_UpdateEndpoint.html](https://docs.aws.amazon.com/sagemaker/latest/dg/API_UpdateEndpoint.html)

**注記**  
AWS Step Functionsは のポリシーを自動的に作成しません`CreateTransformJob`。インラインポリシーは、作成したロールにアタッチする必要があります。詳細については、次の IAM ポリシー例: [`CreateTrainingJob`](#sagemaker-iam-createtrainingjob) を参照してください。

## SageMaker AI 変換ジョブの例
<a name="sagemaker-example-transform"></a>

次に示しているのは、Amazon SageMaker AI 変換ジョブを作成する`Task` ステートであり、`DataSource` と `TransformOutput` の Amazon S3 ロケーションを指定しています。

```
{
"SageMaker CreateTransformJob": {
  "Type": "Task",
  "Resource": "arn:aws:states:::sagemaker:createTransformJob.sync",
  "Arguments": {
    "ModelName": "SageMakerCreateTransformJobModel-9iFBKsYti9vr",
    "TransformInput": {
      "CompressionType": "None",
      "ContentType": "text/csv",
      "DataSource": {
        "S3DataSource": {
          "S3DataType": "S3Prefix",
          "S3Uri": "s3://amzn-s3-demo-source-bucket1/TransformJobDataInput.txt"
        }
      }
    },
    "TransformOutput": {
      "S3OutputPath": "s3://amzn-s3-demo-source-bucket1/TransformJobOutputPath"
    },
    "TransformResources": {
      "InstanceCount": 1,
      "InstanceType": "ml.m4.xlarge"
    },
    "TransformJobName": "sfn-binary-classification-prediction"
  },
  "Next": "ValidateOutput"
},
```

## SageMaker AI トレーニングジョブの例
<a name="sagemaker-example-training"></a>

次に示しているのは、Amazon SageMaker AI トレーニングジョブを作成する `Task` ステートです。

```
{  
   "SageMaker CreateTrainingJob":{  
      "Type":"Task",
      "Resource":"arn:aws:states:::sagemaker:createTrainingJob.sync",
      "Arguments":{  
         "TrainingJobName":"search-model",
         "ResourceConfig":{  
            "InstanceCount":4,
            "InstanceType":"ml.c4.8xlarge",
            "VolumeSizeInGB":20
         },
         "HyperParameters":{  
            "mode":"batch_skipgram",
            "epochs":"5",
            "min_count":"5",
            "sampling_threshold":"0.0001",
            "learning_rate":"0.025",
            "window_size":"5",
            "vector_dim":"300",
            "negative_samples":"5",
            "batch_size":"11"
         },
         "AlgorithmSpecification":{  
            "TrainingImage":"...",
            "TrainingInputMode":"File"
         },
         "OutputDataConfig":{  
            "S3OutputPath":"s3://amzn-s3-demo-destination-bucket1/doc-search/model"
         },
         "StoppingCondition":{  
            "MaxRuntimeInSeconds":100000
         },
         "RoleArn":"arn:aws:iam::account-id:role/docsearch-stepfunction-iam-role",
         "InputDataConfig":[  
            {  
               "ChannelName":"train",
               "DataSource":{  
                  "S3DataSource":{  
                     "S3DataType":"S3Prefix",
                     "S3Uri":"s3://amzn-s3-demo-destination-bucket1/doc-search/interim-data/training-data/",
                     "S3DataDistributionType":"FullyReplicated"
                  }
               }
            }
         ]
      },
      "Retry":[  
         {  
            "ErrorEquals":[  
               "SageMaker.AmazonSageMakerException"
            ],
            "IntervalSeconds":1,
            "MaxAttempts":100,
            "BackoffRate":1.1
         },
         {  
            "ErrorEquals":[  
               "SageMaker.ResourceLimitExceededException"
            ],
            "IntervalSeconds":60,
            "MaxAttempts":5000,
            "BackoffRate":1
         },
         {  
            "ErrorEquals":[  
               "States.Timeout"
            ],
            "IntervalSeconds":1,
            "MaxAttempts":5,
            "BackoffRate":1
         }
      ],
      "Catch":[  
         {  
            "ErrorEquals":[  
               "States.ALL"
            ],
            "Next":"Sagemaker Training Job Error"
         }
      ],
      "Next":"Delete Interim Data Job"
   }
}
```

## SageMaker AI ラベル付けジョブの例
<a name="sagemaker-example-labeling"></a>

次に示しているのは、Amazon SageMaker AI ラベル付けジョブを作成する `Task` ステートです。

```
{
  "StartAt": "SageMaker CreateLabelingJob",
  "TimeoutSeconds": 3600,
  "States": {
    "SageMaker CreateLabelingJob": {
      "Type": "Task",
      "Resource": "arn:aws:states:::sagemaker:createLabelingJob.sync",
      "Arguments": {
        "HumanTaskConfig": {
          "AnnotationConsolidationConfig": {
            "AnnotationConsolidationLambdaArn": "arn:aws:lambda:region:123456789012:function:ACS-TextMultiClass"
          },
          "NumberOfHumanWorkersPerDataObject": 1,
          "PreHumanTaskLambdaArn": "arn:aws:lambda:region:123456789012:function:PRE-TextMultiClass",
          "TaskDescription": "Classify the following text",
          "TaskKeywords": [
            "tc",
            "Labeling"
          ],
          "TaskTimeLimitInSeconds": 300,
          "TaskTitle": "Classify short bits of text",
          "UiConfig": {
            "UiTemplateS3Uri": "s3://amzn-s3-demo-bucket/TextClassification.template"
          },
          "WorkteamArn": "arn:aws:sagemaker:region:123456789012:workteam/private-crowd/ExampleTesting"
        },
        "InputConfig": {
          "DataAttributes": {
            "ContentClassifiers": [
              "FreeOfPersonallyIdentifiableInformation",
              "FreeOfAdultContent"
            ]
          },
          "DataSource": {
            "S3DataSource": {
              "ManifestS3Uri": "s3://amzn-s3-demo-bucket/manifest.json"
            }
          }
        },
        "LabelAttributeName": "Categories",
        "LabelCategoryConfigS3Uri": "s3://amzn-s3-demo-bucket/labelcategories.json",
        "LabelingJobName": "example-job-name",
        "OutputConfig": {
          "S3OutputPath": "s3://amzn-s3-demo-bucket/output"
        },
        "RoleArn": "arn:aws:iam::123456789012:role/service-role/AmazonSageMaker-ExecutionRole",
        "StoppingConditions": {
          "MaxHumanLabeledObjectCount": 10000,
          "MaxPercentageOfInputDatasetLabeled": 100
        }
      },
      "Next": "ValidateOutput"
    },
    "ValidateOutput": {
        "Type": "Choice",
        "Choices": [
            {
                "Next": "Success",
                "Condition": "{% $states.input.LabelingJobArn != '' %}"
            }
        ],
        "Default": "Fail"
        },
        "Success": {
            "Type": "Succeed"
        },
        "Fail": {
            "Type": "Fail",
            "Error": "InvalidOutput",
            "Cause": "Output is not what was expected. This could be due to a service outage or a misconfigured service integration."
        }
    }
}
```

## SageMaker AI 処理ジョブの例
<a name="sagemaker-example-processing"></a>

次に示しているのは、Amazon SageMaker AI 処理ジョブを作成する `Task` ステートです。

```
{
  "StartAt": "SageMaker CreateProcessingJob Sync",
  "TimeoutSeconds": 3600,
  "States": {
    "SageMaker CreateProcessingJob Sync": {
      "Type": "Task",
      "Resource": "arn:aws:states:::sagemaker:createProcessingJob.sync",
      "Arguments": {
        "AppSpecification": {
          "ImageUri": "737474898029.dkr.ecr.sa-east-1.amazonaws.com/sagemaker-scikit-learn:0.20.0-cpu-py3"
        },
        "ProcessingResources": {
          "ClusterConfig": {
            "InstanceCount": 1,
            "InstanceType": "ml.t3.medium",
            "VolumeSizeInGB": 10
          }
        },
        "RoleArn": "arn:aws:iam::account-id:role/SM-003-CreateProcessingJobAPIExecutionRole",
        "ProcessingJobName.$": "$.id"
      },
      "Next": "ValidateOutput"
    },
    "ValidateOutput": {
      "Type": "Choice",
      "Choices": [
        {
          "Not": {
            "Variable": "$.ProcessingJobArn",
            "StringEquals": ""
          },
          "Next": "Succeed"
        }
      ],
      "Default": "Fail"
    },
    "Succeed": {
      "Type": "Succeed"
    },
    "Fail": {
      "Type": "Fail",
      "Error": "InvalidConnectorOutput",
      "Cause": "Connector output is not what was expected. This could be due to a service outage or a misconfigured connector."
    }
  }
}
```

## Amazon SageMaker AI の呼び出しに関する IAM ポリシー
<a name="sagemaker-iam"></a>

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

**注記**  
これらの例では、`roleArn` は、SageMaker AI がモデルアーティファクトおよび Docker イメージにアクセスして、ML コンピューティングインスタンスのデプロイ、またはバッチ変換ジョブに使用する IAM ロールの Amazon リソースネーム (ARN) を参照します。詳細については、[Amazon SageMaker ロール](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-roles.html)を参照してください。

### `CreateTrainingJob`
<a name="sagemaker-iam-createtrainingjob"></a>

静的リソース**

------
#### [ Run a Job (.sync) ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateTrainingJob",
        "sagemaker:DescribeTrainingJob",
        "sagemaker:StopTrainingJob"
      ],
      "Resource": [
        "arn:aws:sagemaker:us-east-1:123456789012:training-job/myJobName*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:ListTags",
        "sagemaker:AddTags"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:PassRole"
      ],
      "Resource": [
        "arn:aws:iam::123456789012:role/MyExampleRole"
      ],
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "sagemaker.amazonaws.com"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "events:PutTargets",
        "events:PutRule",
        "events:DescribeRule"
      ],
      "Resource": [
        "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForSageMakerTrainingJobsRule"
      ]
    }
  ]
}
```

------
#### [ Request Response and Callback (.waitForTaskToken) ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateTrainingJob"
      ],
      "Resource": [
        "arn:aws:sagemaker:us-east-1:123456789012:training-job/myJobName*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:ListTags",
        "sagemaker:AddTags"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:PassRole"
      ],
      "Resource": [
        "arn:aws:iam::123456789012:role/MyExampleRole"
      ],
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "sagemaker.amazonaws.com"
        }
      }
    }
  ]
}
```

------

動的リソース**

------
#### [ .sync or .waitForTaskToken ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateTrainingJob",
        "sagemaker:DescribeTrainingJob",
        "sagemaker:StopTrainingJob"
      ],
      "Resource": [
        "arn:aws:sagemaker:us-east-1:123456789012:training-job/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:ListTags",
        "sagemaker:AddTags"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:PassRole"
      ],
      "Resource": [
        "arn:aws:iam::123456789012:role/MyExampleRole"
      ],
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "sagemaker.amazonaws.com"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "events:PutTargets",
        "events:PutRule",
        "events:DescribeRule"
      ],
      "Resource": [
        "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForSageMakerTrainingJobsRule"
      ]
    }
  ]
}
```

------
#### [ Request Response and Callback (.waitForTaskToken) ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateTrainingJob"
      ],
      "Resource": [
        "arn:aws:sagemaker:us-east-1:123456789012:training-job/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:ListTags",
        "sagemaker:AddTags"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:PassRole"
      ],
      "Resource": [
        "arn:aws:iam::123456789012:role/MyExampleRole"
      ],
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "sagemaker.amazonaws.com"
        }
      }
    }
  ]
}
```

------

### `CreateTransformJob`
<a name="sagemaker-iam-createtransformjob"></a>

**注記**  
AWS Step Functionsは、SageMaker AI と統合するステートマシンを作成する`CreateTransformJob`ときに、 のポリシーを自動的に作成しません。次のいずれかの IAM の例に基づいて、作成されたロールにインラインポリシーをアタッチする必要があります。

静的リソース**

------
#### [ Run a Job (.sync) ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateTransformJob",
        "sagemaker:DescribeTransformJob",
        "sagemaker:StopTransformJob"
      ],
      "Resource": [
        "arn:aws:sagemaker:us-east-1:123456789012:transform-job/myJobName*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:ListTags",
        "sagemaker:AddTags"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:PassRole"
      ],
      "Resource": [
        "arn:aws:iam::123456789012:role/MyExampleRole"
      ],
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "sagemaker.amazonaws.com"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "events:PutTargets",
        "events:PutRule",
        "events:DescribeRule"
      ],
      "Resource": [
        "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForSageMakerTransformJobsRule"
      ]
    }
  ]
}
```

------
#### [ Request Response and Callback (.waitForTaskToken) ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateTransformJob"
      ],
      "Resource": [
        "arn:aws:sagemaker:us-east-1:123456789012:transform-job/myJobName*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:ListTags",
        "sagemaker:AddTags"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:PassRole"
      ],
      "Resource": [
        "arn:aws:iam::123456789012:role/MyExampleRole"
      ],
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "sagemaker.amazonaws.com"
        }
      }
    }
  ]
}
```

------

動的リソース**

------
#### [ Run a Job (.sync) ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateTransformJob",
        "sagemaker:DescribeTransformJob",
        "sagemaker:StopTransformJob"
      ],
      "Resource": [
        "arn:aws:sagemaker:us-east-1:123456789012:transform-job/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:ListTags",
        "sagemaker:AddTags"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:PassRole"
      ],
      "Resource": [
        "arn:aws:iam::123456789012:role/MyExampleRole"
      ],
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "sagemaker.amazonaws.com"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": [
        "events:PutTargets",
        "events:PutRule",
        "events:DescribeRule"
      ],
      "Resource": [
        "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForSageMakerTransformJobsRule"
      ]
    }
  ]
}
```

------
#### [ Request Response and Callback (.waitForTaskToken) ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateTransformJob"
      ],
      "Resource": [
        "arn:aws:sagemaker:us-east-1:123456789012:transform-job/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:ListTags",
        "sagemaker:AddTags"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:PassRole"
      ],
      "Resource": [
        "arn:aws:iam::123456789012:role/MyExampleRole"
      ],
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "sagemaker.amazonaws.com"
        }
      }
    }
  ]
}
```

------

# Step Functions を使用して Amazon SNS トピックにメッセージを発行する
<a name="connect-sns"></a>

Step Functions を使用して Amazon SNS トピックにメッセージを発行する方法について説明します。このページでは、サポートされている Amazon SNS API アクションを一覧表示し、Amazon SNS にメッセージを公開するための `Task` 状態の例を示します。

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

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

以下には、Amazon Simple Notification Service (Amazon SNS) トピックに発行する `Task` 状態が含まれます。

```
{
 "StartAt": "Publish to SNS",
 "States": {
   "Publish to SNS": {
     "Type": "Task",
     "Resource": "arn:aws:states:::sns:publish",
     "Arguments": {
       "TopicArn": "arn:aws:sns:region:account-id:myTopic",
       "Message": "{% states.input.message %}",
       "MessageAttributes": {
         "my_attribute_no_1": {
           "DataType": "String",
           "StringValue": "value of my_attribute_no_1"
         },
         "my_attribute_no_2": {
           "DataType": "String",
           "StringValue": "value of my_attribute_no_2"
         }
       }
     },
     "End": true
    }
  }
}
```

**動的な値を渡す**。上記の例を変更して、この JSON ペイロードから属性を動的に渡すことができます。

```
{
  "message": "Hello world",
  "SNSDetails": {
    "attribute1": "some value",
    "attribute2": "some other value",
  }
}
```

次に示しているのは、`StringValue` フィールドに対して JSONata 式で値を設定する例です。

```
"MessageAttributes": {
  "my_attribute_no_1": {
      "DataType": "String",
      "StringValue": "{% $states.input.SNSDetails.attribute1 %}"
  },
  "my_attribute_no_2": {
      "DataType": "String",
      "StringValue": "{% $states.input.SNSDetails.attribute2 %}"
  }
```

以下には、Amazon SNS トピックに発行され、その後タスクトークンが返されるまで待機する `Task` 状態が含まれます。「[タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token)」を参照してください。

```
{  
   "StartAt":"Send message to SNS",
   "States":{  
      "Send message to SNS":{  
         "Type":"Task",
         "Resource":"arn:aws:states:::sns:publish.waitForTaskToken",
         "Arguments":{  
            "TopicArn":"arn:aws:sns:region:account-id:myTopic",
            "Message":{  
               "Input":"{% states.input.message %}",
               "TaskToken": "{% $states.context.Task.Token %}"
            }
         },
         "End":true
      }
   }
}
```

## 最適化された Amazon SNS API
<a name="connect-sns-api"></a>
+ [https://docs.aws.amazon.com/sns/latest/api/API_Publish.html](https://docs.aws.amazon.com/sns/latest/api/API_Publish.html)

**Step Functions のパラメータは PascalCase で表されます。**  
ネイティブサービス API が、API アクション `startSyncExecution` などの camelCase である場合でも、`StateMachineArn` などの PascalCase でパラメータを指定します。

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

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

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

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sns:Publish"
            ],
            "Resource": [
                "arn:aws:sns:us-east-1:123456789012:myTopicName"
            ]
        }
    ]
}
```

*パスに基づくリソース、または `TargetArn` か `PhoneNumber` に発行する*

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sns:Publish"
            ],
            "Resource": "*"
        }
    ]
}
```

# Step Functions を使用して Amazon SQS キューにメッセージを送信する
<a name="connect-sqs"></a>

次の Amazon SQS API アクションと、Step Functions ワークフローの `Task` ステートコードの例を使用して、Amazon SQS キューにメッセージを送信できます。

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

Amazon SQS におけるメッセージの受信の詳細については、*Amazon Simple Queue Service デベロッパーガイド*の[メッセージの受信および削除](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/step-receive-delete-message.html)を参照してください。

次のサンプルには、オプションの **MessageAttributes** を付けて Amazon Simple Queue Service (Amazon SQS) メッセージを送信する `Task` ステート (JSONata) が含まれています。

```
{
 "StartAt": "Send to SQS",
 "States": {
   "Send to SQS": {
     "Type": "Task",
     "Resource": "arn:aws:states:::sqs:sendMessage",
     "Arguments": {
       "QueueUrl": "https://sqs.us-east-1.amazonaws.com/account-id/myQueue",
       "MessageBody": "{% $states.input.message %}",
       "MessageAttributes": {
         "my_attribute_no_1": {
           "DataType": "String",
           "StringValue": "attribute1"
         },
         "my_attribute_no_2": {
           "DataType": "String",
           "StringValue": "attribute2"
         }
       }
     },
     "End": true
    }
  }
}
```

次のステートマシンには、Amazon SQS キューにパブリッシュしてから、タスクトークンが返されるのを待機する `Task` ステートが含まれています。「[タスクトークンのコールバックまで待機する](connect-to-resource.md#connect-wait-token)」を参照してください。

```
{  
   "StartAt":"Send message to SQS",
   "States":{  
      "Send message to SQS":{  
         "Type":"Task",
         "Resource":"arn:aws:states:::sqs:sendMessage.waitForTaskToken",
         "Arguments":{  
            "QueueUrl":"https://sqs.us-east-1.amazonaws.com/account-id/myQueue",
            "MessageBody":{  
               "Input" : "{% $states.input.message %}",
               "MyTaskToken" : "{% $states.context.Task.Token %}"
            }
         },
         "End":true
      }
   }
}
```

## 最適化された Amazon SQS API
<a name="connect-sqs-api"></a>
+ [https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html)

**Step Functions のパラメータは PascalCase で表されます。**  
ネイティブサービス API が、API アクション `startSyncExecution` などの camelCase である場合でも、`StateMachineArn` などの PascalCase でパラメータを指定します。

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

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

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

静的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sqs:SendMessage"
            ],
            "Resource": [
                "arn:aws:sqs:us-east-1:123456789012:myQueueName"
            ]
        }
    ]
}
```

動的リソース**

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sqs:SendMessage"
            ],
            "Resource": "*"
        }
    ]
}
```

# 実行中の実行から新しい AWS Step Functions ステートマシンを起動する
<a name="connect-stepfunctions"></a>

Step Functions は、サービス統合として独自の API と統合します。Step Functions を使用して、実行中のタスク状態から直接ステートマシンの新しい実行を開始する方法について説明します。新しいワークフローを構築するときに、[ネストされたワークフロー実行](concepts-nested-workflows.md)を使用して、メインワークフローの複雑さを軽減し、一般的なプロセスを再利用します。

**最適化された Step Functions 統合の主な機能**  
[ジョブの実行 (.sync)](connect-to-resource.md#connect-sync) 統合パターンが利用可能です。

詳細については次を参照してください:
+ [Task から開始する](concepts-nested-workflows.md)
+ [ サービスとの統合](integrate-services.md)
+ [Step Functions でサービス API にパラメータを渡す](connect-parameters.md)

## 最適化された Step Functions API
<a name="connect-stepfunctions-api"></a>
+ [https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html](https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html)

## ワークフローの例
<a name="connect-stepfunctions-api-examples"></a>

以下には、別のステートマシンの実行を開始し、その完了を待機する `Task` 状態が含まれています。

```
{  
   "Type":"Task",
   "Resource":"arn:aws:states:::states:startExecution.sync:2",
   "Arguments":{  
      "Input":{
        "Comment": "Hello world!"
       },
      "StateMachineArn":"arn:aws:states:region:account-id:stateMachine:HelloWorld",
      "Name":"ExecutionName"
   },
   "End":true
}
```

以下には、別のステートマシンの実行を開始する `Task` 状態が含まれています。

```
{  
   "Type":"Task",
   "Resource":"arn:aws:states:::states:startExecution",
   "Arguments":{  
      "Input":{
        "Comment": "Hello world!"
       },
      "StateMachineArn":"arn:aws:states:region:account-id:stateMachine:HelloWorld",
      "Name":"ExecutionName"
   },
   "End":true
}
```

以下には、[コールバック](connect-to-resource.md#connect-wait-token)サービス統合パターンを実行する `Task` の状態が含まれます。

```
{ 
   "Type":"Task",
   "Resource":"arn:aws:states:::states:startExecution.waitForTaskToken",
   "Arguments":{ 
      "Input":{
        "Comment": "Hello world!",
        "token": "{% $states.context.Task.Token %}"
       },
      "StateMachineArn":"arn:aws:states:region:account-id:stateMachine:HelloWorld",
      "Name":"ExecutionName"
   },
   "End":true
}
```

ネストされたワークフロー実行を、それを開始した親実行に関連付けるには、[Context オブジェクト](input-output-contextobject.md)からプルされた実行 ID を含む特別な名前のパラメータを渡します。ネストされた実行を開始するときは、`AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID` という名前のパラメータを使用します。で実行 ID を渡し、コンテキストオブジェクトの ID を参照します`$states.context.Execution.Id`。詳細については、「[Context オブジェクトへのアクセス](input-output-contextobject.md#contextobject-access)」を参照してください。

```
{  
   "Type":"Task",
   "Resource":"arn:aws:states:::states:startExecution.sync",
   "Arguments":{  
      "Input":{
        "Comment": "Hello world!",
        "AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID": "{% $states.context.Execution.Id %}"
       },
      "StateMachineArn":"arn:aws:states:region:account-id:stateMachine:HelloWorld",
      "Name":"ExecutionName"
   },
   "End":true
}
```

 ネストされたステートマシンは、以下を返します。


| [リソース]  | Output | 
| --- | --- | 
| startExecution.sync | String | 
| startExecution.sync:2 | JSON | 

どちらもネストされたステートマシンが完了するのを待機しますが、異なる `Output` 形式を返します。例えば、オブジェクト `{ "MyKey": "MyValue" }` を返す Lambda 関数を作成すると、次のレスポンスが得られます。

startExecution.sync の場合:

```
{
   <other fields>
   "Output": "{ \"MyKey\": \"MyValue\" }" 
}
```

startExecution.sync:2 の場合:

```
{
   <other fields> 
   "Output": {
      "MyKey": "MyValue"
   }
}
```

### ネストされたステートマシンの IAM アクセス許可の設定
<a name="nested-stepfunctions-iam-permissions"></a>

親ステートマシンは、ポーリングとイベントを使用して子ステートマシンが実行を完了したかどうかを判断します。ポーリングには `states:DescribeExecution` のアクセス許可が必要ですが、EventBridge 経由で Step Functions に送信されるイベントには `events:PutTargets`、`events:PutRule`、`events:DescribeRule` のアクセス許可が必要です。IAM ロールにこれらのアクセス許可がない場合、親ステートマシンが子ステートマシンの実行完了を認識するまで、遅延が発生する可能性があります。

1 つのネストされたワークフロー実行のために `StartExecution` を呼び出すステートマシンの場合は、そのステートマシンへの許可を制限する IIAM ポリシーを使用します。

## ネストされた Step Functions ワークフローを呼び出すための IAM ポリシー
<a name="stepfunctions-iam"></a>

1 つのネストされたワークフロー実行のために `StartExecution` を呼び出すステートマシンの場合は、そのステートマシンへの許可を制限する IIAM ポリシーを使用します。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "states:StartExecution"
            ],
            "Resource": [
                "arn:aws:states:us-east-1:123456789012:stateMachine:myStateMachineName"
            ]
        }
    ]
}
```

詳細については次を参照してください:
+ [サービスと Step Functions の統合](integrate-services.md)
+ [Step Functions でサービス API にパラメータを渡す](connect-parameters.md)
+ [実行中の実行から新しい AWS Step Functions ステートマシンを起動する](#connect-stepfunctions)

------
#### [ Synchronous ]<a name="sync-async-iam-policies"></a>

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "states:StartExecution"
            ],
            "Resource": [
                "arn:aws:states:us-east-1:123456789012:stateMachine:stateMachineName"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "states:DescribeExecution",
                "states:StopExecution"
            ],
            "Resource": [
               "arn:aws:states:us-east-1:123456789012:execution:myStateMachineName:*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "events:PutTargets",
                "events:PutRule",
                "events:DescribeRule"
            ],
            "Resource": [
               "arn:aws:events:us-east-1:123456789012:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule"
            ]
        }
    ]
}
```

------
#### [ Asynchronous ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "states:StartExecution"
            ],
            "Resource": [
                "arn:aws:states:us-east-1:123456789012:stateMachine:myStateMachineName"
            ]
        }
    ]
}
```

------

**必要な ARN のタイプ**  
**Synchronous** に関するポリシーでは、`states:StartExecution` にステートマシン ARN が必要ですが、`states:DescribeExecution` と `states:StopExecution` には実行 ARN が必要であることに注意してください。  
誤って 3 つのアクションをすべて組み合わせた場合、JSON は有効ですが、IAM ポリシーは正しくありません。ポリシーが正しくないと、ワークフローの実行中にワークフローがスタックしたり、アクセスの問題が発生したりする可能性があります。

ネストされたワークフロー実行の詳細については、[Step Functions で Task 状態からワークフロー実行を開始する](concepts-nested-workflows.md) を参照してください。