Set up event notification for game session placement - Amazon GameLift
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Set up event notification for game session placement

If you're using queues to manage game session placement in your game, you need a way to monitor the status of individual placement requests and take action as appropriate. Implementing event notifications is a fast and efficient method for tracking placement activity. If your game is in production, or in pre-production with high-volume placement activity, you should be using event notifications.

There are two options for setting up event notifications. You can set up an SNS topic and have GameLift publish event notifications on placement activity by referencing the topic ID in a game session queue. Alternatively, you can use Amazon CloudWatch Events, which has a suite of tools available for managing events and taking action on them.

See the list of game session placement events emitted by GameLift in Game sesson placement events. Each placement event is identified by the service (GameLift), the game session queue, and the placement request ID.

Set up an SNS topic

You can ask GameLift to publish all events generated by a game session queue to an Amazon Simple Notification Service (SNS) topic. When configuring the queue, set the notification target field to an SNS topic ARN.

To set up an SNS topic for GameLift event notification

  1. Go to the Amazon Simple Notification Service console.

  2. Create a topic. From the SNS dashboard, choose Create topic and follow the instructions to create your topic. When the topic is created, the console automatically opens the Topic details page for the new topic.

  3. Allow GameLift to publish to the topic. If you're not already in the Topic details page for your topic, choose Topics from the navigation bar and click the topic ARN to open it. Choose the topic action Edit topic policy, and go to the Advanced view tab.

    You can optionally set additional access control for the topic. By adding conditions to your topic resource policy, you can control which queues can publish to the topic. Specify queues by their ARNs. You can only add queues that belong to the same Amazon account as the topic. Cross-account notification publishing is not supported.

    Add the bolded syntax below to the end of your existing policy. (The entire policy is shown for clarity.)

    { "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", "SNS:Receive" ], "Resource": "arn:aws-cn: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-cn:sns:your_region:your_account:your_topic_name" "Condition": { "ArnLike": { "aws:SourceArn": "arn:aws:gamelift:your_region:your_account:gamesessionqueue/your_queue_name" } } } ] }

Set up CloudWatch Events

GameLift automatically posts all game session placement events to CloudWatch Events. With CloudWatch Events you can set up rules to have events routed to a range of targets, including SNS topics and other Amazon services for processing. For example, you might set a rule to route the event "PlacementFulfilled" to an Amazon Lambda function that handles tasks that precede connecting to a game session. Learn more about how to use CloudWatch Events in the Getting Started guide, which includes a collection of tutorials.

If you plan to use CloudWatch Events, when configuring your queues, you can leave the notification target field empty, or reference an SNS topic if you want to use both options.

To access GameLift placement events in CloudWatch Events, go to the Amazon CloudWatch console and open Events. Be sure that you're in the Amazon Region where your game session queue resides. For more information about getting account credentials to access CloudWatch Events, see Sign in to the Amazon CloudWatch Console.

You'll want to set up CloudWatch Events rules to initiate action in response to a queue event. Learn more about this in Creating a CloudWatch Events Rule. Here are some relevant examples:

  • CloudWatch Events rule that matches events from all GameLift queues

    { "source": [ "aws.gamelift" ], "detail-type": [ "GameLift Queue Placement Event" ] }
  • Example CloudWatch Events rule that matches events from a specific queue

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