

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

# 请参阅设置游戏会话置放通知。
<a name="queue-notification"></a>

您可以使用Events 来监控各个放置请求的状态。我们建议为所有有大量投放活动的游戏设置事件通知。

有两个选项可用于设置事件通知。
+ 让 Amazon GameLift Servers 使用队列向 Amazon Simple Notiﬁcation Service（Amazon SNS）主题发布事件通知。
+ 使用自动发布的 Amazon EventBridge 事件及其工具套件来管理事件。

有关 Amazon GameLift Servers 发出的游戏会话放置事件的列表，请参阅[游戏会话放置事件](queue-events.md)。

**重要**  
对于高吞吐量放置系统，我们建议使用标准（非 FIFO）Amazon SNS 主题，而不是 FIFO 主题。FIFO 主题的发布限制低于标准主题，这可能会导致在高负载期间出现节流异常。如果您在使用 FIFO 主题时遇到节流，则可能会丢失队列放置通知。

## 设置 SNS 主题。
<a name="queue-notification-sns"></a>

要让 Amazon GameLift Servers 将游戏会话队列生成的所有事件发布到某个主题，请将通知目标字段设置为主题。

**为 Amazon GameLift Servers 事件通知设置 SNS 主题**

1. [登录 AWS 管理控制台 并在 v3/home 上打开亚马逊 SNS 控制台。https://console.aws.amazon.com/sns/](https://console.aws.amazon.com/sns/v3/home)

1. 在 SNS **主题**页面，选择**创建主题**，然后按照说明创建主题。

1. 在 **Create Policy**（创建策略）下，执行以下操作。

   1. 选择**高级**方法。

   1. 将以粗体显示的 JSON 数据块添加到现有策略。

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

****  

      ```
      {
        "Version":"2012-10-17",		 	 	 
        "Id": "__default_policy_ID",
        "Statement": [
          {
            "Sid": "__default_statement_ID",
            "Effect": "Allow",
            "Principal": {
              "AWS": "*"
            },
            "Action": [
              "SNS:GetTopicAttributes",
              "SNS:SetTopicAttributes",
              "SNS:AddPermission",
              "SNS:RemovePermission",
              "SNS:DeleteTopic",
              "SNS:Subscribe",
              "SNS:ListSubscriptionsByTopic",
              "SNS:Publish"
            ],
            "Resource": "arn:aws:sns:us-east-1:111122223333:your_topic_name",
            "Condition": {
              "StringEquals": {
                "AWS:SourceAccount": "your_account"
              }
            }
          },
          {
            "Sid": "__console_pub_0",
            "Effect": "Allow",
            "Principal": { 
              "Service": "gamelift.amazonaws.com" 
            },
            "Action": "sns:Publish",
            "Resource": "arn:aws:sns:us-east-1:111122223333:your_topic_name",
            "Condition": {
              "ArnLike": {
              "aws:SourceArn": "arn:aws:gamelift:us-east-1:111122223333:gamesessionqueue/your_queue_name"
              }
            }
          }
        ]
      }
      ```

------

   1. （可选）通过向资源策略添加条件，为主题添加其他访问控制。

1. 选择**创建主题**。

1. 创建 SNS 主题后，在创建队列时将其添加到队列中，或者编辑现有队列以将其添加。

## 使用服务器端加密设置 Amazon SNS 主题
<a name="queue-notification-sns-sse"></a>

借助服务器端加密（SSE），您可以采用加密主题的方式存储敏感数据。SSE 使用 AWS Key Management Service （AWS KMS）中托管的密钥保护 Amazon SNS 主题中消息的内容。有关 Amazon S3 如何执行加密的更多信息，请参阅 *Amazon Simple Storage Service 开发人员指南*中的[使用服务器端加密保护数据](https://docs.aws.amazon.com/sns/latest/dg/sns-server-side-encryption.html)。

要使用服务器端加密设置 SNS 主题，请查看下面的主题：
+ 《AWS Key Management Service 开发人员指南》**中的[创建密钥](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html)。
+ 将 S *imple Notification Service 开发人员指南*[中的主题启用 SSE](https://docs.aws.amazon.com/sns/latest/dg/sns-enable-encryption-for-topic.html)

创建 KMS 密钥时，请使用以下 KMS 密钥策略：

```
{ 
    "Effect": "Allow", 
    "Principal": { 
        "Service": "gamelift.amazonaws.com" 
     },
    "Action": [
        "kms:Decrypt",
        "kms:GenerateDataKey"
    ],
    "Resource": "*",
    "Condition": {
        "ArnLike": { 
            "aws:SourceArn": "arn:aws:gamelift:your_region:your_account:gamesessionqueue/your_queue_name" 
        },
        "StringEquals": { 
            "kms:EncryptionContext:aws:sns:topicArn": "arn:aws:sns:your_region:your_account:your_sns_topic_name" 
        }
    }
}
```

## 设置 EventBridge
<a name="queue-notification-cwe"></a>

Amazon GameLift Servers自动将所有游戏会话放置事件发布到 EventBridge。使用 EventBridge 可以设置规则，将事件路由到目标进行处理。例如，您可以设置一条规则，将事件路由`PlacementFulfilled`到一个处理连接到游戏会话之前的任务的 AWS Lambda 函数。有关的更多信息 EventBridge，请参阅 [Amazon 是什么 EventBridge？](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 在《*亚马逊 EventBridge 用户指南》*中。

以下是一些用于Amazon GameLift Servers队列的 EventBridge 规则示例：

匹配来自所有 Amazon GameLift Servers 队列的事件

```
{
    "source": [
        "aws.gamelift"
    ],
    "detail-type": [
        "GameLift Queue Placement Event"
    ]
}
```

匹配特定队列中的事件

```
{
    "source": [
        "aws.gamelift"
    ],
    "detail-type": [
        "GameLift Queue Placement Event"
    ],
    "resources": [
        "arn:aws:gamelift:your_region:your_account:gamesessionqueue/your_queue_name"
    ]
}
```

## 参考实现 AWS CDK
<a name="queue-notification-toolkit"></a>

有关使用 Amazon SNS 和 Amazon DynamoDB 实现基于事件的游戏会话放置的完整参考实现 AWS Lambda，请参阅亚马逊工具包中基于[事件的游戏会话](https://github.com/amazon-gamelift/amazon-gamelift-toolkit/tree/main/event-based-session-placement)放置指南。 GameLift 本指南包括用于部署具有处理游戏会话放置事件 AWS Lambda 功能的完整事件驱动型游戏会话放置系统的 AWS CDK 模板、用于跟踪游戏会话放置状态的 Amazon DynamoDB 表以及队列配置的最佳实践。Amazon GameLift Servers