本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
设置 FlexMatch 事件通知
您可以使用事件通知来跟踪个人对战请求的状态。所有投入实际生产的游戏,或具有大量对战活动的预生产中的游戏都应使用事件通知。
有两个选项可用于设置事件通知。
-
让您的对战构建器将事件通知发布到 Amazon Simple Notification Service 主题。
-
使用自动发布的 Amazon EventBridge 赛事及其工具套件来管理事件。
有关 Amazon GameLift 发出的 FlexMatch 事件的列表,请参阅FlexMatch 对战活动。
EBS EventBridge 事件
Amazon GameLift 会将所有对战的事件发布到 Amazon EventBridge。使用 EventBridge,您可以设置规则,将对战的事件传送到目标进行处理。例如,您可以设置一个规则,将事件“PotentialMatchCreated”路由到处理玩家接受情况的 Amazon Lambda 函数。有关更多信息,请参阅什么是 Amazon EventBridge?
注意
在配置对战构建器时,如果您想同时使用 EventBridge 和 Amazon SNS,请将通知目标字段保留为空或引用 SNS 主题。
一个 Amazon SNS 主题
您可以让 Amazon GameLift 将 FlexMatch 对战构建器生成的所有事件发布到 Amazon SNS 主题中。
为 Amazon GameLift 事件通知创建 SNS 主题
-
打开 Amazon SNS 控制台
。 -
在导航窗格中,选择 Topics (主题)。
-
在 Topics(主页)页面上,选择 Create topic(创建主题)。
-
在 控制台中,创建一个主题。有关更多信息,请参阅《Amazon Simple Notification Service 开发人员指南》中的创建主题Amazon Web Services Management Console。
-
在主题的详细信息页面上,选择编辑。
-
(可选)在主题的编辑页面上,展开访问策略,然后将以下 Amazon Identity and Access Management (IAM) 策略声明中的粗体语法添加到现有策略的末尾。(为清晰起见显示了整个策略。) 请务必将 Amazon 资源名称 (ARN) 详细信息用于您自己的 SNS 主题和 Amazon GameLift 对战配置。
{ "Version": "2008-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:
your_region
:your_account
: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:your_region
:your_account
:your_topic_name
", "Condition": { "ArnLike": { "aws:SourceArn": "arn:aws:gamelift:your_region
:your_account
:matchmakingconfiguration/your_configuration_name
" } } } ] } -
选择 Save changes(保存更改)。
使用服务器端加密设置 Amazon SNS 主题
您可以使用服务器端加密 (SSE),采用加密主题的方式传输敏感数据。SSE 使用 Amazon Key Management Service (Amazon KMS) 中托管的密钥保护 Amazon SNS 主题中消息的内容。有关 Amazon S3 如何执行加密的更多信息,请参阅 Amazon Simple Storage Service 开发人员指南中的使用服务器端加密保护数据。
要使用服务器端加密设置 SNS 主题,请查看下面的主题:
-
《Amazon Key Management Service 开发人员指南》中的创建密钥。
-
将 S imple Notification Service 开发人员指南中的主题启用 SSE
创建 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
:matchmakingconfiguration/your_configuration_name
" }, "StringEquals": { "kms:EncryptionContext:aws:sns:topicArn": "arn:aws:sns:your_region
:your_account
:your_sns_topic_name
" } } }
将主题订阅配置为调用 Lambda 函数
您可以使用发布到 Amazon SNS 主题的事件通知调用 Lambda 函数。配置对战构建器时,将通知目标字段设置为 SNS 主题 ARN。
以下Amazon CloudFormation模板将订阅名为的 SNS 主题配置为调用名MyFlexMatchEventTopic
为的 Lambda 函数。FlexMatchEventHandlerLambdaFunction
该模板创建了一个 IAM 权限策略,允许 Amazon GameLift 写入 SNS 主题。然后,模板将调用 Lambda 函数的权限。
FlexMatchEventTopic: Type: "AWS::SNS::Topic" Properties: KmsMasterKeyId: alias/aws/sns #Enables server-side encryption on the topic using an Amazon managed key Subscription: - Endpoint: !GetAtt FlexMatchEventHandlerLambdaFunction.Arn Protocol: lambda TopicName: MyFlexMatchEventTopic FlexMatchEventTopicPolicy: Type: "AWS::SNS::TopicPolicy" DependsOn: FlexMatchEventTopic Properties: PolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Principal: Service: gamelift.amazonaws.com Action: - "sns:Publish" Resource: !Ref FlexMatchEventTopic Topics: - Ref: FlexMatchEventTopic FlexMatchEventHandlerLambdaPermission: Type: "AWS::Lambda::Permission" Properties: Action: "lambda:InvokeFunction" FunctionName: !Ref FlexMatchEventHandlerLambdaFunction Principal: sns.amazonaws.com SourceArn: !Ref FlexMatchEventTopic