

End of support notice: On May 20, 2026, Amazon will end support for Amazon IoT Events. After May 20, 2026, you will no longer be able to access the Amazon IoT Events console or Amazon IoT Events resources. For more information, see [Amazon IoT Events end of support](https://docs.amazonaws.cn/iotevents/latest/developerguide/iotevents-end-of-support.html).

# Deploy a Lambda function for Amazon IoT Events using Amazon CloudFormation
<a name="alarms-create-lambda-cfn"></a>

This tutorial uses an Amazon CloudFormation template to deploy a Lambda function. This template automatically creates an IAM role that allows the Lambda function to work with Amazon SES and Amazon SNS.

The following shows you how to use the Amazon Command Line Interface (Amazon CLI) to create a CloudFormation stack.

1. <a name="install-cli"></a>In your device's terminal, run `aws --version` to check if you installed the Amazon CLI. For more information, see [Installing or updating to the latest version of the Amazon CLI](https://docs.amazonaws.cn/cli/latest/userguide/getting-started-install.html) in the *Amazon Command Line Interface User Guide*.

1. <a name="configure-cli"></a>Run `aws configure list` to check if you configured the Amazon CLI in the Amazon Region that has all your Amazon resources for this tutorial. For more information, see [Set and view configuration settings using commands](https://docs.amazonaws.cn/cli/latest/userguide/cli-configure-files.html#cli-configure-files-methods) in the *Amazon Command Line Interface User Guide*

1. Download the CloudFormation template, [notificationLambda.template.yaml.zip](samples/notificationLambda.template.yaml.zip).
**Note**  
If you have difficulty downloading the file, the template is also available in the [CloudFormation template](alarms-create-lambda.md#cfn-template).

1. Unzip the content and save it locally as `notificationLambda.template.yaml`.

1. Open a terminal on your device and navigate to the directory where you downloaded the `notificationLambda.template.yaml` file.

1. To create a CloudFormation stack, run the following command:

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

You might modify this CloudFormation template to customize the Lambda function and its behavior.

**Note**  
Amazon Lambda retries function errors twice. If the function doesn't have enough capacity to handle all incoming requests, events might wait in the queue for hours or days to be sent to the function. You can configure an undelivered-message queue (DLQ) on the function to capture events that weren't successfully processed. For more information, see [Asynchronous invocation](https://docs.amazonaws.cn/lambda/latest/dg/invocation-async.html) in the *Amazon Lambda Developer Guide*.

You can also create or configure the stack in the CloudFormation console. For more information, see [Working with stacks](https://docs.amazonaws.cn/AWSCloudFormation/latest/UserGuide/stacks.html), in the *Amazon CloudFormation User Guide*.