

如需與 Amazon Timestream for LiveAnalytics 類似的功能，請考慮使用 Amazon Timestream for InfluxDB。它提供簡化的資料擷取和單一位數毫秒查詢回應時間，以進行即時分析。[在這裡](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html)進一步了解。

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

# AWS Lambda
<a name="Lambda"></a>

 您可以建立與 Timestream for LiveAnalytics 互動的 Lambda 函數。例如，您可以建立定期執行的 Lambda 函數，以在 Timestream 上執行查詢，並根據符合一或多個條件的查詢結果傳送 SNS 通知。若要進一步了解 Lambda，請參閱 [AWS Lambda 文件](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)。

**Topics**
+ [使用 Amazon Timestream for LiveAnalytics 搭配 Python 建置 AWS Lambda 函數](#Lambda.w-python)
+ [使用 Amazon Timestream for LiveAnalytics 搭配 JavaScript 建置 AWS Lambda 函數](#Lambda.w-js)
+ [使用 Amazon Timestream for LiveAnalytics with Go 建置 AWS Lambda 函數](#Lambda.w-go)
+ [使用 Amazon Timestream for LiveAnalytics 搭配 C\$1 建置 AWS Lambda 函數](#Lambda.w-c-sharp)

## 使用 Amazon Timestream for LiveAnalytics 搭配 Python 建置 AWS Lambda 函數
<a name="Lambda.w-python"></a>

 若要使用 Amazon Timestream for LiveAnalytics 搭配 Python 建置 AWS Lambda 函數，請遵循下列步驟。

1.  建立 Lambda 的 IAM 角色以擔任 將授予存取 Timestream 服務所需的許可，如 中所述[為 LiveAnalytics 存取提供 Timestream](accessing.md#getting-started.prereqs.iam-user)。

1. 編輯 IAM 角色的信任關係，以新增 Lambda 服務。您可以使用下列命令來更新現有角色，以便 AWS Lambda 可以擔任該角色：

   1. 建立信任政策文件：

      ```
      cat > Lambda-Role-Trust-Policy.json << EOF
      {
        "Version": "2012-10-17",		 	 	 
        "Statement": [
          {
            "Effect": "Allow",
            "Principal": {
              "Service": [
                "lambda.amazonaws.com"
              ]
            },
            "Action": "sts:AssumeRole"
          }
        ]
      }
      EOF
      ```

   1. 使用信任文件從上一個步驟更新角色

      ```
      aws iam update-assume-role-policy --role-name <name_of_the_role_from_step_1> --policy-document file://Lambda-Role-Trust-Policy.json
      ```

相關參考位於 [TimestreamWrite](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/timestream-write.html) 和 [TimestreamQuery](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/timestream-query.html)。

## 使用 Amazon Timestream for LiveAnalytics 搭配 JavaScript 建置 AWS Lambda 函數
<a name="Lambda.w-js"></a>

 若要使用 Amazon Timestream for LiveAnalytics 搭配 JavaScript 建置 AWS Lambda 函數，請遵循[此處](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html#nodejs-package-dependencies)概述的指示。

相關參考位於 [Timestream Write Client - AWS SDK for JavaScript v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-timestream-write/index.html) 和 [Timestream Query Client - AWS SDK for JavaScript v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-timestream-query/index.html)。

## 使用 Amazon Timestream for LiveAnalytics with Go 建置 AWS Lambda 函數
<a name="Lambda.w-go"></a>

 若要使用 Amazon Timestream for LiveAnalytics with Go 建置 AWS Lambda 函數，請遵循[此處](https://docs.aws.amazon.com/lambda/latest/dg/golang-package.html)概述的指示。

相關參考位於 [timestreamwrite](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/timestreamwrite) 和 [timestreamquery](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/timestreamquery)。

## 使用 Amazon Timestream for LiveAnalytics 搭配 C\$1 建置 AWS Lambda 函數
<a name="Lambda.w-c-sharp"></a>

 若要使用 Amazon Timestream for LiveAnalytics 搭配 C\$1 建置 AWS Lambda 函數，請遵循[此處](https://docs.aws.amazon.com/lambda/latest/dg/csharp-package.html)概述的指示。

相關參考位於 [Amazon.TimestreamWrite](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/TimestreamWrite/NTimestreamWrite.html) 和 [Amazon.TimestreamQuery](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/TimestreamQuery/NTimestreamQuery.html)。