

终止支持通知：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 和亚马逊 SNS 配合使用。

以下内容向您展示了如何使用 AWS Command Line Interface (AWS CLI) 创建 CloudFormation 堆栈。

1. <a name="install-cli"></a>在设备的终端中，运行`aws --version`以检查您是否安装了 AWS CLI。有关更多信息，请参阅《AWS Command Line Interface 用户指南》**中的[安装或更新到最新版本的 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.templat [e.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)。