

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

# sam remote invoke を使用したクラウドでのテストの概要
<a name="using-sam-cli-remote-invoke"></a>

 AWS Serverless Application Model コマンドラインインターフェイス (AWS SAM CLI) `sam remote invoke` コマンドを使用して、 でサポートされている AWS リソースを操作します AWS クラウド。`sam remote invoke` を使用して、次のリソースを呼び出します。
+ **Amazon Kinesis Data Streams** — Kinesis Data Streams アプリケーションにデータレコードを送信します。
+ **AWS Lambda** – イベントを呼び出して Lambda 関数に渡します。
+ **Amazon Simple Queue Service (Amazon SQS)** – Amazon SQS キューにメッセージを送信します。
+ **AWS Step Functions** – Step Functions ステートマシンを呼び出して実行を開始します。

の概要については AWS SAM CLI、「」を参照してください。 [とは AWS SAM CLI](what-is-sam-overview.md#what-is-sam-cli)

一般的な開発ワークフローでの `sam remote invoke` の使用例については、「[ステップ 5: で 関数を操作する AWS クラウド](serverless-getting-started-hello-world.md#serverless-getting-started-hello-world-remote-invoke)」を参照してください。

**Topics**
+ [sam remote invoke コマンドの使用](#using-sam-cli-remote-invoke-use)
+ [sam リモート呼び出しコマンド オプションの使用](#using-sam-cli-remote-invoke-options)
+ [プロジェクト設定ファイルを設定する](#using-sam-cli-remote-invoke-configure)
+ [例](#using-sam-cli-remote-invoke-examples)
+ [関連リンク](#using-sam-cli-remote-invoke-links)

## 前提条件
<a name="using-sam-cli-remote-invoke-prerequisites"></a>

`sam remote invoke` を使用するには、次を実行して AWS SAM CLI をインストールします。
+ [AWS SAM 前提条件](prerequisites.md).
+ [AWS SAM CLI のインストール](install-sam-cli.md).

また、 の最新バージョンにアップグレードすることをお勧めします AWS SAM CLI。詳細については[AWS SAM CLI のアップグレード](manage-sam-cli-versions.md#manage-sam-cli-versions-upgrade)を参照してください。

`sam remote invoke` を使用する前に、次の基本を理解しておくことをお勧めします。
+ [AWS SAM CLI の設定](using-sam-cli-configure.md).
+ [でアプリケーションを作成する AWS SAM](using-sam-cli-init.md).
+ [を使用した の構築の概要 AWS SAM](using-sam-cli-build.md).
+ [を使用したデプロイの概要 AWS SAM](using-sam-cli-deploy.md).
+ [を使用して sam sync に同期する方法の概要 AWS クラウド](using-sam-cli-sync.md).

## sam remote invoke コマンドの使用
<a name="using-sam-cli-remote-invoke-use"></a>

このコマンドを使用する前に、リソースが AWS クラウドにデプロイされている必要があります。

次のコマンド構造を使用し、プロジェクトのルート ディレクトリから実行します。

```
$ sam remote invoke <arguments> <options>
```

**注記**  
このページでは、コマンドプロンプトで提供されるオプションについて説明します。オプションは、コマンドプロンプトで渡す代わりに、プロジェクトの設定ファイルで設定することもできます。詳細については、「[プロジェクト設定を構成する](using-sam-cli-configure.md#using-sam-cli-configure-project)」を参照してください。

`sam remote invoke` 引数とオプションの説明については、「[sam remote invoke](sam-cli-command-reference-remote-invoke.md)」を参照してください。

### Kinesis Data Streams の使用
<a name="using-sam-cli-remote-invoke-use-kinesis"></a>

データレコードを Kinesis Data Streams アプリケーションに送信できます。 AWS SAM CLI はデータレコードを送信し、シャード ID とシーケンス番号を返します。以下に例を示します。

```
$ sam remote invoke KinesisStream --stack-name kinesis-example --event hello-world
	
	Putting record to Kinesis data stream KinesisStream                                                             
	Auto converting value 'hello-world' into JSON '"hello-world"'. If you don't want auto-conversion, please provide
	a JSON string as event                                                                                          
	{
	  "ShardId": "shardId-000000000000",
	  "SequenceNumber": "49646251411914806775980850790050483811301135051202232322"
	}%
```

**データレコードを送信するには**

1. Kinesis Data Streams アプリケーションの引数としてリソース ID 値を指定します。有効なリソース ID については、「[リソース ID](sam-cli-command-reference-remote-invoke.md#sam-cli-command-reference-remote-invoke-args-resource-id)」を参照してください。

1. Kinesis Data Streams アプリケーションに送信するイベントとしてデータレコードを指定します。イベントは、`--event` オプションを使用してコマンドラインで提供することも、`--event-file` を使用してファイルから提供することもできます。イベントを指定しない場合、 AWS SAM CLI は空のイベントを送信します。

### Lambda 関数を使用する
<a name="using-sam-cli-remote-invoke-use-lambda"></a>

クラウド内の Lambda 関数を呼び出して、空のイベントを渡すか、コマンドラインまたはファイルからイベントを提供することができます。は Lambda AWS SAM CLI関数を呼び出し、レスポンスを返します。以下に例を示します。

```
$ sam remote invoke HelloWorldFunction --stack-name sam-app

Invoking Lambda Function HelloWorldFunction                                       
START RequestId: d5ef494b-5f45-4086-86fd-d7322fa1a1f9 Version: $LATEST
END RequestId: d5ef494b-5f45-4086-86fd-d7322fa1a1f9
REPORT RequestId: d5ef494b-5f45-4086-86fd-d7322fa1a1f9  Duration: 6.62 ms       Billed Duration: 7 ms     Memory Size: 128 MB     Max Memory Used: 67 MB  Init Duration: 164.06 ms
{"statusCode":200,"body":"{\"message\":\"hello world\"}"}%
```

**Lambda 関数を呼び出すには**

1. Lambda 関数の引数としてリソース ID の値を指定します。有効なリソース ID については、「[リソース ID](sam-cli-command-reference-remote-invoke.md#sam-cli-command-reference-remote-invoke-args-resource-id)」を参照してください。

1. Lambda 関数に送信するイベントを指定します。イベントは、`--event` オプションを使用してコマンドラインで提供することも、`--event-file` を使用してファイルから提供することもできます。イベントを指定しない場合、 AWS SAM CLI は空のイベントを送信します。

#### レスポンスストリーミングが設定された Lambda 関数
<a name="using-sam-cli-remote-invoke-invoke-stream"></a>

`sam remote invoke` コマンドは、レスポンスをストリーミングするように設定された Lambda 関数をサポートします。 AWS SAM テンプレートの `FunctionUrlConfig`プロパティを使用してレスポンスをストリーミングするように Lambda 関数を設定できます。`sam remote invoke` を使用する場合、 AWS SAM CLI は Lambda 設定を自動的に検出して、レスポンスストリーミングで呼び出します。

例については、[レスポンスをストリーミングするように設定された Lambda 関数を呼び出す](#using-sam-cli-remote-invoke-examples-lambda-stream)を参照してください。

#### 共有可能なテストイベントをクラウド内の Lambda 関数に渡す
<a name="using-sam-cli-remote-invoke-shareable"></a>

共有可能なテストイベントは、同じ AWS アカウント内の他のユーザーと共有できるテストイベントです。詳細については、「*AWS Lambda デベロッパーガイド*」の「[共有可能なテストイベント](https://docs.aws.amazon.com/lambda/latest/dg/testing-functions.html#creating-shareable-events)」を参照してください。

##### 共有可能なテストイベントへのアクセスと管理
<a name="using-sam-cli-remote-invoke-shareable-access"></a>

`sam remote test-event` コマンドを使用して AWS SAM CLI、共有可能なテストイベントにアクセスして管理できます。例えば、`sam remote test-event` を使用して以下を実行できます。
+ Amazon EventBridge スキーマレジストリから共有可能なテストイベントを取得します。
+ 共有可能なテストイベントをローカルで変更し、EventBridge スキーマレジストリにアップロードします。
+ EventBridge スキーマレジストリから共有可能なテストイベントを削除します。

詳細については[sam remote test-event を使用したクラウドテストの概要](using-sam-cli-remote-test-event.md)を参照してください。

##### 共有可能なテストイベントをクラウド内の Lambda 関数に渡す
<a name="using-sam-cli-remote-invoke-shareable-pass"></a>

共有可能なテストイベントを EventBridge スキーマレジストリからクラウドの Lambda 関数に渡すには、`--test-event-name` オプションを使用して共有可能なテストイベントの名前を指定します。以下に例を示します。

```
$ sam remote invoke HelloWorldFunction --stack-name sam-app --test-event-name demo-event
```

共有可能なテストイベントをローカルに保存する場合は、`--event-file` オプションを使用してローカルテストイベントのファイルパスと名前を指定できます。以下に例を示します。

```
$ sam remote invoke HelloWorldFunction --stack-name sam-app --event-file demo-event.json
```

### Amazon SQS での の使用
<a name="using-sam-cli-remote-invoke-use-sqs"></a>

Amazon SQSキューにメッセージを送信できます。は AWS SAM CLI以下を返します。
+ メッセージ ID
+ メッセージ本文の MD5
+ レスポンスメタデータ

 以下に例を示します。

```
$ sam remote invoke MySqsQueue --stack-name sqs-example -event hello

Sending message to SQS queue MySqsQueue                                                                         
{
  "MD5OfMessageBody": "5d41402abc4b2a76b9719d911017c592",
  "MessageId": "05c7af65-9ae8-4014-ae28-809d6d8ec652"
}%
```

**単一のメッセージを送信するには**

1. Amazon SQS キューの引数としてリソース ID 値を指定します。有効なリソース ID については、「[リソース ID](sam-cli-command-reference-remote-invoke.md#sam-cli-command-reference-remote-invoke-args-resource-id)」を参照してください。

1. Amazon SQSキューに送信するイベントを指定します。イベントは、`--event` オプションを使用してコマンドラインで提供することも、`--event-file` を使用してファイルから提供することもできます。イベントを指定しない場合、 AWS SAM CLI は空のイベントを送信します。

### Step Functions を使って実行する
<a name="using-sam-cli-remote-invoke-use-sf"></a>

Step Functions ステート マシンを呼び出して実行を開始できます。 AWS SAM CLI はステートマシンワークフローが完了するのを待ち、実行の最後のステップの出力を返します。以下に例を示します。

```
$ sam remote invoke HelloWorldStateMachine --stack-name state-machine-example --event '{"is_developer": true}'

Invoking Step Function HelloWorldStateMachine                                                                   
"Hello Developer World"%
```

**ステートマシンを呼び出すには**

1. Step Functions ステートマシンの引数としてリソース ID の値を指定します。有効なリソース ID については、「[リソース ID](sam-cli-command-reference-remote-invoke.md#sam-cli-command-reference-remote-invoke-args-resource-id)」を参照してください。

1. ステートマシンに送信するイベントを指定します。イベントは、`--event` オプションを使用してコマンドラインで提供することも、`--event-file` を使用してファイルから提供することもできます。イベントを指定しない場合、 AWS SAM CLI は空のイベントを送信します。

## sam リモート呼び出しコマンド オプションの使用
<a name="using-sam-cli-remote-invoke-options"></a>

このセクションでは、`sam remote invoke` コマンドで使用できる主なオプションのいくつかを説明します。 オプションの完全なリストについては、「[sam remote invoke](sam-cli-command-reference-remote-invoke.md)」を参照してください。

### リソースにイベントを渡します。
<a name="using-sam-cli-remote-invoke-options-event"></a>

以下のオプションを使用して、クラウド内のリソースにイベントを渡します。
+ `--event` — コマンドラインでイベントを渡します。
+ `--event-file` — ファイルからイベントを渡します。

#### Lambda での例
<a name="using-sam-cli-remote-invoke-options-event-lambda-examples"></a>

**`--event` を使用して、コマンドラインでイベントを文字列値として渡します。**

```
$ sam remote invoke HelloWorldFunction --stack-name sam-app --event '{"message": "hello!"}'

Invoking Lambda Function HelloWorldFunction                                                                                                                                                                                                                     
START RequestId: b992292d-1fac-4aa2-922a-c9dc5c6fceab Version: $LATEST
END RequestId: b992292d-1fac-4aa2-922a-c9dc5c6fceab
REPORT RequestId: b992292d-1fac-4aa2-922a-c9dc5c6fceab  Duration: 16.41 ms      Billed Duration: 17 ms  Memory Size: 128 MB     Max Memory Used: 67 MB  Init Duration: 185.96 ms
{"statusCode":200,"body":"{\"message\":\"hello!\"}"}%
```

**`--event-file` を使用してファイルからのイベントを渡し、ファイルへのパスを指定します。**

```
$ cat event.json
			
{"message": "hello from file"}%    
			
$ sam remote invoke HelloWorldFunction --stack-name sam-app --event-file event.json       

Invoking Lambda Function HelloWorldFunction                                                                                                                                                                                                                     
START RequestId: 3bc71f7d-153a-4b1e-8c9a-901d91b1bec9 Version: $LATEST
END RequestId: 3bc71f7d-153a-4b1e-8c9a-901d91b1bec9
REPORT RequestId: 3bc71f7d-153a-4b1e-8c9a-901d91b1bec9  Duration: 21.15 ms      Billed Duration: 22 ms  Memory Size: 128 MB     Max Memory Used: 67 MB
{"statusCode":200,"body":"{\"message\":\"hello from file\"}"}%
```

**`stdin` を使用してイベントを渡します。**

```
$ cat event.json
			
{"message": "hello from file"}%    
                                                                       
$ cat event.json | sam remote invoke HelloWorldFunction --stack-name sam-app --event-file -

Reading event from stdin (you can also pass it from file with --event-file)                               
Invoking Lambda Function HelloWorldFunction                                                               
START RequestId: 85ecc902-8ad0-4a2b-a8c8-9bb4f65f5a7a Version: $LATEST
END RequestId: 85ecc902-8ad0-4a2b-a8c8-9bb4f65f5a7a
REPORT RequestId: 85ecc902-8ad0-4a2b-a8c8-9bb4f65f5a7a  Duration: 1.36 ms       Billed Duration: 2 ms   Memory Size: 128 MB       Max Memory Used: 67 MB
{"statusCode":200,"body":"{\"message\":\"hello from file\"}"}%
```

### AWS SAMCLI レスポンス出力を設定します。
<a name="using-sam-cli-remote-invoke-options-output"></a>

`sam remote invoke` でサポートされているリソースをで呼び出すと、 AWS SAMCLI は次の内容を含むレスポンスを返します。
+ **リクエストメタデータ** – リクエストに関連するメタデータです。これには、リクエスト ID とリクエスト開始時間が含まれます。
+ **Resource Response** — クラウド内で呼び出された後のリソースからのレスポンスです。

`--output` オプションを使用して、出力レスポンスを設定できます AWS SAM CLI。以下のオプション値を使用できます。
+ `json` – メタデータとリソースレスポンスが JSON 構造で返されます。レスポンスには完全な SDK 出力が含まれます。
+ `text` – メタデータがテキスト構造で返されます。リソースレスポンスは、リソースの出力形式で返されます。

以下は、`json` 出力の例です。

```
$ sam remote invoke --stack-name sam-app --output json

Invoking Lambda Function HelloWorldFunction                                                                                                                                                                                                                     
{
  "ResponseMetadata": {
    "RequestId": "3bdf9a30-776d-4a90-94a6-4cccc0fc7b41",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Mon, 19 Jun 2023 17:15:46 GMT",
      "content-type": "application/json",
      "content-length": "57",
      "connection": "keep-alive",
      "x-amzn-requestid": "3bdf9a30-776d-4a90-94a6-4cccc0fc7b41",
      "x-amzn-remapped-content-length": "0",
      "x-amz-executed-version": "$LATEST",
      "x-amz-log-result": "U1RBUlQgUmVxdWVzdElkOiAzYmRmOWEzMC03NzZkLTRhOTAtOTRhNi00Y2NjYzBmYzdiNDEgVmVyc2lvbjogJExBVEVTVApFTkQgUmVxdWVzdElkOiAzYmRmOWEzMC03NzZkLTRhOTAtOTRhNi00Y2NjYzBmYzdiNDEKUkVQT1JUIFJlcXVlc3RJZDogM2JkZjlhMzAtNzc2ZC00YTkwLTk0YTYtNGNjY2MwZmM3YjQxCUR1cmF0aW9uOiA4LjIzIG1zCUJpbGxlZCBEdXJhdGlvbjogOSBtcwlNZW1vcnkgU2l6ZTogMTI4IE1CCU1heCBNZW1vcnkgVXNlZDogNjggTUIJCg==",
      "x-amzn-trace-id": "root=1-64908d42-17dab270273fcc6b527dd6b8;sampled=0;lineage=2301f8dc:0"
    },
    "RetryAttempts": 0
  },
  "StatusCode": 200,
  "LogResult": "U1RBUlQgUmVxdWVzdElkOiAzYmRmOWEzMC03NzZkLTRhOTAtOTRhNi00Y2NjYzBmYzdiNDEgVmVyc2lvbjogJExBVEVTVApFTkQgUmVxdWVzdElkOiAzYmRmOWEzMC03NzZkLTRhOTAtOTRhNi00Y2NjYzBmYzdiNDEKUkVQT1JUIFJlcXVlc3RJZDogM2JkZjlhMzAtNzc2ZC00YTkwLTk0YTYtNGNjY2MwZmM3YjQxCUR1cmF0aW9uOiA4LjIzIG1zCUJpbGxlZCBEdXJhdGlvbjogOSBtcwlNZW1vcnkgU2l6ZTogMTI4IE1CCU1heCBNZW1vcnkgVXNlZDogNjggTUIJCg==",
  "ExecutedVersion": "$LATEST",
  "Payload": "{\"statusCode\":200,\"body\":\"{\\\"message\\\":\\\"hello world\\\"}\"}"
}%
```

`json` 出力を指定すると、レスポンス全体が `stdout` に返されます。以下に例を示します。

```
$ sam remote invoke --stack-name sam-app --output json 1> stdout.log

Invoking Lambda Function HelloWorldFunction           
                                                                                                                                                                                                          
$ cat stdout.log
			
{
  "ResponseMetadata": {
    "RequestId": "d30d280f-8188-4372-bc94-ce0f1603b6bb",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Mon, 19 Jun 2023 17:35:56 GMT",
      "content-type": "application/json",
      "content-length": "57",
      "connection": "keep-alive",
      "x-amzn-requestid": "d30d280f-8188-4372-bc94-ce0f1603b6bb",
      "x-amzn-remapped-content-length": "0",
      "x-amz-executed-version": "$LATEST",
      "x-amz-log-result": "U1RBUlQgUmVxdWVzdElkOiBkMzBkMjgwZi04MTg4LTQzNzItYmM5NC1jZTBmMTYwM2I2YmIgVmVyc2lvbjogJExBVEVTVApFTkQgUmVxdWVzdElkOiBkMzBkMjgwZi04MTg4LTQzNzItYmM5NC1jZTBmMTYwM2I2YmIKUkVQT1JUIFJlcXVlc3RJZDogZDMwZDI4MGYtODE4OC00MzcyLWJjOTQtY2UwZjE2MDNiNmJiCUR1cmF0aW9uOiA0LjE2IG1zCUJpbGxlZCBEdXJhdGlvbjogNSBtcwlNZW1vcnkgU2l6ZTogMTI4IE1CCU1heCBNZW1vcnkgVXNlZDogNjcgTUIJSW5pdCBEdXJhdGlvbjogMTU4LjM5IG1zCQo=",
      "x-amzn-trace-id": "root=1-649091fc-771473c7778689627a6122b7;sampled=0;lineage=2301f8dc:0"
    },
    "RetryAttempts": 0
  },
  "StatusCode": 200,
  "LogResult": "U1RBUlQgUmVxdWVzdElkOiBkMzBkMjgwZi04MTg4LTQzNzItYmM5NC1jZTBmMTYwM2I2YmIgVmVyc2lvbjogJExBVEVTVApFTkQgUmVxdWVzdElkOiBkMzBkMjgwZi04MTg4LTQzNzItYmM5NC1jZTBmMTYwM2I2YmIKUkVQT1JUIFJlcXVlc3RJZDogZDMwZDI4MGYtODE4OC00MzcyLWJjOTQtY2UwZjE2MDNiNmJiCUR1cmF0aW9uOiA0LjE2IG1zCUJpbGxlZCBEdXJhdGlvbjogNSBtcwlNZW1vcnkgU2l6ZTogMTI4IE1CCU1heCBNZW1vcnkgVXNlZDogNjcgTUIJSW5pdCBEdXJhdGlvbjogMTU4LjM5IG1zCQo=",
  "ExecutedVersion": "$LATEST",
  "Payload": "{\"statusCode\":200,\"body\":\"{\\\"message\\\":\\\"hello world\\\"}\"}"
}%
```

以下は、`text` 出力の例です。

```
$ sam remote invoke --stack-name sam-app --output text

Invoking Lambda Function HelloWorldFunction                                                                                                                                                                                                                     
START RequestId: 4dbacc43-1ec6-47c2-982b-9dc4620144d6 Version: $LATEST
END RequestId: 4dbacc43-1ec6-47c2-982b-9dc4620144d6
REPORT RequestId: 4dbacc43-1ec6-47c2-982b-9dc4620144d6  Duration: 9.13 ms       Billed Duration: 10 ms  Memory Size: 128 MB     Max Memory Used: 67 MB  Init Duration: 165.50 ms
{"statusCode":200,"body":"{\"message\":\"hello world\"}"}%
```

`text` 出力を指定すると、Lambda 関数ランタイム出力 (ログなど) が `stderr` に返されます。Lambda 関数ペイロードは `stdout` に返されます。以下に例を示します。

```
$ sam remote invoke --stack-name sam-app --output text 2> stderr.log

{"statusCode":200,"body":"{\"message\":\"hello world\"}"}% 
                                                                                                                                                                                                     
$ cat stderr.log

Invoking Lambda Function HelloWorldFunction
START RequestId: 82273c3b-aa3a-4d16-8f1c-1d2ad3ace891 Version: $LATEST
END RequestId: 82273c3b-aa3a-4d16-8f1c-1d2ad3ace891
REPORT RequestId: 82273c3b-aa3a-4d16-8f1c-1d2ad3ace891  Duration: 40.62 ms      Billed Duration: 41 ms  Memory Size: 128 MB     Max Memory Used: 68 MB

$ sam remote invoke --stack-name sam-app --output text 1> stdout.log
 
Invoking Lambda Function HelloWorldFunction                                                                                                                                                                                                                     
START RequestId: 74acaa9f-5b80-4a5c-b3b8-ffaccb84cbbd Version: $LATEST
END RequestId: 74acaa9f-5b80-4a5c-b3b8-ffaccb84cbbd
REPORT RequestId: 74acaa9f-5b80-4a5c-b3b8-ffaccb84cbbd  Duration: 2.31 ms       Billed Duration: 3 ms   Memory Size: 128 MB     Max Memory Used: 67 MB

$ cat stdout.log

{"statusCode":200,"body":"{\"message\":\"hello world\"}"}%
```

### Boto3 パラメータをカスタマイズする
<a name="using-sam-cli-remote-invoke-options-boto3"></a>

の場合`sam remote invoke` AWS SAM CLI、 は AWS SDK for Python (Boto3) を使用してクラウド内のリソースとやり取りします。`--parameter` オプションを使用して、Boto3 パラメータをカスタマイズすることができます。サポートされるカスタマイズ可能なパラメータのリストについては、「`--parameter`」を参照してください。

#### 例
<a name="using-sam-cli-remote-invoke-options-boto3-examples"></a>

**パラメータ値を検証し、許可を確認するための Lambda 関数の呼び出し**

```
$ sam remote invoke HelloWorldFunction --stack-name sam-app --parameter InvocationType="DryRun"
```

**1 つのコマンドで `--parameter` オプションを複数回使用して、複数のパラメータを指定することができます。**

```
$ sam remote invoke HelloWorldFunction --stack-name sam-app --parameter InvocationType="Event" --parameter LogType="None"
```

### その他のオプション
<a name="using-sam-cli-remote-invoke-options-other"></a>

`sam remote invoke` オプションの完全なリストについては、「[sam remote invoke](sam-cli-command-reference-remote-invoke.md)」を参照してください。

## プロジェクト設定ファイルを設定する
<a name="using-sam-cli-remote-invoke-configure"></a>

設定ファイルで `sam remote invoke` を設定するには、テーブルで `remote_invoke` を使用します。以下は、`sam remote invoke` コマンドのデフォルト値を設定する `samconfig.toml` ファイルの例です。

```
...
version =0.1

[default]
...
[default.remote_invoke.parameters]
stack_name = "cloud-app"
event = '{"message": "Hello!"}'
```

## 例
<a name="using-sam-cli-remote-invoke-examples"></a>

を使用する基本的な例については`sam remote invoke`、 *AWS コンピューティングブログ*の[AWS SAM 「リモートでの 関数のテスト AWS Lambda](https://aws.amazon.com/blogs/compute/testing-aws-lambda-functions-with-aws-sam-remote-invoke/)」を参照してください。

### Kinesis Data Streams の例
<a name="using-sam-cli-remote-invoke-examples-kinesis"></a>

#### 基本的な例
<a name="using-sam-cli-remote-invoke-examples-kinesis-basic"></a>

**ファイルから Kinesis Data Streams アプリケーションにデータレコードを送信します。Kinesis Data Streams アプリケーションは、リソース ID の ARN を指定することで識別されます。**

```
$ sam remote invoke arn:aws:kinesis:us-west-2:01234567890:stream/kinesis-example-KinesisStream-BgnLcAey4xUQ --event-file event.json
```

**コマンドラインで指定されるイベントを Kinesis Data Streams アプリケーションに送信します。**

```
$ sam remote invoke KinesisStream --stack-name kinesis-example --event hello-world

Putting record to Kinesis data stream KinesisStream                                                             
Auto converting value 'hello-world' into JSON '"hello-world"'. If you don't want auto-conversion, please provide
a JSON string as event                                                                                          
{
  "ShardId": "shardId-000000000000",
  "SequenceNumber": "49646251411914806775980903986194508740483329854174920706"
}%
```

**Kinesis Data Streams アプリケーションの物理 ID を取得します。次に、コマンドラインにイベントを指定します。**

```
$ sam list resources --stack-name kinesis-example --output json

[
  {
    "LogicalResourceId": "KinesisStream",
    "PhysicalResourceId": "kinesis-example-KinesisStream-ZgnLcQey4xUQ"
  }
]

$ sam remote invoke kinesis-example-KinesisStream-ZgnLcQey4xUQ --event hello

Putting record to Kinesis data stream KinesisStream                                                             
Auto converting value 'hello' into JSON '"hello"'. If you don't want auto-conversion, please provide a JSON     
string as event                                                                                                 
{
  "ShardId": "shardId-000000000000",
  "SequenceNumber": "49646251411914806775980904340716841045751814812900261890"
}%
```

**コマンドラインに JSON 文字列をイベントとして指定します。**

```
$ sam remote invoke KinesisStream --stack-name kinesis-example --event '{"method": "GET", "body": ""}'                      

Putting record to Kinesis data stream KinesisStream                                                             
{
  "ShardId": "shardId-000000000000",
  "SequenceNumber": "49646251411914806775980904492868617924990209230536441858"
}%
```

**Kinesis Data Streams アプリケーションに空のイベントを送信します。**

```
$ sam remote invoke KinesisStream --stack-name kinesis-example

Putting record to Kinesis data stream KinesisStream                                                             
{
  "ShardId": "shardId-000000000000",
  "SequenceNumber": "49646251411914806775980904866469008589597168190416224258"
}%
```

**JSON 形式でレスポンスを返します AWS SAM CLI。**

```
$ sam remote invoke KinesisStream --stack-name kinesis-example --event '{"hello": "world"}' --output json

Putting record to Kinesis data stream KinesisStream                                                             
{
  "ShardId": "shardId-000000000000",
  "SequenceNumber": "49646251411914806775980905078409420803696667195489648642",
  "ResponseMetadata": {
    "RequestId": "ebbbd307-3e9f-4431-b67c-f0715e9e353e",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "x-amzn-requestid": "ebbbd307-3e9f-4431-b67c-f0715e9e353e",
      "x-amz-id-2": "Q3yBcgTwtPaQTV26IKclbECmZikUYOzKY+CzcxA84ZHgCkc5T2N/ITWg6RPOQcWw8Gn0tNPcEJBEHyVVqboJAPgCritqsvCu",
      "date": "Thu, 09 Nov 2023 18:13:10 GMT",
      "content-type": "application/x-amz-json-1.1",
      "content-length": "110"
    },
    "RetryAttempts": 0
  }
}%
```

**JSON 出力を標準出力に返します。**

```
$ sam remote invoke KinesisStream --stack-name kinesis-example --event '{"hello": "world"}' --output json 1> stdout.log

Putting record to Kinesis data stream KinesisStream                                                             

$ cat stdout.log
{
  "ShardId": "shardId-000000000000",
  "SequenceNumber": "49646251411914806775980906397777867595039988349006774274",
  "ResponseMetadata": {
    "RequestId": "f4290006-d84b-b1cd-a9ee-28306eeb2939",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "x-amzn-requestid": "f4290006-d84b-b1cd-a9ee-28306eeb2939",
      "x-amz-id-2": "npCqz+IBKpoL4sQ1ClbUmxuJlbeA24Fx1UgpIrS6mm2NoIeV2qdZSN5AhNurdssykXajBrXaC9anMhj2eG/h7Hnbf+bPuotU",
      "date": "Thu, 09 Nov 2023 18:33:26 GMT",
      "content-type": "application/x-amz-json-1.1",
      "content-length": "110"
    },
    "RetryAttempts": 0
  }
}%
```

### Lambda での例
<a name="using-sam-cli-remote-invoke-examples-lambda"></a>

#### 基本的な例
<a name="using-sam-cli-remote-invoke-examples-lambda-basic"></a>

**ARN をリソース ID として指定して Lambda 関数を呼び出します。**

```
$ sam remote invoke arn:aws:lambda:us-west-2:012345678910:function:sam-app-HelloWorldFunction-ohRFEn2RuAvp
```

**論理 ID をリソース ID として指定して Lambda 関数を呼び出します。**

また、 `--stack-name`オプションを使用して CloudFormation スタック名を指定する必要があります。以下に例を示します。

```
$ sam remote invoke HelloWorldFunction --stack-name sam-app
```

アプリケーションに単一の Lambda 関数が含まれている場合、その論理 ID を指定する必要はありません。`--stack-name` オプションのみを指定できます。以下に例を示します。

```
$ sam remote invoke --stack-name sam-app
```

**物理 ID をリソース ID として指定して Lambda 関数を呼び出します。**

物理 ID は、 を使用してデプロイするときに作成されます CloudFormation。

```
$ sam remote invoke sam-app-HelloWorldFunction-TZvxQRFNv0k4
```

**子スタックの Lambda 関数を呼び出します。**

この例では、アプリケーションには次のディレクトリ構造が含まれています。

```
lambda-example
├── childstack
│   ├── function
│   │   ├── __init__.py
│   │   ├── app.py
│   │   └── requirements.txt
│   └── template.yaml
├── events
│   └── event.json
├── samconfig.toml
└── template.yaml
```

`childstack` の Lambda 関数を呼び出すには、以下を実行します。

```
$ sam remote invoke ChildStack/HelloWorldFunction --stack-name lambda-example

Invoking Lambda Function HelloWorldFunction                                                                     
START RequestId: 207a864b-e67c-4307-8478-365b004d4bcd Version: $LATEST
END RequestId: 207a864b-e67c-4307-8478-365b004d4bcd
REPORT RequestId: 207a864b-e67c-4307-8478-365b004d4bcd  Duration: 1.27 ms       Billed Duration: 2 ms   Memory Size: 128 MB     Max Memory Used: 36 MB  Init Duration: 111.07 ms
{"statusCode": 200, "body": "{\"message\": \"Hello\", \"received_event\": {}}"}%
```

#### レスポンスをストリーミングするように設定された Lambda 関数を呼び出す
<a name="using-sam-cli-remote-invoke-examples-lambda-stream"></a>

この例では、 AWS SAM CLI を使用して、レスポンスをストリーミングするように設定された Lambda 関数が含まれる新しいサーバーレスアプリケーションを初期化します。アプリケーションを にデプロイ AWS クラウド し`sam remote invoke`、 を使用してクラウド内の 関数を操作します。

まず、`sam init` コマンドを実行して新しいサーバーレスアプリケーションを作成することから始めます。**[Lambda レスポンスストリーミング]** クイックスタートテンプレートを選択して、アプリケーションに **lambda-streaming-nodejs-app** という名前を付けます。

```
$ sam init
	
	You can preselect a particular runtime or package type when using the `sam init` experience.
	Call `sam init --help` to learn more.
	
	Which template source would you like to use?
	        1 - AWS Quick Start Templates
	        2 - Custom Template Location
	Choice: 1
	
	Choose an AWS Quick Start application template
	        1 - Hello World Example
	        ...
	        9 - Lambda Response Streaming
	        ...
	        15 - Machine Learning
	Template: 9
	
	Which runtime would you like to use?
	        1 - go (provided.al2)
	        2 - nodejs18.x
	        3 - nodejs16.x
	Runtime: 2
	
	Based on your selections, the only Package type available is Zip.
	We will proceed to selecting the Package type as Zip.
	
	Based on your selections, the only dependency manager available is npm.
	We will proceed copying the template using npm.
	
	Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]: ENTER
	
	Would you like to enable monitoring using CloudWatch Application Insights?
	For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]: ENTER
	
	Project name [sam-app]: lambda-streaming-nodejs-app
	
	    -----------------------
	    Generating application:
	    -----------------------
	    Name: lambda-streaming-nodejs-app
	    Runtime: nodejs18.x
	    Architectures: x86_64
	    Dependency Manager: npm
	    Application Template: response-streaming
	    Output Directory: .
	    Configuration file: lambda-streaming-nodejs-app/samconfig.toml
	    
	    Next steps can be found in the README file at lambda-streaming-nodejs-app/README.md
	        
	
	Commands you can use next
	=========================
	[*] Create pipeline: cd lambda-streaming-nodejs-app && sam pipeline init --bootstrap
	[*] Validate SAM template: cd lambda-streaming-nodejs-app && sam validate
	[*] Test Function in the Cloud: cd lambda-streaming-nodejs-app && sam sync --stack-name {stack-name} --watch
```

は AWS SAM CLI、次の構造でプロジェクトを作成します。

```
lambda-streaming-nodejs-app
	├── README.md
	├── __tests__
	│   └── unit
	│       └── index.test.js
	├── package.json
	├── samconfig.toml
	├── src
	│   └── index.js
	└── template.yaml
```

以下は、Lambda 関数コードの例です。

```
exports.handler = awslambda.streamifyResponse(
	  async (event, responseStream, context) => {
	    const httpResponseMetadata = {
	      statusCode: 200,
	      headers: {
	        "Content-Type": "text/html",
	        "X-Custom-Header": "Example-Custom-Header"
	      }
	    };
	
	    responseStream = awslambda.HttpResponseStream.from(responseStream, httpResponseMetadata);
	    // It's recommended to use a `pipeline` over the `write` method for more complex use cases.
	    // Learn more: https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html
	    responseStream.write("<html>");
	    responseStream.write("<p>First write!</p>");
	
	    responseStream.write("<h1>Streaming h1</h1>");
	    await new Promise(r => setTimeout(r, 1000));
	    responseStream.write("<h2>Streaming h2</h2>");
	    await new Promise(r => setTimeout(r, 1000));
	    responseStream.write("<h3>Streaming h3</h3>");
	    await new Promise(r => setTimeout(r, 1000));
	
	    // Long strings will be streamed
	    const loremIpsum1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae mi tincidunt tellus ultricies dignissim id et diam. Morbi pharetra eu nisi et finibus. Vivamus diam nulla, vulputate et nisl cursus, pellentesque vehicula libero. Cras imperdiet lorem ante, non posuere dolor sollicitudin a. Vestibulum ipsum lacus, blandit nec augue id, lobortis dictum urna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Morbi auctor orci eget tellus aliquam, non maximus massa porta. In diam ante, pulvinar aliquam nisl non, elementum hendrerit sapien. Vestibulum massa nunc, mattis non congue vitae, placerat in quam. Nam vulputate lectus metus, et dignissim erat varius a.";
	    responseStream.write(`<p>${loremIpsum1}</p>`);
	    await new Promise(r => setTimeout(r, 1000));
	
	    responseStream.write("<p>DONE!</p>");
	    responseStream.write("</html>");
	    responseStream.end();
	  }
	);
```

以下は、`template.yaml` ファイルの例です。Lambda 関数のレスポンスストリーミングは、`FunctionUrlConfig` プロパティを使用して設定されます。

```
AWSTemplateFormatVersion: '2010-09-09'
	Transform: AWS::Serverless-2016-10-31
	
	Description: >
	  Sample SAM Template for lambda-streaming-nodejs-app
	  
	Resources:
	  StreamingFunction:
	    Type: AWS::Serverless::Function
	    Properties:
	      CodeUri: src/
	      Handler: index.handler
	      Runtime: nodejs18.x
	      Architectures:
	        - x86_64
	      Timeout: 10
	      FunctionUrlConfig:
	        AuthType: AWS_IAM
	        InvokeMode: RESPONSE_STREAM
	
	Outputs:
	  StreamingFunction:
	    Description: "Streaming Lambda Function ARN"
	    Value: !GetAtt StreamingFunction.Arn
	  StreamingFunctionURL:
	    Description: "Streaming Lambda Function URL"
	    Value: !GetAtt StreamingFunctionUrl.FunctionUrl
```

通常は、`sam build` および `sam deploy --guided` を使用して本番アプリケーションを構築し、デプロイすることができます。この例では、開発環境を想定し、アプリケーションを構築してデプロイするために `sam sync` コマンドを使用します。

**注記**  
`sam sync` コマンドは開発環境に推奨されます。詳細については[を使用して sam sync に同期する方法の概要 AWS クラウド](using-sam-cli-sync.md)を参照してください。

`sam sync` を実行する前に、プロジェクトが `samconfig.toml` ファイル内で正しく設定されていることを確認します。最も重要なのは、`stack_name` と `watch` の値を確認することです。設定ファイル内でこれらの値が指定されていれば、コマンドラインでそれらを指定する必要がありません。

```
version = 0.1
	
	[default]
	[default.global.parameters]
	stack_name = "lambda-streaming-nodejs-app"
	
	[default.build.parameters]
	cached = true
	parallel = true
	
	[default.validate.parameters]
	lint = true
	
	[default.deploy.parameters]
	capabilities = "CAPABILITY_IAM"
	confirm_changeset = true
	resolve_s3 = true
	s3_prefix = "lambda-streaming-nodejs-app"
	region = "us-west-2"
	image_repositories = []
	
	[default.package.parameters]
	resolve_s3 = true
	
	[default.sync.parameters]
	watch = true
	
	[default.local_start_api.parameters]
	warm_containers = "EAGER"
	
	[default.local_start_lambda.parameters]
	warm_containers = "EAGER"
```

次に、`sam sync` を実行してアプリケーションを構築し、デプロイします。設定ファイルで `--watch` オプションが設定されていることから、 AWS SAM CLI がアプリケーションを構築し、アプリケーションをデプロイして、変更を監視します。

```
$ sam sync
	
	The SAM CLI will use the AWS Lambda, Amazon API Gateway, and AWS StepFunctions APIs to upload your code   
	without                                                                                                   
	performing a CloudFormation deployment. This will cause drift in your CloudFormation stack.               
	**The sync command should only be used against a development stack**.                                     
	                                                                                                          
	Queued infra sync. Waiting for in progress code syncs to complete...                                      
	Starting infra sync.                                                                                      
	Building codeuri:                                                                                         
	/Users/.../lambda-streaming-nodejs-app/src runtime: nodejs18.x metadata: {} architecture: x86_64 functions: StreamingFunction  
	package.json file not found. Continuing the build without dependencies.                                   
	Running NodejsNpmBuilder:CopySource                                                                       
	
	Build Succeeded
	
	Successfully packaged artifacts and wrote output template to file /var/folders/45/5ct135bx3fn2551_ptl5g6_80000gr/T/tmpavrzdhgp.
	Execute the following command to deploy the packaged template
	sam deploy --template-file /var/folders/45/5ct135bx3fn2551_ptl5g6_80000gr/T/tmpavrzdhgp --stack-name <YOUR STACK NAME>
	
	
	        Deploying with following values
	        ===============================
	        Stack name                   : lambda-streaming-nodejs-app
	        Region                       : us-west-2
	        Disable rollback             : False
	        Deployment s3 bucket         : aws-sam-cli-managed-default-samclisam-s3-demo-bucket-1a4x26zbcdkqr
	        Capabilities                 : ["CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
	        Parameter overrides          : {}
	        Signing Profiles             : null
	
	Initiating deployment
	=====================
	
	
	2023-06-20 12:11:16 - Waiting for stack create/update to complete
	
	CloudFormation events from stack operations (refresh every 0.5 seconds)
	-----------------------------------------------------------------------------------------------------
	ResourceStatus            ResourceType              LogicalResourceId         ResourceStatusReason    
	-----------------------------------------------------------------------------------------------------
	CREATE_IN_PROGRESS        AWS::CloudFormation::St   lambda-streaming-         Transformation          
	                          ack                       nodejs-app                succeeded               
	CREATE_IN_PROGRESS        AWS::IAM::Role            StreamingFunctionRole     -                       
	CREATE_IN_PROGRESS        AWS::CloudFormation::St   AwsSamAutoDependencyLay   -                       
	                          ack                       erNestedStack                                     
	CREATE_IN_PROGRESS        AWS::IAM::Role            StreamingFunctionRole     Resource creation       
	                                                                              Initiated               
	CREATE_IN_PROGRESS        AWS::CloudFormation::St   AwsSamAutoDependencyLay   Resource creation       
	                          ack                       erNestedStack             Initiated               
	CREATE_COMPLETE           AWS::IAM::Role            StreamingFunctionRole     -                       
	CREATE_COMPLETE           AWS::CloudFormation::St   AwsSamAutoDependencyLay   -                       
	                          ack                       erNestedStack                                     
	CREATE_IN_PROGRESS        AWS::Lambda::Function     StreamingFunction         -                       
	CREATE_IN_PROGRESS        AWS::Lambda::Function     StreamingFunction         Resource creation       
	                                                                              Initiated               
	CREATE_COMPLETE           AWS::Lambda::Function     StreamingFunction         -                       
	CREATE_IN_PROGRESS        AWS::Lambda::Url          StreamingFunctionUrl      -                       
	CREATE_IN_PROGRESS        AWS::Lambda::Url          StreamingFunctionUrl      Resource creation       
	                                                                              Initiated               
	CREATE_COMPLETE           AWS::Lambda::Url          StreamingFunctionUrl      -                       
	CREATE_COMPLETE           AWS::CloudFormation::St   lambda-streaming-         -                       
	                          ack                       nodejs-app                                        
	-----------------------------------------------------------------------------------------------------
	
	CloudFormation outputs from deployed stack
	-------------------------------------------------------------------------------------------------------
	Outputs                                                                                               
	-------------------------------------------------------------------------------------------------------
	Key                 StreamingFunction                                                                 
	Description         Streaming Lambda Function ARN                                                     
	Value               arn:aws:lambda:us-west-2:012345678910:function:lambda-streaming-nodejs-app-       
	StreamingFunction-gUmhO833A0vZ                                                                        
	
	Key                 StreamingFunctionURL                                                              
	Description         Streaming Lambda Function URL                                                     
	Value               https://wxgkcc2dyntgtrwhf2dgdcvylu0rnnof.lambda-url.us-west-2.on.aws/             
	-------------------------------------------------------------------------------------------------------
	
	                                                                                                          
	Stack creation succeeded. Sync infra completed.                                                           
	                                                                                                          
	Infra sync completed.
```

関数がクラウドにデプロイされたので、`sam remote invoke` を使用して関数とやり取りできるようになりました。 AWS SAM CLI は、関数がレスポンスストリーミング用に設定されていることを自動的に検出し、関数のストリーミングされたレスポンスのリアルタイムでの出力を直ちに開始します。

```
$ sam remote invoke StreamingFunction
	
	Invoking Lambda Function StreamingFunction                                              
	{"statusCode":200,"headers":{"Content-Type":"text/html","X-Custom-Header":"Example-Custom-Header"}}<html><p>First write!</p><h1>Streaming h1</h1><h2>Streaming h2</h2><h3>Streaming h3</h3><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae mi tincidunt tellus ultricies dignissim id et diam. Morbi pharetra eu nisi et finibus. Vivamus diam nulla, vulputate et nisl cursus, pellentesque vehicula libero. Cras imperdiet lorem ante, non posuere dolor sollicitudin a. Vestibulum ipsum lacus, blandit nec augue id, lobortis dictum urna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Morbi auctor orci eget tellus aliquam, non maximus massa porta. In diam ante, pulvinar aliquam nisl non, elementum hendrerit sapien. Vestibulum massa nunc, mattis non congue vitae, placerat in quam. Nam vulputate lectus metus, et dignissim erat varius a.</p><p>DONE!</p></html>START RequestId: 1e4cdf04-60de-4769-b3a2-c1481982deb4 Version: $LATEST
	END RequestId: 1e4cdf04-60de-4769-b3a2-c1481982deb4
	REPORT RequestId: 1e4cdf04-60de-4769-b3a2-c1481982deb4  Duration: 4088.66 ms    Billed Duration: 4089 ms        Memory Size: 128 MB     Max Memory Used: 68 MB  Init Duration: 168.45 ms
```

関数コードを変更すると、 AWS SAM CLI が変更を即座に検出して、それらを直ちにデプロイします。以下は、関数コードに変更を行った後の AWS SAM CLI 出力の例です。

```
Syncing Lambda Function StreamingFunction...                                             
	Building codeuri:                                                                        
	/Users/.../lambda-streaming-nodejs-app/src runtime: nodejs18.x metadata: {} architecture:    
	x86_64 functions: StreamingFunction                                                      
	package.json file not found. Continuing the build without dependencies.                  
	Running NodejsNpmBuilder:CopySource                                                      
	Finished syncing Lambda Function StreamingFunction.                                      
	Syncing Layer StreamingFunctione9cfe924DepLayer...                                       
	SyncFlow [Layer StreamingFunctione9cfe924DepLayer]: Skipping resource update as the      
	content didn't change                                                                    
	Finished syncing Layer StreamingFunctione9cfe924DepLayer.
```

これで、`sam remote invoke` を再度使用して、クラウド内の関数とやり取りし、変更をテストできるようになりました。

### SQS の例
<a name="using-sam-cli-remote-invoke-examples-sqs"></a>

#### 基本的な例
<a name="using-sam-cli-remote-invoke-examples-sqs-basic"></a>

**ARN をリソース ID として指定して Amazon SQS キューを呼び出します。**

```
$ sam remote invoke arn:aws:sqs:us-west-2:01234567890:sqs-example-4DonhBsjsW1b --event '{"hello": "world"}' --output json

Sending message to SQS queue MySqsQueue                                                                         
{
  "MD5OfMessageBody": "49dfdd54b01cbcd2d2ab5e9e5ee6b9b9",
  "MessageId": "4f464cdd-15ef-4b57-bd72-3ad225d80adc",
  "ResponseMetadata": {
    "RequestId": "95d39377-8323-5ef0-9223-ceb198bd09bd",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "x-amzn-requestid": "95d39377-8323-5ef0-9223-ceb198bd09bd",
      "date": "Wed, 08 Nov 2023 23:27:26 GMT",
      "content-type": "application/x-amz-json-1.0",
      "content-length": "106",
      "connection": "keep-alive"
    },
    "RetryAttempts": 0
  }
}%
```

### Step Functions の例
<a name="using-sam-cli-remote-invoke-examples-sf"></a>

#### 基本的な例
<a name="using-sam-cli-remote-invoke-examples-sf-basic"></a>

**物理 ID をリソース ID として指定してステートマシンを呼び出します。**

まず、`sam list resources` を使用して物理 ID を取得します。

```
$ sam list resources --stack-name state-machine-example --output json

[
  {
    "LogicalResourceId": "HelloWorldStateMachine",
    "PhysicalResourceId": "arn:aws:states:us-west-2:513423067560:stateMachine:HelloWorldStateMachine-z69tFEUx0F66"
  },
  {
    "LogicalResourceId": "HelloWorldStateMachineRole",
    "PhysicalResourceId": "simple-state-machine-HelloWorldStateMachineRole-PduA0BDGuFXw"
  }
]
```

次に、物理 ID をリソース ID として使用してステートマシンを呼び出します。コマンドラインで `--event` オプションを指定してイベントを渡します。

```
$ sam remote invoke arn:aws:states:us-west-2:01234567890:stateMachine:HelloWorldStateMachine-z69tFEUx0F66 --event '{"is_developer": true}'

Invoking Step Function arn:aws:states:us-west-2:01234567890:stateMachine:HelloWorldStateMachine-z69tFEUx0F66   
"Hello Developer World"%
```

**空のイベントを渡してステートマシンを呼び出します。**

```
$ sam remote invoke HelloWorldStateMachine --stack-name state-machine-example

Invoking Step Function HelloWorldStateMachine                                                                   
"Hello World"%
```

## 関連リンク
<a name="using-sam-cli-remote-invoke-links"></a>

`sam remote invoke` および の使用に関するドキュメントについては AWS SAM CLI、以下を参照してください。
+ [sam remote invoke](sam-cli-command-reference-remote-invoke.md)
+ [AWS SAMCLI トラブルシューティング](sam-cli-troubleshooting.md)