---
title: Integrate Amazon SageMaker with Tiger Cloud | Tiger Data Docs
description: Build, train, and deploy ML models with time-series data storage and analysis
---

[Amazon SageMaker AI](https://docs.aws.amazon.com/sagemaker/latest/dg/whatis.html) 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 Tiger Cloud service.

## Prerequisites

To follow the procedure on this page you need to:

- Create a [target Tiger Cloud service](/docs/get-started/quickstart/create-service/index.md).

  This procedure also works for [self-hosted TimescaleDB](/docs/get-started/choose-your-path/install-timescaledb/index.md).

* Set up an [AWS Account](https://signin.aws.amazon.com/signup?request_type=register)

## Prepare your service to ingest data from SageMaker

Create a table in Tiger Cloud service to store model predictions generated by SageMaker.

1. **Connect to your Tiger Cloud service**

   For Tiger Cloud, open an [SQL editor](/docs/build/data-management/run-queries-from-tiger-console/index.md) in [Tiger Console](https://console.cloud.tigerdata.com/dashboard/services). For self-hosted TimescaleDB, use [`psql`](/docs/integrate/query-administration/psql/index.md).

2. **For better performance and easier real-time analytics, create a hypertable**

   [Hypertables](/docs/learn/hypertables/understand-hypertables/index.md) 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.

   ```
   CREATE TABLE model_predictions (
     time TIMESTAMPTZ NOT NULL,
     model_name TEXT NOT NULL,
     prediction DOUBLE PRECISION NOT NULL
   ) WITH (
     tsdb.hypertable
   );
   ```

   When you create a hypertable using [CREATE TABLE … WITH …](/docs/reference/timescaledb/hypertables/create_table/index.md), the default partitioning column is automatically the first column with a timestamp data type. Also, TimescaleDB creates a [columnstore policy](/docs/reference/timescaledb/hypercore/add_columnstore_policy/index.md) that automatically converts your data to the columnstore, after an interval equal to the value of the [chunk\_interval](/docs/reference/timescaledb/hypertables/set_chunk_time_interval/index.md), defined through `after` in the policy. This columnar format enables fast scanning and aggregation, optimizing performance for analytical workloads while also saving significant storage space. In the columnstore conversion, hypertable chunks are compressed by up to 98%, and organized for efficient, large-scale queries.

   You can customize this policy later using [alter\_job](/docs/reference/timescaledb/jobs-automation/alter_job/index.md). However, to change `after` or `created_before`, the compression settings, or the hypertable the policy is acting on, you must [remove the columnstore policy](/docs/reference/timescaledb/hypercore/remove_columnstore_policy/index.md) and [add a new one](/docs/reference/timescaledb/hypercore/add_columnstore_policy/index.md).

   You can also manually [convert chunks](/docs/reference/timescaledb/hypercore/convert_to_columnstore/index.md) in a hypertable to the columnstore.

## Create the code to inject data into a service

1. **Create a SageMaker Notebook instance**

   1. In [Amazon SageMaker > Notebooks and Git repos](https://console.aws.amazon.com/sagemaker/home#/notebooks-and-git-repos), click `Create Notebook instance`.
   2. Follow the wizard to create a default Notebook instance.

2. **Write a Notebook script that inserts data into your Tiger Cloud service**

   1. When your Notebook instance is `inService,` click `Open JupyterLab` and click `conda_python3`.

   2. Update the following script with your [connection details](/docs/integrate/find-connection-details/index.md), then paste it in the Notebook.

      ```
      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>"
      )
      ```

3. **Test your SageMaker script**

   1. Run the script in your SageMaker notebook.

   2. Verify that the data is in your service

      Open an [SQL editor](/docs/build/data-management/run-queries-from-tiger-console/index.md) and check the `sensor_data` table:

      ```
      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       |

Now you can seamlessly integrate Amazon SageMaker with Tiger Cloud to store and analyze time-series data generated by machine learning models. You can also integrate visualization tools like [Grafana](/docs/integrate/observability-alerting/grafana/index.md) or [Tableau](/docs/integrate/bi-vizualization/tableau/index.md) with Tiger Cloud to create real-time dashboards of your model predictions.
