

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# sam remote invoke
<a name="sam-cli-command-reference-remote-invoke"></a>

此頁面提供 AWS Serverless Application Model Command Line Interface (AWS SAM CLI) `sam remote invoke`命令的參考資訊。
+ 如需 的簡介 AWS SAM CLI，請參閱 [什麼是 AWS SAM CLI？](what-is-sam-overview.md#what-is-sam-cli)
+ 如需使用 AWS SAM CLI`sam remote invoke`命令的文件，請參閱 [在雲端使用 進行測試的簡介 sam remote invoke](using-sam-cli-remote-invoke.md)。

`sam remote invoke` 命令會在 中叫用支援的資源 AWS 雲端。

## Usage
<a name="sam-cli-command-reference-remote-invoke-usage"></a>

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

## 引數
<a name="sam-cli-command-reference-remote-invoke-args"></a>

**Resource ID (資源 ID)**  <a name="sam-cli-command-reference-remote-invoke-args-resource-id"></a>
要叫用之受支援資源的 ID。  
此引數接受下列值：  
+ **Amazon Resource Name (ARN)** – 資源的 ARN。
**提示**  
使用 `sam list stack-outputs --stack-name <stack-name>`取得 資源的 ARN。
+ **邏輯 ID** – 資源的邏輯 ID。您還必須使用 `--stack-name`選項提供 AWS CloudFormation 堆疊名稱。
+ **實體 ID** – 資源的實體 ID。當您使用 部署資源時，會建立此 ID CloudFormation。
**提示**  
使用 `sam list resources --stack-name <stack-name>`取得 資源的實體 ID。  
**當您提供 ARN 或實體 ID 時：**  
如果您提供 ARN 或實體 ID，請勿提供堆疊名稱。使用 `--stack-name`選項提供堆疊名稱時，或在組態檔案中定義堆疊名稱時， AWS SAM CLI會自動將您的資源 ID 處理為 CloudFormation 堆疊中的邏輯 ID 值。  
**當您不提供資源 ID 時：**  
如果您不提供資源 ID，但使用 `--stack-name`選項提供堆疊名稱，CLI AWS SAM 將嘗試使用以下邏輯自動調用 CloudFormation 堆疊中的資源：  

1.  AWS SAM CLI 將依下列順序識別資源類型，並在堆疊中找到資源類型後移至下一個步驟：

   1. Lambda

   1. 步驟函數

   1. Amazon SQS

   1. Kinesis Data Streams

1. 如果資源類型在您的堆疊中有單一資源， AWS SAM CLI會叫用它。如果您的堆疊中存在多個資源類型，則 AWS SAM CLI會傳回錯誤。
以下是 AWS SAM CLI將執行的操作範例：  
+ **包含兩個 Lambda 函數和 Amazon SQS 佇列的堆疊** – AWS SAM CLI將尋找 Lambda 資源類型，並傳回 和 錯誤，因為堆疊包含多個 Lambda 函數。
+ **包含 Lambda 函數和兩個 Amazon Kinesis Data Streams 應用程式的堆疊** – AWS SAM CLI將尋找 Lambda 函數並將其叫用，因為堆疊包含單一 Lambda 資源。
+ **包含單一 Amazon SQS 佇列和兩個 Kinesis Data Streams 應用程式的堆疊** – AWS SAM CLI將尋找 Amazon SQS 佇列並將其叫用，因為堆疊包含單一 Amazon SQS 佇列。

## 選項
<a name="sam-cli-command-reference-remote-invoke-options"></a>

`--beta-features | --no-beta-features`  <a name="sam-cli-command-reference-remote-invoke-options-beta-features"></a>
允許或拒絕 Beta 版功能。

`--config-env TEXT`  <a name="sam-cli-command-reference-remote-invoke-options-config-env"></a>
從 AWS SAM CLI組態檔案指定要使用的環境。  
*預設*：`default`

`--config-file FILENAME`  <a name="sam-cli-command-reference-remote-invoke-options-config-file"></a>
指定組態檔案的路徑和檔案名稱。  
如需關於組態檔案的詳細資訊，請參閱 [設定 AWS SAM CLI](using-sam-cli-configure.md)。  
*預設*：在專案目錄的`samconfig.toml`根目錄。

`--debug`  <a name="sam-cli-command-reference-remote-invoke-options-debug"></a>
啟用除錯記錄。這會列印 產生的偵錯訊息和時間戳記 AWS SAM CLI。

`--event, -e TEXT`  <a name="sam-cli-command-reference-remote-invoke-options-event"></a>
要傳送至目標資源的事件。

`--event-file FILENAME`  <a name="sam-cli-command-reference-remote-invoke-options-event-file"></a>
檔案的路徑，其中包含要傳送至目標資源的事件。

`--help, -h`  <a name="sam-cli-command-reference-remote-invoke-options-help"></a>
顯示說明訊息並結束。

`--output [ text | json ]`  <a name="sam-cli-command-reference-remote-invoke-options-output"></a>
以特定輸出格式輸出調用的結果。  
`json` – 請求中繼資料和資源回應會以 JSON 結構傳回。回應包含完整的 SDK 輸出。  
`text` – 請求中繼資料會以文字結構傳回。資源回應會以叫用資源的輸出格式傳回。

`--parameter`  <a name="sam-cli-command-reference-remote-invoke-options-parameter"></a>
您可以傳遞給要叫用之資源的其他[https://boto3.amazonaws.com/v1/documentation/api/latest/index.html](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html)參數。    
**Amazon Kinesis Data Streams**  <a name="sam-cli-command-reference-remote-invoke-options-parameter-kinesis"></a>
下列其他參數可用來將記錄放入 Kinesis 資料串流：  
+ `ExplicitHashKey='string'`
+ `PartitionKey='string'`
+ `SequenceNumberForOrdering='string'`
+ `StreamARN='string'`
如需每個參數的說明，請參閱 [Kinesis.Client.put\$1record](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/kinesis/client/put_record.html)。  
**AWS Lambda**  <a name="sam-cli-command-reference-remote-invoke-options-parameter-lambda"></a>
下列其他參數可用來叫用 Lambda 資源並接收緩衝回應：  
+ `ClientContext='base64-encoded string'`
+ `InvocationType='[ DryRun | Event | RequestResponse ]'`
+ `LogType='[ None | Tail ]'`
+ `Qualifier='string'`
下列其他參數可用來透過回應串流叫用 Lambda 資源：  
+ `ClientContext='base64-encoded string'`
+ `InvocationType='[ DryRun | RequestResponse ]'`
+ `LogType='[ None | Tail ]'`
+ `Qualifier='string'`
如需每個參數的說明，請參閱下列內容：  
+ 具有緩衝回應的 Lambda – [Lambda.Client.invoke](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda/client/invoke.html)
+ 具有回應串流的 Lambda – [Lambda.Client.invoke\$1with\$1response\$1stream](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda/client/invoke_with_response_stream.html)  
**Amazon Simple Queue Service (Amazon SQS)**  <a name="sam-cli-command-reference-remote-invoke-options-parameter-sqs"></a>
下列其他參數可用來傳送訊息至 Amazon SQS 佇列：  
+ `DelaySeconds=integer`
+ `MessageAttributes='json string'`
+ `MessageDeduplicationId='string'`
+ `MessageGroupId='string'`
+ `MessageSystemAttributes='json string'`
如需每個參數的說明，請參閱 [SQS.Client.send\$1message](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs/client/send_message.html)。  
**AWS Step Functions**  <a name="sam-cli-command-reference-remote-invoke-options-parameter-sf"></a>
下列其他參數可用來啟動狀態機器執行：  
+ `name='string'`
+ `traceHeader='string'`
如需每個參數的說明，請參閱 [SFN.Client.start\$1execution](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions/client/start_execution.html)。

`--profile TEXT`  <a name="sam-cli-command-reference-remote-invoke-options-profile"></a>
從您的登入資料檔案中取得 AWS 登入資料的特定設定檔。

`--region TEXT`  <a name="sam-cli-command-reference-remote-invoke-options-region"></a>
資源 AWS 區域 的 。例如 `us-east-1`。

`--stack-name TEXT`  <a name="sam-cli-command-reference-remote-invoke-options-stack-name"></a>
資源所屬的 CloudFormation 堆疊名稱。

`--tenant-id TEXT`  <a name="ref-sam-cli-local-invoke-options-tenancyconfig"></a>
多租用戶 Lambda 函數的租用戶 ID。用來確保不同租用戶之間的運算隔離。叫用使用租戶隔離模式設定的函數時為必要。

`--test-event-name NAME`  <a name="sam-cli-command-reference-remote-invoke-options-test-event-name"></a>
要傳遞至 Lambda 函數的可共用測試事件名稱。  
此選項僅支援 Lambda 函數。

## 範例
<a name="sam-cli-command-reference-remote-invoke-examples"></a>

下列範例會叫用 AWS 雲端中支援的資源，並啟用偵錯記錄，以列印 產生的偵錯訊息和時間戳記 AWS SAM CLI：

```
$ sam remote invoke--debug
```