

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

# 管理 ElastiCache 亚马逊 SNS 通知
<a name="ECEvents.SNS"></a>

您可以配置 ElastiCache 为使用亚马逊简单通知服务 (Amazon SNS) Service 发送重要集群事件的通知。在这些示例中，您将使用 Amazon SNS 主题的 Amazon 资源名称（ARN）配置集群，以便接收通知。

**注意**  
此主题假设您已经注册 Amazon SNS，同时已设置并订阅 Amazon SNS 主题。有关如何执行此操作的信息，请参阅 [Amazon Simple Notification Service 开发人员指南](https://docs.amazonaws.cn/sns/latest/dg/)。
默认情况下，`API modify-replication-group` 会影响区域中的所有组，而不仅仅是当前指定的组。如果您想在一个区域中以不同于其他组的方式配置一个特定组，可以使用 `--notification-topic-arn` 选项为该组创建一个单独的主题。

## 添加 Amazon SNS 主题
<a name="ECEvents.SNS.Adding"></a>

以下各节介绍如何使用Amazon控制台、或 API 添加 Amazon SNS 主题。Amazon CLI ElastiCache 

### 添加 Amazon SNS 主题（控制台）
<a name="ECEvents.SNS.Adding.Console"></a>

 以下过程说明了如何为集群添加 Amazon SNS 主题。在步骤 2 中使用 Valkey 或 Redis OSS 为复制组添加 Amazon SNS 主题时，请选择复制组，而不是集群。然后按照相同的剩余步骤操作。

**注意**  
 此过程还可用于修改 Amazon SNS 主题。

**为集群添加或修改 Amazon SNS 主题（控制台）**

1. 登录Amazon Web Services 管理控制台并打开 ElastiCache 控制台，网址为[ https://console.aws.amazon.com/elasticache/](https://console.amazonaws.cn/elasticache/)。

1. 在 **Clusters（集群）**中，选择要为其添加或修改 Amazon SNS 主题 ARN 的集群。

1. 选择 **Modify**(修改)。

1. 在 **Topic for SNS Notification（SNS 通知的主题）**下的 **Modify Cluster（修改集群）**中，选择要添加的 SNS 主题，或选择 **Manual ARN input（手动 ARN 输入）**并键入 Amazon SNS 主题的 ARN。

1. 选择 **Modify**(修改)。

### 添加 Amazon SNS 主题 (Amazon CLI）
<a name="ECEvents.SNS.Adding.CLI"></a>

要为集群添加或修改 Amazon SNS 主题，请使用命令。Amazon CLI`modify-cache-cluster`

以下代码示例会将 Amazon SNS 主题 ARN 添加到 *my-cluster*。

对于 Linux、macOS 或 Unix：

```
aws elasticache modify-cache-cluster \
    --cache-cluster-id my-cluster \
    --notification-topic-arn arn:aws:sns:us-west-2:123456789xxx:ElastiCacheNotifications
```

对于 Windows：

```
aws elasticache modify-cache-cluster ^
    --cache-cluster-id my-cluster ^
    --notification-topic-arn arn:aws:sns:us-west-2:123456789xx:ElastiCacheNotifications
```

有关更多信息，请参阅 [modify-cache-cluster](https://docs.amazonaws.cn/cli/latest/reference/elasticache/modify-cache-cluster.html)。

### 添加亚马逊 SNS 主题 (API) ElastiCache
<a name="ECEvents.SNS.Adding.API"></a>

若要为集群添加或修改 Amazon SNS 主题，请使用下列参数调用 `ModifyCacheCluster` 操作：
+ `CacheClusterId``=my-cluster`
+ `TopicArn``=arn%3Aaws%3Asns%3Aus-west-2%3A565419523791%3AElastiCacheNotifications`

**Example**  

```
 1. https://elasticache.amazon.com/
 2.     ?Action=ModifyCacheCluster
 3.     &ApplyImmediately=false
 4.     &CacheClusterId=my-cluster
 5.     &NotificationTopicArn=arn%3Aaws%3Asns%3Aus-west-2%3A565419523791%3AElastiCacheNotifications
 6.     &Version=2014-12-01
 7.     &SignatureVersion=4
 8.     &SignatureMethod=HmacSHA256
 9.     &Timestamp=20141201T220302Z
10.     &X-Amz-Algorithm=&AWS;4-HMAC-SHA256
11.     &X-Amz-Date=20141201T220302Z
12.     &X-Amz-SignedHeaders=Host
13.     &X-Amz-Expires=20141201T220302Z
14.     &X-Amz-Credential=<credential>
15.     &X-Amz-Signature=<signature>
```

有关更多信息，请参阅 [ModifyCacheCluster](https://docs.amazonaws.cn/AmazonElastiCache/latest/APIReference/API_ModifyCacheCluster.html)。

## 启用和禁用 Amazon SNS 通知
<a name="ECEvents.SNS.Disabling"></a>

 您可以打开或关闭针对集群的通知。下面将介绍如何禁用 Amazon SNS 通知。

### 启用和禁用 Amazon SNS 通知（控制台）
<a name="ECEvents.SNS.Disabling.Console"></a>

**要禁用 Amazon SNS 通知，请使用Amazon Web Services 管理控制台**

1. 登录Amazon Web Services 管理控制台并打开 ElastiCache 控制台，网址为[ https://console.aws.amazon.com/elasticache/](https://console.amazonaws.cn/elasticache/)。

1. 要查看运行 Memcached 的集群的列表，请在导航窗格中选择 **Memcached**。

   要查看运行 Valkey 或 Redis OSS 的集群列表，请在导航窗格中选择 **Valkey** 或 **Redis OSS**。

1. 选择要修改其通知的集群左侧的框。

1. 选择 **Modify**(修改)。

1. 在 **Topic for SNS Notification** 下的 **Modify Cluster** 中，选择 *Disable Notifications*。

1. 选择 **Modify**(修改)。

### 启用和禁用 Amazon SNS 通知 (Amazon CLI）
<a name="ECEvents.SNS.Disabling.CLI"></a>

若要禁用 Amazon SNS 通知，请使用包含以下参数的命令 `modify-cache-cluster`：

对于 Linux、macOS 或 Unix：

```
aws elasticache modify-cache-cluster \
    --cache-cluster-id my-cluster \
    --notification-topic-status inactive
```

对于 Windows：

```
aws elasticache modify-cache-cluster ^
    --cache-cluster-id my-cluster ^
    --notification-topic-status inactive
```

**注意**  
当集群属于复制组时，必须使用 `modify-replication-group` CLI 命令启用或禁用 SNS 通知。

### 启用和禁用 Amazon SNS 通知 (API) ElastiCache
<a name="ECEvents.SNS.Disabling.API"></a>

若要禁用 Amazon SNS 通知，请使用下列参数调用 `ModifyCacheCluster` 操作：
+ `CacheClusterId``=my-cluster`
+ `NotificationTopicStatus``=inactive`

此调用返回类似于下述信息的输出：

**Example**  

```
 1. https://elasticache.us-west-2.amazonaws.com/
 2.     ?Action=ModifyCacheCluster
 3.     &ApplyImmediately=false
 4.     &CacheClusterId=my-cluster
 5.     &NotificationTopicStatus=inactive
 6.     &Version=2014-12-01
 7.     &SignatureVersion=4
 8.     &SignatureMethod=HmacSHA256
 9.     &Timestamp=20141201T220302Z
10.     &X-Amz-Algorithm=&AWS;4-HMAC-SHA256
11.     &X-Amz-Date=20141201T220302Z
12.     &X-Amz-SignedHeaders=Host
13.     &X-Amz-Expires=20141201T220302Z
14.     &X-Amz-Credential=<credential>
15.     &X-Amz-Signature=<signature>
```