

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

# 了解 Amazon SNS 資料保護政策
<a name="sns-message-data-protection-policies"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

## 什麼是資料保護政策？
<a name="what-are-data-protection-policies"></a>

Amazon SNS 使用**資料保護政策**來選取您要掃描的敏感資料，以及您想要採取的動作以防止 Amazon SNS 主題交換該資料。若要選擇感興趣的敏感資料，請使用[資料識別符](sns-message-data-protection-managed-data-identifiers.md)。然後，Amazon SNS 訊息資料保護會使用機器學習和模式比對來偵測敏感資料。若要根據找到的資料識別符採取行動，您可以定義**稽核**、**去識別化**或**拒絕**操作。這些操作可讓您記錄找到 (或找不到) 的敏感資料、遮罩或修訂敏感資料，或拒絕訊息傳遞。

![\[Amazon SNS 利用資料保護政策來管理和保護不同位置的敏感資料 AWS 服務。它會顯示傳入和傳出訊息的工作流程，詳細說明如何根據稽核、取消識別或拒絕資料傳輸等政策設定來監控資料和採取動作，以保護個人身分識別資訊 (PII) 和受保護醫療資訊 (PHI) 等資訊。\]](http://docs.aws.amazon.com/zh_tw/sns/latest/dg/images/message-data-protection-policies-overview.png)


## 資料保護政策的結構如何？
<a name="overview-of-data-protection-policies"></a>

如下圖所示，資料保護政策文件包含以下元素：
+ 在文件最上方選用的整體政策資訊
+ 一或多個個別的陳述式

每個陳述式包含關於單一許可的資訊。

![\[Amazon SNS 中資料保護政策的結構，說明政策如何由政策名稱、描述、版本和多個陳述式等各種元素組成，這些元素指定了動作，例如根據資料方向、識別符和涉及的委託人進行稽核、取消識別或拒絕。\]](http://docs.aws.amazon.com/zh_tw/sns/latest/dg/images/payload-policy-process.png)


每個 Amazon SNS 主題只能定義一個資料保護政策。資料保護政策可以有一或多個拒絕或去識別化陳述式，但只能有一個稽核陳述式。

### 資料保護政策的 JSON 屬性
<a name="data-protection-policy-json-properties"></a>

資料保護政策需要下列基本政策資訊才能識別：
+ **Name** - 政策名稱。
+ **Description** (選用) - 政策描述。
+ **Version** - 政策語言版本。目前版本是 2021-06-01。
+ **Statement** - 指定資料保護政策動作的陳述式清單。

```
{
  "Name": "basicPII-protection",
  "Description": "Protect basic types of sensitive data",
  "Version": "2021-06-01",
  "Statement": [
        ...
  ]
}
```

### 政策陳述式的 JSON 屬性
<a name="policy-statement-json-properties"></a>

政策陳述式會設定資料保護操作的偵測內容。
+ **Sid** (選用) - 陳述式識別符。
+ **DataDirection** - 與 Amazon SNS 主題相關的傳入 (針對發佈 API 請求) 或傳出 (用於通知交付)。
+ **DataIdentifier** - Amazon SNS 主題應掃描的敏感資料。例如，姓名、地址或電話號碼。
+ **Principal** - 發布至主題的 IAM 主體，或訂閱主題的 IAM 主體。
+ **操作** - Amazon SNS 主題找到敏感資料後會執行的後續動作：**Audit** (稽核)、**De-identify** (去識別化) (遮罩或修改) 或**Deny** (拒絕) (封鎖)。

```
{
    "Sid": "basicPII-inbound-protection",
    "DataDirection": "Inbound",
    "Principal": ["*"],
    "DataIdentifier": [
        "arn:aws:dataprotection::aws:data-identifier/Name",
        "arn:aws:dataprotection::aws:data-identifier/PhoneNumber-US"
    ],
    "Operation": {
        ...
    }
}
```

### 政策陳述式操作的 JSON 屬性
<a name="statement-operation-json-properties"></a>

政策陳述式會設定下列其中一項資料保護操作。
+ [**Audit**](sns-message-data-protection-operations.md#statement-operation-json-properties-audit) - 發出指標和發現結果日誌，但不中斷訊息發佈或傳遞。
+ [**去識別化**](sns-message-data-protection-operations.md#statement-operation-json-properties-deidentify) - 遮罩或修改敏感資料，而不中斷訊息發佈。
+ [**Deny**](sns-message-data-protection-operations.md#statement-operation-json-properties-deny) - 封鎖 Amazon SNS 發佈請求或讓訊息傳遞失敗。

## 如何判斷資料保護政策的 IAM 主體？
<a name="data-protection-policy-iam-principal-determined"></a>

訊息資料保護使用兩個與 Amazon SNS 互動的 IAM 主體。

1. **發佈 API 主體** (傳入) - 已驗證的 IAM 主體，呼叫 Amazon SNS `Publish` API。

1. **訂閱主體** (傳出) - 已驗證的 IAM 主體，在建立訂閱期間呼叫 `Subscribe` API。

`SubscriptionPrincipal` 是公開可用的 Amazon SNS 訂閱屬性，可從 `GetSubscriptionAttributes` API 擷取。

```
{
  "Attributes": {
    "SubscriptionPrincipal": "arn:aws:iam::123456789012:user/NoNameAccess",
    "Owner": "123412341234",
    "RawMessageDelivery": "true",
    "TopicArn": "arn:aws:sns:us-east-1:123412341234:PII-data-topic",
    "Endpoint": "arn:aws:sqs:us-east-1:123456789012:NoNameAccess",
    "Protocol": "sqs",
    "PendingConfirmation": "false",
    "ConfirmationWasAuthenticated": "true",
    "SubscriptionArn": "arn:aws:sns:us-east-1:123412341234:PII-data-topic:5d8634ef-67ef-49eb-a824-4042b28d6f55"
  }
}
```

# Amazon SNS 中的資料保護政策操作
<a name="sns-message-data-protection-operations"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

以下是您可以用來稽核和拒絕敏感資料的資料保護政策的範例。如需包含範例應用程式的完整教學課程，請參閱 [Introducing message data protection for Amazon SNS](https://aws.amazon.com/blogs/compute/introducing-message-data-protection-for-amazon-sns/) (Amazon SNS 的訊息資料保護簡介) 部落格文章。

## Audit 操作
<a name="statement-operation-json-properties-audit"></a>

**稽核**操作會範例傳入訊息主題，並記錄 AWS 目的地中的敏感資料問題清單。取樣率可以是介於 0-99 之間的整數。此操作需要下列其中一種記錄目的地類型：

1. **FindingsDestination** - Amazon SNS 主題在承載中找到敏感資料時的記錄目的地。

1. **NoFindingsDestination** - Amazon SNS 主題在承載中找不到敏感資料時的記錄目的地。

您可以在下列每種日誌目的地類型 AWS 服務 中使用下列項目：
+ **Amazon CloudWatch Logs** (選用) - `LogGroup` 必須在主題區域中，且名稱開頭必須是 **/aws/vendedlogs/**。
+ ** **（選用） – `DeliveryStream`必須在主題區域中，並以 **Direct PUT** 做為交付串流的來源。如需其他詳細資訊，請參閱《*Amazon Data Firehose 開發人員指南*》中的[來源、目的地和名稱](https://docs.aws.amazon.com/firehose/latest/dev/create-name.html)。
+ **Amazon S3** (選用) - Amazon S3 儲存貯體名稱。[在啟用 SSE-KMS 加密的情況下使用 Amazon S3 儲存貯體，需要採取額外動作](#flow-logs-s3-cmk-policy)。

```
{
  "Operation": {
    "Audit": {
      "SampleRate": "99",
      "FindingsDestination": {
            "CloudWatchLogs": {
                "LogGroup": "/aws/vendedlogs/log-group-name"
            },
            "Firehose": {
                "DeliveryStream": "delivery-stream-name"
            },
            "S3": {
                "Bucket": "bucket-name"
            }
      },
      "NoFindingsDestination": {
            "CloudWatchLogs": {
                "LogGroup": "/aws/vendedlogs/log-group-name"
            },
            "Firehose": {
                "DeliveryStream": "delivery-stream-name"
            },
            "S3": {
                "Bucket": "bucket-name"
            }
      }
    }
  }
}
```

### 指定日誌目的地時所需的許可
<a name="required-permissions-log-operations"></a>

當您在資料保護政策中指定記錄目的地時，必須使用 `--data-protection-policy` 參數，將下列許可新增至呼叫 Amazon SNS `PutDataProtectionPolicy` API 或 `CreateTopic` API 之 IAM 主體的 IAM 身分政策。


| 稽核目的地 | IAM 許可 | 
| --- | --- | 
| 預設 | logs:CreateLogDelivery logs:GetLogDelivery logs:UpdateLogDelivery logs:DeleteLogDelivery logs:ListLogDeliveries  | 
| CloudWatchLogs | logs:PutResourcePolicy logs:DescribeResourcePolicies logs:DescribeLogGroups  | 
| Firehose | iam:CreateServiceLinkedRole firehose:TagDeliveryStream  | 
| S3 | s3:PutBucketPolicy s3:GetBucketPolicy [在啟用 SSE-KMS 加密的情況下使用 Amazon S3 儲存貯體，需要採取額外動作](#flow-logs-s3-cmk-policy)。  | 

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogDelivery",
                "logs:GetLogDelivery",
                "logs:UpdateLogDelivery",
                "logs:DeleteLogDelivery",
                "logs:ListLogDeliveries"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:PutResourcePolicy",
                "logs:DescribeResourcePolicies",
                "logs:DescribeLogGroups"
            ],
            "Resource": [
                "arn:aws:logs:us-west-1:123456789012:SampleLogGroupName:*:*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "iam:CreateServiceLinkedRole",
                "firehose:TagDeliveryStream"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutBucketPolicy",
                "s3:GetBucketPolicy"
            ],
            "Resource": [
                "arn:aws:s3:::bucket-name"
            ]
        }
    ]
}
```

------

#### 搭配 SSE-KMS 使用的必要金鑰政策
<a name="flow-logs-s3-cmk-policy"></a>

如果您使用 Amazon S3 儲存貯體做為日誌目的地，您可以透過啟用伺服器端加密搭配 Amazon S3-Managed管金鑰 (SSE-S3) 或伺服器端加密搭配 AWS KMS keys (SSE-KMS) 來保護儲存貯體中的資料。如需詳細資訊，請參閱《*Amazon S3 使用者指南*》中的[使用伺服器端加密保護資料](https://docs.aws.amazon.com/AmazonS3/latest/userguide/serv-side-encryption.html)。

如果您選擇 SSE-S3，則不需要其他組態。Amazon S3 會處理加密金鑰。

若您選擇 SSE-KMS，則必須使用客戶受管金鑰。您必須更新客戶受管金鑰的金鑰政策，以讓日誌傳遞帳戶能夠寫入您的 S3 儲存貯體。如需詳細資訊，請參閱《Amazon CloudWatch Logs 使用者指南》中的 [Amazon S3 儲存貯體伺服器端加密](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-logs-SSE-KMS-S3)。

### 稽核目的地日誌範例
<a name="data-protection-policy-audit-destination-log"></a>

在以下範例中，`callerPrincipal` 用於識別敏感內容來源，`messageID` 用作檢查 `Publish` API 回應的參考。

```
{
  "messageId": "34d9b400-c6dd-5444-820d-fbeb0f1f54cf",
  "auditTimestamp": "2022-05-12T2:10:44Z",
  "callerPrincipal": "arn:aws:iam::123412341234:role/Publisher",
  "resourceArn": "arn:aws:sns:us-east-1:123412341234:PII-data-topic",
  "dataIdentifiers": [
    {
      "name": "Name",
      "count": 1,
      "detections": [
        {
          "start": 1,
          "end": 2
        }
      ]
    },
    {
      "name": "PhoneNumber",
      "count": 2,
      "detections": [
        {
          "start": 3,
          "end": 4
        },
        {
          "start": 5,
          "end": 6
        }
      ]
    }
  ]
}
```

### Audit 操作指標
<a name="data-protection-policy-audit-metrics"></a>

當 audit 操作已指定 `FindingsDestination` 或 `NoFindingsDestination` 屬性時，主題擁有者也會收到 CloudWatch `MessagesWithFindings` 和 `MessagesWithNoFindings` 指標。

![\[顯示指定期間內資料的稽核範例。\]](http://docs.aws.amazon.com/zh_tw/sns/latest/dg/images/audit-operations-metrics.png)


## 去識別化操作
<a name="statement-operation-json-properties-deidentify"></a>

**去識別化**操作會遮罩或修訂已發布或交付訊息中的敏感資料。此操作適用於傳入與傳出訊息，且需要下列其中一種設定類型：
+ **MaskConfig** - 使用下表中支援的字元進行遮罩。例如，ssn:`123-45-6789` 變成 ssn:`###########`。

  ```
  {
  "Operation": {
      "Deidentify": {
          "MaskConfig": {
              "MaskWithCharacter": "#"
            }
      }
  }
  ```    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sns/latest/dg/sns-message-data-protection-operations.html)
+ **RedactConfig** - 完全刪除資料以進行修訂。例如，ssn:`123-45-6789` 變成 ssn:` `。

  ```
  {
  "Operation": {
      "Deidentify": {
          "RedactConfig": {}
      }
  }
  ```

在傳入訊息上，會在稽核操作後去識別化敏感資料，且當整則訊息皆敏感時，`SNS:Publish` API 呼叫者會收到下列無效參數錯誤。

`Error code: AuthorizationError ...`

## Deny 操作
<a name="statement-operation-json-properties-deny"></a>

如果訊息包含敏感資料，**Deny** 操作會中斷 `Publish` API 請求或訊息傳遞。Deny 操作物件是空的，因為它不需要額外的組態。

```
"Operation": {
    "Deny": {}
}
```

在傳入訊息上，`SNS:Publish` API 呼叫者會收到授權錯誤。

`Error code: AuthorizationError ...`

在傳出訊息上，Amazon SNS 主題不會將訊息傳遞至訂閱。若要追蹤未經授權的傳遞，請啟用主題的[傳遞狀態記錄](sns-topic-attributes.md)。下列為傳遞狀態日誌的範例：

```
{
    "notification": {
        "messageMD5Sum": "29638742ffb68b32cf56f42a79bcf16b",
        "messageId": "34d9b400-c6dd-5444-820d-fbeb0f1f54cf",
        "topicArn": "arn:aws:sns:us-east-1:123412341234:PII-data-topic",
        "timestamp": "2022-05-12T2:12:44Z"
    },
    "delivery": {
        "deliveryId": "98236591c-56aa-51ee-a5ed-0c7d43493170",
        "destination": "arn:aws:sqs:us-east-1:123456789012:NoNameAccess",
        "providerResponse": "The topic's data protection policy prohibits this message from being delivered to <subscription-arn>",
        "dwellTimeMs":20,
        "attempts":1,
        "statusCode": 403
    },
    "status": "FAILURE"
}
```

# Amazon SNS 資料保護政策範例
<a name="sns-message-data-protection-examples"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

以下範例是您可以用來稽核和拒絕敏感資料的資料保護政策。如需包含範例應用程式的完整教學課程，請參閱 [Introducing message data protection for Amazon SNS](https://aws.amazon.com/blogs/compute/introducing-message-data-protection-for-amazon-sns/) (Amazon SNS 的訊息資料保護簡介) 部落格文章。

## 稽核的範例政策
<a name="sns-message-data-protection-audit-example"></a>

稽核政策可讓您稽核高達 99% 的傳入訊息，並將調查結果傳送至 [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)[https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html](https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html)、 和 [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)。

例如，您可以建立稽核政策來評估是否有任何系統意外傳送或接收敏感資料。如果稽核結果顯示系統正在傳送信用卡資訊至不需要此資訊的系統，您可以使用封鎖政策來防止資料的傳遞。

以下範例透過尋找信用卡號碼並將調查結果傳送至 CloudWatch Logs、Firehose 和 Amazon S3 來稽核 99% 通過主題的訊息。

**資料保護政策**：

```
{
  "Name": "__example_data_protection_policy",
  "Description": "Example data protection policy",
  "Version": "2021-06-01",
  "Statement": [
    {
      "DataDirection": "Inbound",
      "Principal": ["*"],
      "DataIdentifier": [
        "arn:aws:dataprotection::aws:data-identifier/CreditCardNumber"
      ],
      "Operation": {
        "Audit": {
          "SampleRate": "99",
          "FindingsDestination": {
            "CloudWatchLogs": {
              "LogGroup": "<example log name>"
            },
            "Firehose": {
              "DeliveryStream": "<example stream name>"
            },
            "S3": {
              "Bucket": "<example bucket name>"
            }
          }
        }
      }
    }
  ]
}
```

**稽核結果格式範例**：

```
{
    "messageId": "...",
    "callerPrincipal": "arn:aws:sts::123456789012:assumed-role/ExampleRole",
    "resourceArn": "arn:aws:sns:us-east-1:123456789012:ExampleArn", 
    "dataIdentifiers": [
        {
            "name": "CreditCardNumber",
            "count": 1,
            "detections": [
                { "start": 1, "end": 2 }
            ]
        }
    ],
    "timestamp": "2021-04-20T00:33:40.241Z"
}
```

## 政策傳入去識別化遮罩陳述式範例
<a name="sns-message-data-protection-inbound-deidentify-mask-example"></a>

下列範例會遮罩訊息內容中的敏感資料，防止使用者將訊息發佈至含有 `CreditCardNumber` 的主題。

```
{
  "Name": "__example_data_protection_policy",
  "Description": "Example data protection policy",
  "Version": "2021-06-01",
  "Statement": [
    {
      "DataDirection": "Inbound",
      "Principal": [
        "arn:aws:iam::123456789012:user/ExampleUser"
      ],
      "DataIdentifier": [
        "arn:aws:dataprotection::aws:data-identifier/CreditCardNumber"
      ],
      "Operation": {
        "Deidentify": {
          "MaskConfig": {
            "MaskWithCharacter": "#"
          }
        }
      }
    }
  ]
}
```

**傳入去識別化修改結果範例：**

```
// original message
My credit card number is 4539894458086459

// delivered message
My credit card number is ################
```

## 政策傳入去識別化修改陳述式範例
<a name="sns-message-data-protection-inbound-deidentify-redact-example"></a>

下列範例會修訂訊息內容中的敏感資料，防止使用者將訊息發佈至含有 `CreditCardNumber` 的主題。

```
{
  "Name": "__example_data_protection_policy",
  "Description": "Example data protection policy",
  "Version": "2021-06-01",
  "Statement": [
    {
      "DataDirection": "Inbound",
      "Principal": [
        "arn:aws:iam::123456789012:user/ExampleUser"
      ],
      "DataIdentifier": [
        "arn:aws:dataprotection::aws:data-identifier/CreditCardNumber"
      ],
      "Operation": {
        "Deidentify": {
          "RedactConfig": {}
        }
      }
    }
  ]
}
```

**傳入去識別化修訂結果範例：**

```
// original message
My credit card number is 4539894458086459

// delivered message
My credit card number is
```

## 政策傳出去識別化遮罩陳述式範例
<a name="sns-message-data-protection-outbound-deidentify-mask-example"></a>

下列範例會遮罩訊息內容中的敏感資料，防止使用者接收含有 `CreditCardNumber` 的訊息。

```
{
  "Name": "__example_data_protection_policy",
  "Description": "Example data protection policy",
  "Version": "2021-06-01",
  "Statement": [
    {
      "DataDirection": "Outbound",
      "Principal": [
        "arn:aws:iam::123456789012:user/ExampleUser"
      ],
      "DataIdentifier": [
        "arn:aws:dataprotection::aws:data-identifier/CreditCardNumber"
      ],
      "Operation": {
        "Deidentify": {
          "MaskConfig": {
            "MaskWithCharacter": "-"
          }
        }
      }
    }
  ]
}
```

**傳出去識別化遮罩結果範例：**

```
// original message
My credit card number is 4539894458086459

// delivered message
My credit card number is ----------------
```

## 政策傳出去識別化修改陳述式範例
<a name="sns-message-data-protection-outbound-deidentify-redact-example"></a>

下列範例會修改訊息內容中的敏感資料，防止使用者接收含有 `CreditCardNumber` 的訊息。

```
{
  "Name": "__example_data_protection_policy",
  "Description": "Example data protection policy",
  "Version": "2021-06-01",
  "Statement": [
    {
      "DataDirection": "Outbound",
      "Principal": [
        "arn:aws:iam::123456789012:user/ExampleUser"
      ],
      "DataIdentifier": [
        "arn:aws:dataprotection::aws:data-identifier/CreditCardNumber"
      ],
      "Operation": {
        "Deidentify": {
          "RedactConfig": {}
        }
      }
    }
  ]
}
```

**傳出去識別化修訂結果範例：**

```
// original message
My credit card number is 4539894458086459

// delivered message
My credit card number is
```

## 政策傳入拒絕陳述式範例
<a name="sns-message-data-protection-inbound-deny-example"></a>

下列範例會防止使用者將訊息內容中有 `CreditCardNumber` 的訊息發佈至主題。API 回應中遭拒的承載狀態碼為「403 AuthorizationError」。

```
{
  "Name": "__example_data_protection_policy",
  "Description": "Example data protection policy",
  "Version": "2021-06-01",
  "Statement": [
    {
      "DataDirection": "Inbound",
      "Principal": [
        "arn:aws:iam::123456789012:user/ExampleUser"
      ],
      "DataIdentifier": [
        "arn:aws:dataprotection::aws:data-identifier/CreditCardNumber"
      ],
      "Operation": {
        "Deny": {}
      }
    }
  ]
}
```

## 傳出拒絕陳述式的政策範例
<a name="sns-message-data-protection-outbound-deny-example"></a>

下列範例會封鎖 AWS 帳戶接收包含 的訊息`CreditCardNumber`。

```
{
  "Name": "__example_data_protection_policy",
  "Description": "Example data protection policy",
  "Version": "2021-06-01",
  "Statement": [
    {
      "DataDirection": "Outbound",
      "Principal": [
        "arn:aws:iam::123456789012:user/ExampleUser"
      ],
      "DataIdentifier": [
        "arn:aws:dataprotection::aws:data-identifier/CreditCardNumber"
      ],
      "Operation": {
        "Deny": {}
      }
    }
  ]
}
```

**Amazon CloudWatch 中記錄的傳出拒絕結果範例：**

```
{
  "notification": {
    "messageMD5Sum": "2e8f58ff2eeed723b56b15493fbfb5a5",
    "messageId": "8747a956-ebf1-59da-b291-f2c2e4b87c9c",
    "topicArn": "arn:aws:sns:us-east-2:664555388960:test1",
    "timestamp": "2022-09-08 15:40:57.144"
  },
  "delivery": {
    "deliveryId": "6a422437-78cc-5171-ad64-7fa3778507aa",
    "destination": "arn:aws:sqs:us-east-2:664555388960:test",
    "providerResponse": "The topic's data protection policy prohibits this message from being delivered to <subscription arn>",
    "dwellTimeMs": 22,
    "attempts": 1,
    "statusCode": 403
  },
  "status": "FAILURE"
}
```

# 在 Amazon SNS 中建立資料保護政策
<a name="sns-message-data-protection-configure"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

[資料保護政策](sns-message-data-protection-policies.md)透過稽核、去識別化 (遮罩或修訂) 和拒絕 (封鎖) 在應用程式或 AWS 服務服務之間移動的敏感資料，來保護發佈到 Amazon SNS 主題的資料。您可以使用 AWS API AWS CLI、 CloudFormation或 AWS 管理主控台 在 Amazon SNS 中建立資料保護政策。每個 Amazon SNS 主題只能定義一個政策。每個資料保護政策可以有一或多個去識別化和拒絕陳述式，但只能有一個稽核陳述式。

**Topics**
+ [使用 API](sns-message-data-protection-configure-api.md)
+ [使用 AWS CLI](sns-message-data-protection-configure-cli.md)
+ [使用 CloudFormation](sns-message-data-protection-configure-cfn.md)
+ [使用 AWS 管理主控台](sns-message-data-protection-configure-console.md)
+ [使用 AWS SDK](sns-message-data-protection-configure-sdk.md)

# 使用 API 在 Amazon SNS 中建立資料保護政策
<a name="sns-message-data-protection-configure-api"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

 AWS 帳戶中 Amazon SNS 資源的數量和大小有限。如需詳細資訊，請參閱 [Amazon Simple Notification Service 端點和配額](https://docs.aws.amazon.com/general/latest/gr/sns.html)。

## 使用 API 建立資料保護政策
<a name="create-policies-api"></a>

使用 AWS API 建立 Amazon SNS 資料保護政策。

**建立資料保護政策與 Amazon SNS 主題 (AWS API)**  
使用標準 Amazon SNS 主題的 `DataProtectionPolicy` 屬性：
+ [https://docs.aws.amazon.com/sns/latest/api/API_CreateTopic.html](https://docs.aws.amazon.com/sns/latest/api/API_CreateTopic.html)

**擷取或建立現有 Amazon SNS 主題 (AWS API) 的資料保護政策**  
呼叫以下其中一項操作：
+ [GetDataProtectionPolicy](https://docs.aws.amazon.com/sns/latest/api/API_GetDataProtectionPolicy.html)
+ [PutDataProtectionPolicy](https://docs.aws.amazon.com/sns/latest/api/API_PutDataProtectionPolicy.html)

# 使用 CLI 在 Amazon SNS 中建立資料保護政策
<a name="sns-message-data-protection-configure-cli"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

 AWS 帳戶中 Amazon SNS 資源的數量和大小有限。如需詳細資訊，請參閱 [Amazon Simple Notification Service 端點和配額](https://docs.aws.amazon.com/general/latest/gr/sns.html)。

## 使用 建立資料保護政策 AWS CLI
<a name="create-policies-cli"></a>

使用 建立 Amazon SNS 資料保護政策 AWS Command Line Interface。

**若要與 Amazon SNS 主題一起建立資料保護政策 (AWS CLI)**  
使用此選項，與標準 Amazon SNS 主題一起建立新的資料保護政策：
+ [create-topic](https://docs.aws.amazon.com/cli/latest/reference/sns/create-topic.html)

**若要建立或擷取現有 Amazon SNS 主題的資料保護政策 (AWS CLI)**  
呼叫以下其中一項操作：
+ [get-data-protection-policy](https://docs.aws.amazon.com/cli/latest/reference/sns/get-data-protection-policy.html)
+ [put-data-protection-policy](https://docs.aws.amazon.com/cli/latest/reference/sns/put-data-protection-policy.html)

# 使用 CloudFormation 在 Amazon SNS 中建立資料保護政策
<a name="sns-message-data-protection-configure-cfn"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

 AWS 帳戶中 Amazon SNS 資源的數量和大小有限。如需詳細資訊，請參閱 [Amazon Simple Notification Service 端點和配額](https://docs.aws.amazon.com/general/latest/gr/sns.html)。

## 建立資料保護政策 (CloudFormation)
<a name="create-policies-cfn"></a>

使用 建立 Amazon SNS 資料保護政策 CloudFormation。

**若要與 Amazon SNS 主題一起建立資料保護政策 (CloudFormation)**  
使用此選項，與標準 Amazon SNS 主題一起建立新的資料保護政策：
+ [AWS::SNS::Topic](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-topic.html)

# 使用主控台在 Amazon SNS 中建立資料保護政策
<a name="sns-message-data-protection-configure-console"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

 AWS 帳戶中 Amazon SNS 資源的數量和大小有限。如需詳細資訊，請參閱 [Amazon Simple Notification Service 端點和配額](https://docs.aws.amazon.com/general/latest/gr/sns.html)。

**若要與 Amazon SNS 主題一起建立資料保護政策 (主控台)**  
使用此選項可同時建立新的資料保護政策與標準 Amazon SNS 主題。

1. 登入 [Amazon SNS 主控台](https://console.aws.amazon.com/sns/home)。

1. 選擇主題或建立新主題。如需建立主題的詳細資訊，請參閱[建立 Amazon SNS 主題](sns-create-topic.md)。

1. 在 **Create topic** (建立主題) 頁面的 **Details** (詳細資訊) 區段中，選擇 **Standard** (標準)。

   1. 輸入新主題的 **名稱** (Name)。

   1. (選用) 為主題輸入 **Display name** (顯示名稱)。

1. 展開 **Data protection policy** (資料保護政策)。

1. 選擇 **Configuration mode** (組態模式)：
   + **Basic** (基本) - 使用簡單的功能表定義資料保護政策。
   + **Advanced** (進階) - 使用 JSON 定義自訂資料保護政策。

1. (選用) 若要建立自己的**自訂資料識別符**，請展開**自訂資料識別符組態區段**，並執行下列動作：

   1. 輸入自訂資料識別符的唯一**名稱**。自訂資料識別符的名稱可支援英數字、底線 (\$1) 和連字號 (-) 字元。最多可支援 128 個字元。此名稱不可與[受管資料識別符](sns-message-data-protection-managed-data-identifiers.md)的名稱相同。如需自訂資料識別符限制的完整清單，請參閱 [自訂資料識別符的限制](sns-message-data-protection-custom-data-identifiers.md#custom-data-identifiers-limitations)。

   1. 輸入自訂資料識別符的規則運算式 (RegEx)。RegEx 可支援英數字元、RegEx 保留字元和符號。RegEx 的長度上限為 200 個字元。如果 RegEx 太過複雜，Amazon SNS 會讓 API 呼叫失敗。如需 RegEx 限制的完整清單，請參閱 [自訂資料識別符的限制](sns-message-data-protection-custom-data-identifiers.md#custom-data-identifiers-limitations)。

   1. (選用) 選擇**新增自訂資料識別符**，視需要新增其他資料識別符。每個資料保護政策最多可支援 10 個自訂資料識別符。

1. 選擇您要新增至資料保護政策的陳述式。您可以將**audit** (稽核)、**de-identify** (去識別化) (遮罩或修訂) 和**deny** (拒絕) (封鎖) 陳述式類型新增至相同的資料保護政策。

   1. **Add audit statement** (新增稽核陳述式) - 設定要稽核的敏感資料、要稽核該資料的訊息百分比，以及將稽核日誌傳送到何處。
**注意**  
每個資料保護政策或主題僅允許一個稽核陳述式。

      1. 選取 **data identifiers** (資料識別符) 定義您要稽核的敏感資料。

      1. 對於 **Audit sample rate** (稽核採樣率)，輸入要稽核機密資訊的訊息百分比，上限為 99%。

      1. 針對**稽核目的地**，選取要 AWS 服務 傳送稽核調查結果結果的目的地，然後輸入 AWS 服務 您使用的每個目的地名稱。您可以從以下 Amazon Web Services 中進行選擇：
         + **Amazon CloudWatch** - CloudWatch Logs 是 AWS 標準記錄解決方案。使用 CloudWatch Logs，您可以使用 Logs Insights 執行日誌分析 ([在這裡查看範例](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax-examples.html)) 並建立指標和警示。CloudWatch Logs 是許多服務發佈日誌的地方，這可以簡化使用單一解決方案彙總所有日誌。如需 Amazon CloudWatch 的詳細資訊，請參閱 [Amazon CloudWatch 使用者指南](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)。
         + **** – Firehose 滿足即時串流至 Splunk、OpenSearch 和 Amazon Redshift 的需求，以進行進一步的日誌分析。如需 的相關資訊，請參閱[《 使用者指南》](https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html)。
         + **Amazon Simple Storage Service** - Amazon S3 是用於存檔的經濟型日誌目的地。您可能需要保留日誌一段時間。在此情況下，您可以將日誌放入 Amazon S3 中以節省成本。如需 Amazon Simple Storage Service 的相關資訊，請參閱 [Amazon Simple Storage Service 使用者指南](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)。

   1. **Add a de-identify statement** (新增去識別化陳述式) - 設定您要在訊息中去識別化 (無論遮罩或修訂) 的敏感資料，以及停止傳遞該資料的帳戶。

      1. 針對 **Data identifiers** (資料識別符)，請選取您要去識別化的敏感資料。

      1. 針對**定義此去識別化陳述**式，選取套用此去識別化陳述式 AWS 的帳戶或 IAM 主體。您可以將其套用至**所有 AWS 帳戶**，或使用帳戶 ID 或 IAM 實體 ARN 的**特定 AWS 帳戶**或 **IAM 實體** (帳戶根目錄、角色或使用者)。使用逗號 (,) 分隔多個 ID 或 ARN。

         以下是支援的 [IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html) 主體：
         + **IAM account principals** (IAM 帳戶主體) - 例如 `arn:aws:iam::AWS-account-ID:root`。
         + **IAM role principals** (IAM 角色主體) - 例如 `arn:aws:iam::AWS-account-ID:role/role-name`。
         + **IAM user principals** (IAM 使用者主體) - 例如 `arn:aws:iam::AWS-account-ID:user/user-name`。

      1. 針對 **De-identify Option** (去識別化選項)，請選取您要如何去識別化敏感資料。支援下列選項：
         + **Redact** (修訂) - 完全移除資料。例如，電子郵件：`classified@amazon.com` 變成電子郵件：` `。
         + **Mask** (遮罩) - 以單一字元取代資料。例如，電子郵件：`classified@amazon.com` 變成電子郵件：`*********************`。

      1. (選用) 視需要繼續新增去識別化陳述式。

   1. **Add deny statement** (新增拒絕陳述式) - 設定要防止在您的主題中移動的敏感資料，以及要防止哪些主參與者傳送該資料。

      1. 針對 **data direction** (資料方向)，請選擇拒絕陳述式的訊息方向：
         + **Inbound messages** (傳入訊息) - 將此拒絕陳述式套用至傳送至主題的訊息。
         + **Outbound messages** (傳出訊息) - 將此拒絕陳述式套用至主題傳遞給訂閱端點的訊息。

      1. 選擇 **data identifiers** (資料識別符) 定義您要拒絕的敏感資料。

      1. 選擇此拒絕陳述式套用的 **IAM principals** (IAM 主體)。您可以將其套用至使用** AWS 帳戶 ID 或 IAM 實體 ARN 的所有**帳戶、**特定 AWS 帳戶**或 IAM 實體 （例如帳戶根目錄、角色或使用者）。 **** IDs ARNs 使用逗號 (,) 分隔多個 ID 或 ARN。以下是支援的 [IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html) 主體：
         + **IAM account principals** (IAM 帳戶主體) - 例如 `arn:aws:iam::AWS-account-ID:root`。
         + **IAM role principals** (IAM 角色主體) - 例如 `arn:aws:iam::AWS-account-ID:role/role-name`。
         + **IAM user principals** (IAM 使用者主體) - 例如 `arn:aws:iam::AWS-account-ID:user/user-name`。

      1. (選用) 視需要繼續新增拒絕陳述式。

# 使用 SDK 建立 Amazon SNS 資料保護政策以保護訊息資料
<a name="sns-message-data-protection-configure-sdk"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

 AWS 帳戶中 Amazon SNS 資源的數量和大小有限。如需詳細資訊，請參閱 [Amazon Simple Notification Service 端點和配額](https://docs.aws.amazon.com/general/latest/gr/sns.html)。

## 使用 AWS SDK 建立資料保護政策
<a name="create-policies-sdk"></a>

使用 AWS SDK 建立 Amazon SNS 資料保護政策。

**建立資料保護政策與 Amazon SNS 主題 (AWS SDK)**  
使用下列選項，與標準 Amazon SNS 主題一起建立新的資料保護政策：

------
#### [ Java ]

```
/**
 * For information regarding CreateTopic see this documentation topic:
 *
 * https://docs.aws.amazon.com/code-samples/latest/catalog/javav2-sns-src-main-java-com-example-sns-CreateTopic.java.html
 */

public static String createSNSTopicWithDataProtectionPolicy(SnsClient snsClient, String topicName, String dataProtectionPolicy) {

    try {
        CreateTopicRequest request = CreateTopicRequest.builder()
                .name(topicName)
                .dataProtectionPolicy(dataProtectionPolicy)
                .build();

        CreateTopicResponse result = snsClient.createTopic(request);
        return result.topicArn();
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
```

------
#### [ JavaScript ]

```
// Import required AWS SDK clients and commands for Node.js
import {CreateTopicCommand } from "@aws-sdk/client-sns";
import {snsClient } from "./libs/snsClient.js";

// Set the parameters
const params = { Name: "TOPIC_NAME", DataProtectionPolicy: "DATA_PROTECTION_POLICY" };

const run = async () => {
  try {
    const data = await snsClient.send(new CreateTopicCommand(params));
    console.log("Success.",  data);
    return data; // For unit tests.
  } catch (err) {
    console.log("Error", err.stack);
  }
};
run();
```

------

**建立或擷取現有 Amazon SNS 主題 (AWS SDK) 的資料保護政策**  
使用下列選項，與標準 Amazon SNS 主題一起建立或擷取新的資料保護政策：

------
#### [ Java ]

```
public static void putDataProtectionPolicy(SnsClient snsClient, String topicName, String dataProtectionPolicy) {

    try {
        PutDataProtectionPolicyRequest request = PutDataProtectionPolicyRequest.builder()
                .resourceArn(topicName)
                .dataProtectionPolicy(dataProtectionPolicy)
                .build();

        PutDataProtectionPolicyResponse result = snsClient.putDataProtectionPolicy(request);
        System.out.println("\n\nStatus was " + result.sdkHttpResponse().statusCode() 
                + "\n\nTopic " + request.resourceArn()
                + " DataProtectionPolicy " + request.dataProtectionPolicy());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}


public static void getDataProtectionPolicy(SnsClient snsClient, String topicName) {

    try {
        GetDataProtectionPolicyRequest request = GetDataProtectionPolicyRequest.builder()
                .resourceArn(topicName)
                .build();
        
        GetDataProtectionPolicyResponse result = snsClient.getDataProtectionPolicy(request);
        
        System.out.println("\n\nStatus is " + result.sdkHttpResponse().statusCode() 
        + "\n\nDataProtectionPolicy: \n\n" + result.dataProtectionPolicy());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
```

------
#### [ JavaScript ]

```
// Import required AWS SDK clients and commands for Node.js
import {PutDataProtectionPolicyCommand, GetDataProtectionPolicyCommand } from "@aws-sdk/client-sns";
import {snsClient } from "./libs/snsClient.js";

// Set the parameters
const putParams = { ResourceArn: "TOPIC_ARN", DataProtectionPolicy: "DATA_PROTECTION_POLICY" };

const runPut = async () => {
  try {
    const data = await snsClient.send(new PutDataProtectionPolicyCommand(putParams));
    console.log("Success.",  data);
    return data; // For unit tests.
  } catch (err) {
    console.log("Error", err.stack);
  }
};
runPut();

// Set the parameters
const getParams = { ResourceArn: "TOPIC_ARN" };

const runGet = async () => {
  try {
    const data = await snsClient.send(new GetDataProtectionPolicyCommand(getParams));
    console.log("Success.",  data);
    return data; // For unit tests.
  } catch (err) {
    console.log("Error", err.stack);
  }
};
runGet();
```

------

# 刪除 Amazon SNS 中的資料保護政策
<a name="sns-message-data-protection-delete"></a>

**重要**  
自 2026 年 4 月 30 日起，Amazon SNS 訊息資料保護將不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

您可以使用 AWS API AWS CLI CloudFormation、 或 **刪除** Amazon SNS 資料保護政策 AWS 管理主控台。

如需 Amazon SNS 資料保護政策的一般資訊，請參閱 [了解 Amazon SNS 資料保護政策](sns-message-data-protection-policies.md)。

 AWS 帳戶中的 Amazon SNS 資料保護政策資源之數量和大小均有所限制。如需詳細資訊，請參閱 AWS 一般參考中的 [Amazon SNS API 限流](https://docs.aws.amazon.com/general/latest/gr/sns.html)。

## 使用主控台刪除資料保護政策
<a name="sns-delete-data-protection-policy"></a>

**使用主控台刪除受管資料保護政策**

1. 登入 [Amazon SNS 主控台](https://console.aws.amazon.com/sns/home)。

1. 選擇包含您要刪除之資料保護政策的主題。

1. 選擇**編輯**。

1. 展開 **Data protection policy** (資料保護政策) 區段。

1. 選擇您要移除之資料保護政策陳述式旁的 **Remove** (移除)。

1. 選擇**儲存變更**。

## 使用空的 JSON 字串刪除資料保護政策
<a name="sns-message-data-protection-remove-example-json"></a>

您可以將資料保護政策更新為空的 JSON 字串來刪除資料保護政策。

## 使用 刪除資料保護政策 AWS CLI
<a name="sns-message-data-protection-remove-example-cli"></a>

您可使用 AWS CLI刪除資料保護政策。

`//aws sns put-data-protection-policy --resource-arn topic-arn --data-protection-policy ""`