

支援終止通知：2026 年 5 月 20 日， AWS 將終止對 的支援 AWS IoT Events。2026 年 5 月 20 日之後，您將無法再存取 AWS IoT Events 主控台或 AWS IoT Events 資源。如需詳細資訊，請參閱[AWS IoT Events 終止支援](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-end-of-support.html)。

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

# 部署 Lambda 函數以 AWS IoT Events 使用 CloudFormation
<a name="alarms-create-lambda-cfn"></a>

本教學課程使用 CloudFormation 範本來部署 Lambda 函數。此範本會自動建立 IAM 角色，允許 Lambda 函數使用 Amazon SES 和 Amazon SNS。

以下說明如何使用 AWS Command Line Interface (AWS CLI) 來建立 CloudFormation 堆疊。

1. <a name="install-cli"></a>在裝置的終端機中，執行 `aws --version` 以檢查是否已安裝 AWS CLI。如需詳細資訊，請參閱 *AWS Command Line Interface User Guide* 中的 [Installing or updating to the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. <a name="configure-cli"></a>執行 `aws configure list` 以檢查您是否 AWS CLI 在具有本教學課程所有 AWS 資源的 AWS 區域中設定 。如需詳細資訊，請參閱*AWS Command Line Interface 《 使用者指南*》中的[使用命令設定和檢視組態設定](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-methods) 

1. 下載 CloudFormation 範本 [notificationLambda.template.yaml.zip](samples/notificationLambda.template.yaml.zip)。
**注意**  
如果您在下載檔案時遇到困難，也可以在 中使用範本[CloudFormation 範本](alarms-create-lambda.md#cfn-template)。

1. 解壓縮內容並以 `notificationLambda.template.yaml` 儲存在本機。

1. 在您的裝置上開啟終端機，並導覽至您下載`notificationLambda.template.yaml`檔案的目錄。

1. 若要建立 CloudFormation 堆疊，請執行下列命令：

   ```
   aws cloudformation create-stack --stack-name notificationLambda-stack --template-body file://notificationLambda.template.yaml --capabilities CAPABILITY_IAM
   ```

您可以修改此 CloudFormation 範本來自訂 Lambda 函數及其行為。

**注意**  
AWS Lambda 會重試函數錯誤兩次。如果函式沒有足夠的容量來處理所有傳入的請求，事件可能在佇列中等待數小時或數天才會傳送到函式。您可以在函數上設定未傳遞訊息佇列 (DLQ)，以擷取未成功處理的事件。如需詳細資訊，請參閱 *AWS Lambda 開發人員指南*中的[非同步叫用](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html)。

您也可以在 CloudFormation 主控台中建立或設定堆疊。如需詳細資訊，請參閱*AWS CloudFormation 《 使用者指南*》中的[使用堆疊](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacks.html)。