-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3723 docs rfccreate a doc showing how to integrate amazon sagemaker w…
…ith timescale cloud (#3789) * chore: update the sagemaker doc
- Loading branch information
1 parent
3f2484c
commit 9b01b00
Showing
5 changed files
with
161 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
--- | ||
title: Integrate Amazon Sagemaker with Timescale Cloud | ||
excerpt: Integrate Amazon SageMaker with Timescale Cloud to store and analyze ML model data. | ||
products: [cloud, mst, self_hosted] | ||
keywords: [connect, integrate, amazon, aws, sagemaker] | ||
--- | ||
|
||
import IntegrationPrereqs from "versionContent/_partials/_integration-prereqs.mdx"; | ||
|
||
# Integrate Amazon SageMaker with $CLOUD_LONG | ||
|
||
[Amazon SageMaker AI][Amazon Sagemaker] is a fully managed machine learning (ML) service. With SageMaker AI, data | ||
scientists and developers can quickly and confidently build, train, and deploy ML models into a production-ready | ||
hosted environment. | ||
|
||
This page shows you how to integrate Amazon Sagemaker with a $SERVICE_LONG. | ||
|
||
## Prerequisites | ||
|
||
<IntegrationPrereqs /> | ||
|
||
* Setup an [AWS Account][aws-sign-up] | ||
|
||
## Prepare your $SERVICE_LONG to ingest data from SageMaker | ||
|
||
Create a table in $SERVICE_LONG to store model predictions generated by SageMaker. | ||
|
||
<Procedure> | ||
|
||
1. **Connect to your $SERVICE_LONG** | ||
|
||
For $CLOUD_LONG, open an [SQL editor][run-queries] in [$CONSOLE][open-console]. For self-hosted, use [`psql`][psql]. | ||
|
||
```sql | ||
CREATE TABLE model_predictions ( | ||
time TIMESTAMPTZ NOT NULL, | ||
model_name TEXT NOT NULL, | ||
prediction DOUBLE PRECISION NOT NULL | ||
); | ||
``` | ||
|
||
1. **For better performance and easier real-time analytics, convert the table to a hypertable** | ||
|
||
[Hypertables][about-hypertables] are PostgreSQL tables that automatically partition your data by time. You interact | ||
with hypertables in the same way as regular PostgreSQL tables, but with extra features that makes managing your | ||
time-series data much easier. | ||
|
||
```sql | ||
SELECT create_hypertable('model_predictions', 'time'); | ||
``` | ||
|
||
</Procedure> | ||
|
||
## Create the code to inject data into a $SERVICE_LONG | ||
|
||
<Procedure> | ||
|
||
1. **Create a SageMaker Notebook instance** | ||
|
||
1. In [Amazon SageMaker > Notebooks and Git repos][aws-notebooks-git-repos], click `Create Notebook instance`. | ||
1. Follow the wizard to create a default Notebook instance. | ||
|
||
1. **Write a Notebook script that inserts data into your $SERVICE_LONG** | ||
|
||
1. When your Notebook instance is `inService,` click `Open JupyterLab` and click `conda_python3`. | ||
1. Update the following script with your [connection details][connection-info], then paste it in the Notebook. | ||
|
||
```python | ||
import psycopg2 | ||
from datetime import datetime | ||
|
||
def insert_prediction(model_name, prediction, host, port, user, password, dbname): | ||
conn = psycopg2.connect( | ||
host=host, | ||
port=port, | ||
user=user, | ||
password=password, | ||
dbname=dbname | ||
) | ||
cursor = conn.cursor() | ||
|
||
query = """ | ||
INSERT INTO model_predictions (time, model_name, prediction) | ||
VALUES (%s, %s, %s); | ||
""" | ||
|
||
values = (datetime.utcnow(), model_name, prediction) | ||
cursor.execute(query, values) | ||
conn.commit() | ||
|
||
cursor.close() | ||
conn.close() | ||
|
||
# Example usage | ||
insert_prediction( | ||
model_name="example_model", | ||
prediction=0.95, | ||
host="<host>", | ||
port="<port>", | ||
user="<user>", | ||
password="<password>", | ||
dbname="<dbname>" | ||
) | ||
``` | ||
|
||
1. **Test your SageMaker script** | ||
|
||
1. Run the script in your SageMaker notebook. | ||
1. Verify that the data is in your $SERVICE_SHORT | ||
|
||
Open an [SQL editor][run-queries] and check the `sensor_data` table: | ||
|
||
```sql | ||
SELECT * FROM model_predictions; | ||
``` | ||
You see something like: | ||
|
||
|time | model_name | prediction | | ||
| -- | -- | -- | | ||
|2025-02-06 16:56:34.370316+00| timescale-cloud-model| 0.95| | ||
|
||
</Procedure> | ||
|
||
Now you can seamlessly integrate Amazon SageMaker with $CLOUD_LONG to store and analyze time-series data generated by | ||
machine learning models. You can also untegrate visualization tools like [Grafana][grafana-integration] or | ||
[Tableau][tableau-integration] with $CLOUD_LONG to create real-time dashboards of your model predictions. | ||
|
||
|
||
|
||
|
||
|
||
|
||
[Amazon Sagemaker]: https://docs.aws.amazon.com/sagemaker/latest/dg/whatis.html | ||
[aws-sign-up]: https://signin.aws.amazon.com/signup?request_type=register | ||
[install-aws-cli]: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html | ||
[install-python]: https://www.python.org/downloads/ | ||
[install-postgresql]: https://www.postgresql.org/download/ | ||
[console]: https://console.cloud.timescale.com/ | ||
[grafana-integration]: use-timescale/:currentVersion:/integrations/grafana/ | ||
[tableau-integration]: use-timescale/:currentVersion:/integrations/tableau/ | ||
[run-queries]: /getting-started/:currentVersion:/run-queries-from-console/ | ||
[open-console]: https://console.cloud.timescale.com/dashboard/services | ||
[psql]: /use-timescale/:currentVersion:/integrations/psql/ | ||
[about-hypertables]: /use-timescale/:currentVersion:/hypertables/about-hypertables/ | ||
[aws-notebooks-git-repos]:https://console.aws.amazon.com/sagemaker/home#/notebooks-and-git-repos | ||
[secure-vpc-aws]: /use-timescale/:currentVersion:/vpc/ | ||
[connection-info]: /use-timescale/:currentVersion:/integrations/find-connection-details/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters