

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

# 分析存放在 Amazon Redshift 目的地中的 Amazon SNS 訊息
<a name="firehose-message-analysis-redshift"></a>

本主題說明如何分析透過交付串流傳送至 Amazon Redshift 目的地的 Amazon SNS 訊息。

**分析透過 Firehose 交付串流傳送至 Amazon Redshift 目的地的 SNS 訊息**

1. 設定您的 Amazon Redshift 資源。如需說明，請參閱 *Amazon Redshift 入門指南*中的 [Amazon Redshift 入門](https://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html)。

1. 設定交付串流。如需說明，請參閱[《Amazon Data Firehose 開發人員指南》中的為您的目的地選擇 Amazon Redshift](https://docs.aws.amazon.com/firehose/latest/dev/create-destination.html#create-destination-redshift)。 **

1. 執行查詢。如需詳細資訊，請參閱《Amazon Redshift 管理指南》**中的[使用查詢編輯器來查詢資料庫](https://docs.aws.amazon.com/redshift/latest/mgmt/query-editor.html)。

## 查詢範例
<a name="example-rs-query"></a>

在本範例查詢中，假設下列情況：
+ 訊息會儲存在預設 `public` 結構描述的 `notifications` 表格。
+ 來自 SNS 訊息的 `Timestamp` 屬性會儲存在表格欄位資料類型為 `timestamptz` 的 `timestamp` 欄。
**注意**  
若要轉換 Amazon Redshift 端點的 JSON 中繼資料，您可以使用 SQL `COPY` 命令。如需詳細資訊，請參閱 *Amazon Redshift 資料庫開發人員指南*中的[從 JSON 範例複製](https://docs.aws.amazon.com/redshift/latest/dg/r_COPY_command_examples.html#r_COPY_command_examples-copy-from-json)和[使用「auto 忽略」選項從 JSON 資料載入](https://docs.aws.amazon.com/redshift/latest/dg/r_COPY_command_examples.html#copy-from-json-examples-using-auto-ignorecase)。

下列查詢會傳回在指定日期範圍內收到的所有 SNS 訊息：

```
SELECT *
FROM public.notifications
WHERE timestamp > '2020-12-01T09:00:00.000Z' AND timestamp < '2020-12-02T09:00:00.000Z';
```