

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

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

# 使用 API
<a name="Using.API"></a>

 除了 [SDKs](getting-started-sdks.md) 之外，Amazon Timestream for LiveAnalytics 透過*端點探索模式*提供直接 REST API 存取。端點探索模式及其使用案例如下所述。

## 端點探索模式
<a name="Using-API.endpoint-discovery"></a>

由於 Timestream Live Analytics SDKs 旨在透明地使用服務的架構，包括服務端點的管理和映射，因此建議您將 SDKs用於大多數應用程式。不過，有些執行個體需要使用 Timestream for LiveAnalytics REST API 端點探索模式：
+ 您使用 [VPC 端點 (AWS PrivateLink) 搭配 Timestream for LiveAnalytics](VPCEndpoints.md)
+ 您的應用程式使用尚未支援 SDK 的程式設計語言
+ 您需要更好地控制用戶端實作

本節包含端點探索模式如何運作、如何實作端點探索模式，以及用量備註的相關資訊。選取以下主題以進一步了解。

**Topics**
+ [端點探索模式](#Using-API.endpoint-discovery)
+ [端點探索模式的運作方式](Using-API.endpoint-discovery.how-it-works.md)
+ [實作端點探索模式](Using-API.endpoint-discovery.describe-endpoints.implementation.md)

# 端點探索模式的運作方式
<a name="Using-API.endpoint-discovery.how-it-works"></a>

 Timestream 使用[行動架構](architecture.md#cells)建置，以確保更好的擴展和流量隔離屬性。由於每個客戶帳戶都會對應至區域中的特定儲存格，因此您的應用程式必須使用帳戶已對應至的正確儲存格特定端點。使用 SDKs時，系統會為您透明地處理此映射，您不需要管理儲存格特定的端點。不過，當直接存取 REST API 時，您需要自行管理和映射正確的端點。此程序為*端點探索模式*，如下所述：

1.  端點探索模式會從呼叫 `DescribeEndpoints`動作開始 （如 [https://docs.aws.amazon.com/timestream/latest/developerguide/API_Reference.html](https://docs.aws.amazon.com/timestream/latest/developerguide/API_Reference.html) 節所述）。

1.  端點應在傳回time-to-live(TTL) 值 () 指定的時間內快取和重複使用[https://docs.aws.amazon.com/timestream/latest/developerguide/API_Endpoint.html#timestream-Type-Endpoint-CachePeriodInMinutes.html](https://docs.aws.amazon.com/timestream/latest/developerguide/API_Endpoint.html#timestream-Type-Endpoint-CachePeriodInMinutes.html)。然後，可以在 TTL 期間呼叫 Timestream Live Analytics API。

1.  TTL 過期後，應對 DescribeEndpoints 進行新的呼叫以重新整理端點 （換言之，從步驟 1 開始）。

**注意**  
 `DescribeEndpoints` 動作的語法、參數和其他用量資訊如 [API 參考](https://docs.aws.amazon.com/timestream/latest/developerguide/API_DescribeEndpoints.html)所述。請注意， `DescribeEndpoints`動作可透過兩個 SDKs，而且每個 SDK 都相同。

如需端點探索模式的實作，請參閱 [實作端點探索模式](Using-API.endpoint-discovery.describe-endpoints.implementation.md)。

# 實作端點探索模式
<a name="Using-API.endpoint-discovery.describe-endpoints.implementation"></a>

 若要實作端點探索模式，請選擇 API （寫入或查詢）、建立 **DescribeEndpoints** 請求，並在傳回的 TTL 值 (s) 期間使用傳回的端點。實作程序如下所述。

**注意**  
確保您熟悉[用量備註](#Using-API.endpoint-discovery.describe-endpoints.usage-notes)。

## 實作程序
<a name="Using-API.endpoint-discovery.describe-endpoints.implementation.procedure"></a>

1.  使用 [https://docs.aws.amazon.com/timestream/latest/developerguide/API_DescribeEndpoints.html](https://docs.aws.amazon.com/timestream/latest/developerguide/API_DescribeEndpoints.html)請求，取得您要呼叫的 API 端點 [（寫入](https://docs.aws.amazon.com/timestream/latest/developerguide/API_Operations_Amazon_Timestream_Write.html)或[查詢](https://docs.aws.amazon.com/timestream/latest/developerguide/API_Operations_Amazon_Timestream_Query.html))。

   1.  使用下列兩個端點之一，為 建立[https://docs.aws.amazon.com/timestream/latest/developerguide/API_DescribeEndpoints.html](https://docs.aws.amazon.com/timestream/latest/developerguide/API_DescribeEndpoints.html)對應至所關注 API [（寫入](https://docs.aws.amazon.com/timestream/latest/developerguide/API_Operations_Amazon_Timestream_Write.html)或[查詢](https://docs.aws.amazon.com/timestream/latest/developerguide/API_Operations_Amazon_Timestream_Query.html)) 的請求。請求沒有輸入參數。請務必閱讀以下備註。  
*寫入 SDK：*  

      ```
      ingest.timestream.<region>.amazonaws.com
      ```  
*查詢 SDK：*  

      ```
      query.timestream.<region>.amazonaws.com
      ```

      區域 的 CLI 呼叫範例`us-east-1`如下。

      ```
      REGION_ENDPOINT="https://query.timestream.us-east-1.amazonaws.com"
      REGION=us-east-1
      aws timestream-write describe-endpoints \
      --endpoint-url $REGION_ENDPOINT \
      --region $REGION
      ```
**注意**  
 HTTP "Host" 標頭*也必須*包含 API 端點。如果未填入 標頭，請求將會失敗。這是所有 HTTP/1.1 請求的標準需求。如果您使用支援 1.1 或更新版本的 HTTP 程式庫，HTTP 程式庫應該會自動為您填入 標頭。
**注意**  
將 *<region>* 替換為請求所在區域的區域識別符，例如 `us-east-1`

   1. 剖析 （擷取） 端點和快取 TTL 值的回應。回應是一或多個[`Endpoint`物件 ](https://docs.aws.amazon.com/timestream/latest/developerguide/API_Endpoint.html)的陣列。每個`Endpoint`物件都包含端點地址 (`Address`) 和該端點的 TTL (`CachePeriodInMinutes`)。

1.  快取端點，直到達到指定的 TTL。

1.  當 TTL 過期時，從實作的步驟 1 重新開始擷取新的端點。

## 端點探索模式的使用備註
<a name="Using-API.endpoint-discovery.describe-endpoints.usage-notes"></a>
+ **DescribeEndpoints** 動作是 Timestream Live Analytics 區域端點唯一可辨識的動作。
+ 回應包含要對其進行 Timestream Live Analytics API 呼叫的端點清單。
+  成功回應時，清單中應該至少有一個端點。如果清單中有多個端點，則任何端點都同樣可用於 API 呼叫，而且發起人可以選擇隨機使用的端點。
+ 除了端點的 DNS 地址之外，清單中的每個端點都會指定允許使用以分鐘為單位指定端點的存留時間 (TTL)。
+ 應在傳回的 TTL 值指定的時間內快取和重複使用端點 （以分鐘為單位）。TTL 過期後，應對 **DescribeEndpoints** 進行新的呼叫，以重新整理要使用的端點，因為 TTL 過期後，端點將無法再運作。