

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

# 分析存储在 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.amazonaws.cn/redshift/latest/gsg/getting-started.html)。

1. 配置传输流。有关说明，请参阅《Amazon Data Firehose 开发人员指南》**中的[选择 Amazon Redshift 作为目标](https://docs.amazonaws.cn/firehose/latest/dev/create-destination.html#create-destination-redshift)。

1. 运行查询。有关更多信息，请参阅《Amazon Redshift 管理指南》**中的 [使用查询编辑器查询数据库](https://docs.amazonaws.cn/redshift/latest/mgmt/query-editor.html)。

## 示例查询
<a name="example-rs-query"></a>

在本示例查询中，我们假设满足以下条件：
+ 消息存储在默认 `public` schema 的 `notifications` 表中。
+ SNS 消息的 `Timestamp` 属性存储在表的 `timestamp` 列中，其列数据类型为 `timestamptz`。
**注意**  
要转换 Amazon Redshift 终端节点的 JSON 元数据，您可以使用 SQL `COPY` 命令。有关更多信息，请参阅 *Amazon Redshift 数据库开发人员指南*中的[从 JSON 中复制示例](https://docs.amazonaws.cn/redshift/latest/dg/r_COPY_command_examples.html#r_COPY_command_examples-copy-from-json)和[使用“auto ignorecase”选项从 JSON 数据中加载](https://docs.amazonaws.cn/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';
```