

要获得与亚马逊 Timestream 类似的功能 LiveAnalytics，可以考虑适用于 InfluxDB 的亚马逊 Timestream。适用于 InfluxDB 的 Amazon Timestream 提供简化的数据摄取和个位数毫秒级的查询响应时间，以实现实时分析。点击[此处](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html)了解更多信息。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Amazon SageMaker AI
<a name="Sagemaker"></a>

 可使用 Amazon SageMaker 笔记本将机器学习模型与 Amazon Timestream 集成。为协助您开始使用，我们已创建示例 SageMaker 笔记本，用于处理来自 Timestream 的数据。该数据从持续发送数据的多线程 Python 应用程序插入到 Timestream 中。示例 SageMaker 笔记本及示例 Python 应用程序的源代码可在 GitHub 中获取。

1. 按照 [创建数据库](console_timestream.md#console_timestream.db.using-console) 和 [创建表](console_timestream.md#console_timestream.table.using-console) 中所述的说明创建数据库和表。

1. 按照 [GitHub](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/cloning-a-repository) 中的说明克隆[多线程 Python 示例应用程序](https://github.com/awslabs/amazon-timestream-tools/tree/mainline/tools/python/continuous-ingestor)的 GitHub 存储库。

1. 按照 [GitHub](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/cloning-a-repository) 中的说明克隆[示例 Timestream SageMaker 笔记本](https://github.com/awslabs/amazon-timestream-tools/blob/master/integrations/sagemaker)的 GitHub 存储库。

1. 按照[自述文件](https://github.com/awslabs/amazon-timestream-tools/blob/mainline/tools/python/continuous-ingestor/README.md)中的说明运行应用程序，持续将数据摄取到 Timestream 中。

1. 按照[此处](https://docs.aws.amazon.com/sagemaker/latest/dg/gs-config-permissions.html)所述的说明创建用于 Amazon SageMaker 的 Amazon S3 存储桶。

1. 创建已安装最新 boto3 的 Amazon SageMaker 实例：除[此处](https://docs.aws.amazon.com/sagemaker/latest/dg/gs-setup-working-env.html)所述说明外，请按照以下步骤操作：

   1. 在**创建笔记本**实例页面上，点击**其他配置**

   1. 点击**生命周期配置：可选****，然后选择**创建新的生命周期配置**

   1. 在*创建生命周期配置*向导框中，执行以下操作：

      1. 在配置中填写所需名称，例如 `on-start`

      1. 在“启动笔记本”脚本中，复制并粘贴来自 [Github](https://github.com/aws-samples/amazon-sagemaker-notebook-instance-lifecycle-config-samples/blob/master/scripts/install-pip-package-single-environment/on-start.sh) 的脚本内容 

      1. 在粘贴的脚本中，将 `PACKAGE=scipy` 替换为 `PACKAGE=boto3`。

1. 点击**创建配置**

1. 转到 AWS 管理控制台中的 IAM 服务，查找为笔记本实例新创建的 SageMaker 执行角色。

1. 将 `AmazonTimestreamFullAccess` 的 IAM 策略附加到执行角色。
**注意**  
`AmazonTimestreamFullAccess` IAM 策略不局限于特定资源，且不适用于生产环境。对于生产系统，建议使用限制特定资源访问权限的策略。

1. 当笔记本实例的状态为**正在使用**时，选择**打开 Jupyter**，以便为该实例启用 SageMaker 笔记本。

1.  选择**上传**按钮，将文件 `timestreamquery.py` 和 `Timestream_SageMaker_Demo.ipynb` 上传至笔记本中

1. 选择 `Timestream_SageMaker_Demo.ipynb`
**注意**  
如果弹出**未找到内核**提示框，请选择 **conda\$1python3** 并点击**设置内核**。

1. 修改 `DB_NAME`、`TABLE_NAME`、`bucket` 和 `ENDPOINT`，以匹配训练模型的数据库名称、表名称、S3 存储桶名称和区域。

1. 选择**播放**图标，以运行单个单元格

1. 到达单元格 `Leverage Timestream to find hosts with average CPU utilization across the fleet` 时，请确保输出返回至少 2 个主机名。
**注意**  
如果输出中的主机名少于 2 个，则可能需要重新运行示例 Python 应用程序，在向 Timestream 摄取数据时使用更多的线程和更大的主机规模。

1. 到达单元格 `Train a Random Cut Forest (RCF) model using the CPU utilization history` 时，根据训练作业的资源要求更改 `train_instance_type`

1. 到达单元格 `Deploy the model for inference` 时，根据推理作业的资源要求更改 `instance_type`
**注意**  
训练模型可能需要几分钟时间。训练完成后，将在单元格的输出中看到消息**已完成：训练作业已完成**。

1. 运行单元格 `Stop and delete the endpoint`，以清除资源。也可以通过 SageMaker 控制台停止和删除实例