使用 Amazon 的 GameLift 示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文档 Amazon CLI 仅适用于版本 1。有关版本 2 的文档 Amazon CLI,请参阅版本 2 用户指南

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

使用 Amazon 的 GameLift 示例 Amazon CLI

以下代码示例向您展示如何在 Amazon 中使用来执行操作和实现常见场景 GameLift。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例显示了如何使用create-build

Amazon CLI

示例 1:使用 S3 存储桶中的文件创建游戏版本

以下create-build示例创建了自定义游戏编译资源。它使用存储在 S3 位置的由您控制的 Amazon 账户中的压缩文件。此示例假设您已经创建了一个授予 Amazon 访问 S3 位置的 GameLift 权限的IAM角色。由于请求未指定操作系统,因此新的编译资源默认为 WINDOWS _2012。

aws gamelift create-build \ --storage-location file://storage-loc.json \ --name MegaFrogRaceServer.NA \ --build-version 12345.678

storage-loc.json 的内容:

{ "Bucket":"MegaFrogRaceServer_NA_build_files" "Key":"MegaFrogRaceServer_build_123.zip" "RoleArn":"arn:aws:iam::123456789012:role/gamelift" }

输出:

{ "Build": { "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "CreationTime": 1496708916.18, "Name": "MegaFrogRaceServer.NA", "OperatingSystem": "WINDOWS_2012", "SizeOnDisk": 479303, "Status": "INITIALIZED", "Version": "12345.678" }, "StorageLocation": { "Bucket": "MegaFrogRaceServer_NA_build_files", "Key": "MegaFrogRaceServer_build_123.zip" } }

示例 2:创建游戏编译资源以手动将文件上传到 GameLift

以下create-build示例创建了一个新的构建资源。它还会获得存储位置和临时证书,允许您手动将游戏版本上传到 Amazon S3 中的相应 GameLift 位置。成功上传版本后,该 GameLift 服务会验证版本并更新新版本的状态。

aws gamelift create-build \ --name MegaFrogRaceServer.NA \ --build-version 12345.678 \ --operating-system AMAZON_LINUX

输出:

{ "Build": { "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "CreationTime": 1496708916.18, "Name": "MegaFrogRaceServer.NA", "OperatingSystem": "AMAZON_LINUX", "SizeOnDisk": 0, "Status": "INITIALIZED", "Version": "12345.678" }, "StorageLocation": { "Bucket": "gamelift-builds-us-west-2", "Key": "123456789012/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }, "UploadCredentials": { "AccessKeyId": "AKIAIOSFODNN7EXAMPLE", "SecretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "SessionToken": "AgoGb3JpZ2luENz...EXAMPLETOKEN==" } }

有关更多信息,请参阅《Amazon GameLift 开发者指南》 GameLift中的将自定义服务器版本上传到

以下代码示例显示了如何使用create-fleet

Amazon CLI

示例 1:创建基本的 Linux 舰队

以下create-fleet示例创建了一个配置最少的按需 Linux 实例队列来托管自定义服务器版本。您可以使用完成配置update-fleet

aws gamelift create-fleet \ --name MegaFrogRaceServer.NA.v2 \ --description 'Hosts for v2 North America' \ --build-id build-1111aaaa-22bb-33cc-44dd-5555eeee66ff \ --certificate-configuration 'CertificateType=GENERATED' \ --ec2-instance-type c4.large \ --fleet-type ON_DEMAND \ --runtime-configuration 'ServerProcesses=[{LaunchPath=/local/game/release-na/MegaFrogRace_Server.exe,ConcurrentExecutions=1}]'

输出:

{ "FleetAttributes": { "BuildId": "build-1111aaaa-22bb-33cc-44dd-5555eeee66ff", "CertificateConfiguration": { "CertificateType": "GENERATED" }, "CreationTime": 1496365885.44, "Description": "Hosts for v2 North America", "FleetArn": "arn:aws:gamelift:us-west-2:444455556666:fleet/fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa", "FleetId": "fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa", "FleetType": "ON_DEMAND", "InstanceType": "c4.large", "MetricGroups": ["default"], "Name": "MegaFrogRace.NA.v2", "NewGameSessionProtectionPolicy": "NoProtection", "OperatingSystem": "AMAZON_LINUX", "ServerLaunchPath": "/local/game/release-na/MegaFrogRace_Server.exe", "Status": "NEW" } }

示例 2:创建基本的 Windows 队列

以下create-fleet示例创建了一个配置最少的 Spot Windows 实例队列来托管自定义服务器版本。您可以使用完成配置update-fleet

aws gamelift create-fleet \ --name MegaFrogRace.NA.v2 \ --description 'Hosts for v2 North America' \ --build-id build-2222aaaa-33bb-44cc-55dd-6666eeee77ff \ --certificate-configuration 'CertificateType=GENERATED' \ --ec2-instance-type c4.large \ --fleet-type SPOT \ --runtime-configuration 'ServerProcesses=[{LaunchPath=C:\game\Bin64.Release.Dedicated\MegaFrogRace_Server.exe,ConcurrentExecutions=1}]'

输出:

{ "FleetAttributes": { "BuildId": "build-2222aaaa-33bb-44cc-55dd-6666eeee77ff", "CertificateConfiguration": { "CertificateType": "GENERATED" }, "CreationTime": 1496365885.44, "Description": "Hosts for v2 North America", "FleetArn": "arn:aws:gamelift:us-west-2:444455556666:fleet/fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa", "FleetId": "fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa", "FleetType": "SPOT", "InstanceType": "c4.large", "MetricGroups": ["default"], "Name": "MegaFrogRace.NA.v2", "NewGameSessionProtectionPolicy": "NoProtection", "OperatingSystem": "WINDOWS_2012", "ServerLaunchPath": "C:\game\Bin64.Release.Dedicated\MegaFrogRace_Server.exe", "Status": "NEW" } }

示例 3:创建完全配置的舰队

以下create-fleet示例为自定义服务器版本创建了一个 Spot Windows 实例队列,并提供了最常用的配置设置。

aws gamelift create-fleet \ --name MegaFrogRace.NA.v2 \ --description 'Hosts for v2 North America' \ --build-id build-2222aaaa-33bb-44cc-55dd-6666eeee77ff \ --certificate-configuration 'CertificateType=GENERATED' \ --ec2-instance-type c4.large \ --ec2-inbound-permissions 'FromPort=33435,ToPort=33435,IpRange=10.24.34.0/23,Protocol=UDP' \ --fleet-type SPOT \ --new-game-session-protection-policy FullProtection \ --runtime-configuration file://runtime-config.json \ --metric-groups default \ --instance-role-arn 'arn:aws:iam::444455556666:role/GameLiftS3Access'

runtime-config.json 的内容:

GameSessionActivationTimeoutSeconds=300, MaxConcurrentGameSessionActivations=2, ServerProcesses=[ {LaunchPath=C:\game\Bin64.Release.Dedicated\MegaFrogRace_Server.exe,Parameters=-debug,ConcurrentExecutions=1}, {LaunchPath=C:\game\Bin64.Release.Dedicated\MegaFrogRace_Server.exe,ConcurrentExecutions=1}]

输出:

{ "FleetAttributes": { "InstanceRoleArn": "arn:aws:iam::444455556666:role/GameLiftS3Access", "Status": "NEW", "InstanceType": "c4.large", "FleetArn": "arn:aws:gamelift:us-west-2:444455556666:fleet/fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa", "FleetId": "fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa", "Description": "Hosts for v2 North America", "FleetType": "SPOT", "OperatingSystem": "WINDOWS_2012", "Name": "MegaFrogRace.NA.v2", "CreationTime": 1569309011.11, "MetricGroups": [ "default" ], "BuildId": "build-2222aaaa-33bb-44cc-55dd-6666eeee77ff", "ServerLaunchParameters": "abc", "ServerLaunchPath": "C:\\game\\Bin64.Release.Dedicated\\MegaFrogRace_Server.exe", "NewGameSessionProtectionPolicy": "FullProtection", "CertificateConfiguration": { "CertificateType": "GENERATED" } } }

示例 4:创建实时服务器队列

以下create-fleet示例使用已上传到 Amazon GameLift 的实时配置脚本创建竞价型实例队列。所有实时服务器都部署在 Linux 计算机上。在本示例中,假设上传的实时脚本包含多个脚本文件,该Init()函数位于该脚本文件中名为MainScript.js。如图所示,此文件在运行时配置中被标识为启动脚本。

aws gamelift create-fleet \ --name MegaFrogRace.NA.realtime \ --description 'Mega Frog Race Realtime fleet' \ --script-id script-1111aaaa-22bb-33cc-44dd-5555eeee66ff \ --ec2-instance-type c4.large \ --fleet-type SPOT \ --certificate-configuration 'CertificateType=GENERATED' --runtime-configuration 'ServerProcesses=[{LaunchPath=/local/game/MainScript.js,Parameters=+map Winter444,ConcurrentExecutions=5}]'

输出:

{ "FleetAttributes": { "FleetId": "fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa", "Status": "NEW", "CreationTime": 1569310745.212, "InstanceType": "c4.large", "NewGameSessionProtectionPolicy": "NoProtection", "CertificateConfiguration": { "CertificateType": "GENERATED" }, "Name": "MegaFrogRace.NA.realtime", "ScriptId": "script-1111aaaa-22bb-33cc-44dd-5555eeee66ff", "FleetArn": "arn:aws:gamelift:us-west-2:444455556666:fleet/fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa", "FleetType": "SPOT", "MetricGroups": [ "default" ], "Description": "Mega Frog Race Realtime fleet", "OperatingSystem": "AMAZON_LINUX" } }

以下代码示例显示了如何使用create-game-session-queue

Amazon CLI

示例 1:设置有序的游戏会话队列

以下create-game-session-queue示例创建了一个新的游戏会话队列,其目的地位于两个区域。它还会配置队列,使游戏会话请求在等待放置 10 分钟后超时。由于未定义延迟策略,因此会 GameLift 尝试将所有游戏会话放置在列出的第一个目标上。

aws gamelift create-game-session-queue \ --name MegaFrogRaceServer-NA \ --destinations file://destinations.json \ --timeout-in-seconds 600

destinations.json 的内容:

{ "Destinations": [ {"DestinationArn": "arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }, {"DestinationArn": "arn:aws:gamelift:us-west-1::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" } ] }

输出:

{ "GameSessionQueues": [ { "Name": "MegaFrogRaceServer-NA", "GameSessionQueueArn": "arn:aws:gamelift:us-west-2:123456789012:gamesessionqueue/MegaFrogRaceServer-NA", "TimeoutInSeconds": 600, "Destinations": [ {"DestinationArn": "arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"}, {"DestinationArn": "arn:aws:gamelift:us-west-1::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222"} ] } ] }

示例 2:使用玩家延迟策略设置游戏会话队列

以下create-game-session-queue示例使用两个玩家延迟策略创建了一个新的游戏会话队列。第一个策略设置了 100 毫秒的延迟上限,该上限在尝试放置游戏会话的第一分钟内强制执行。第二项策略将延迟上限提高到 200 毫秒,直到放置请求在 3 分钟后超时。

aws gamelift create-game-session-queue \ --name MegaFrogRaceServer-NA \ --destinations file://destinations.json \ --player-latency-policies file://latency-policies.json \ --timeout-in-seconds 180

destinations.json 的内容:

{ "Destinations": [ { "DestinationArn": "arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }, { "DestinationArn": "arn:aws:gamelift:us-east-1::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" } ] }

latency-policies.json 的内容:

{ "PlayerLatencyPolicies": [ {"MaximumIndividualPlayerLatencyMilliseconds": 200}, {"MaximumIndividualPlayerLatencyMilliseconds": 100, "PolicyDurationSeconds": 60} ] }

输出:

{ "GameSessionQueue": { "Name": "MegaFrogRaceServer-NA", "GameSessionQueueArn": "arn:aws:gamelift:us-west-2:111122223333:gamesessionqueue/MegaFrogRaceServer-NA", "TimeoutInSeconds": 600, "PlayerLatencyPolicies": [ { "MaximumIndividualPlayerLatencyMilliseconds": 100, "PolicyDurationSeconds": 60 }, { "MaximumIndividualPlayerLatencyMilliseconds": 200 } ] "Destinations": [ {"DestinationArn": "arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"}, {"DestinationArn": "arn:aws:gamelift:us-east-1::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222"} ], } }

有关更多信息,请参阅《Amazon GameLift 开发者指南》中的创建队列

以下代码示例显示了如何使用delete-build

Amazon CLI

删除自定义游戏版本

以下delete-build示例从您的 Amazon GameLift 账户中删除了一个版本。版本被删除后,您将无法使用它来创建新的舰队。此操作无法撤消。

aws gamelift delete-build \ --build-id build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

此命令不生成任何输出。

以下代码示例显示了如何使用delete-fleet

Amazon CLI

删除不再使用的舰队

以下delete-fleet示例移除了已缩减为零实例的队列。如果队列容量大于零,则请求失败并出现 HTTP 400 错误。

aws gamelift delete-fleet \ --fleet-id fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

此命令不生成任何输出。

有关更多信息,请参阅《Amazon GameLift 开发者指南》中的管理 GameLift 舰队

以下代码示例显示了如何使用delete-game-session-queue

Amazon CLI

删除游戏会话队列

以下delete-game-session-queue示例删除了指定的游戏会话队列。

aws gamelift delete-game-session-queue \ --name MegaFrogRace-NA

此命令不生成任何输出。

以下代码示例显示了如何使用describe-build

Amazon CLI

获取有关自定义游戏版本的信息

以下describe-build示例检索游戏服务器编译资源的属性。

aws gamelift describe-build \ --build-id build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "Build": { "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "CreationTime": 1496708916.18, "Name": "My_Game_Server_Build_One", "OperatingSystem": "AMAZON_LINUX", "SizeOnDisk": 1304924, "Status": "READY", "Version": "12345.678" } }

有关更多信息,请参阅《Amazon GameLift 开发者指南》 GameLift中的将自定义服务器版本上传到

以下代码示例显示了如何使用describe-ec2-instance-limits

Amazon CLI

检索EC2实例类型的服务限制

以下describe-ec2-instance-limits示例显示了当前区域中指定实例类型允许的最大EC2实例数和当前使用的实例数。结果表明,在允许的二十个实例中,只使用了五个。

aws gamelift describe-ec2-instance-limits \ --ec2-instance-type m5.large

输出:

{ "EC2InstanceLimits": [ { "EC2InstanceType": ""m5.large", "CurrentInstances": 5, "InstanceLimit": 20 } ] }

有关更多信息,请参阅 Amazon GameLift 开发者指南中的选择计算资源

  • 有关API详细信息,请参阅InstanceLimits《Amazon CLI 命令参考》中的 DescribeEc2

以下代码示例显示了如何使用describe-fleet-attributes

Amazon CLI

示例 1:查看舰队列表的属性

以下describe-fleet-attributes示例检索两个指定舰队的舰队属性。如图所示,所请求的队列采用相同的版本部署,一个用于按需实例,一个用于竞价型实例,但有一些细微的配置差异。

aws gamelift describe-fleet-attributes \ --fleet-ids arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222

输出:

{ "FleetAttributes": [ { "FleetId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "FleetArn": "arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "FleetType": "ON_DEMAND", "InstanceType": "c4.large", "Description": "On-demand hosts for v2 North America", "Name": "MegaFrogRaceServer.NA.v2-od", "CreationTime": 1568836191.995, "Status": "ACTIVE", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE33333", "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE33333", "ServerLaunchPath": "C:\\game\\MegaFrogRace_Server.exe", "ServerLaunchParameters": "+gamelift_start_server", "NewGameSessionProtectionPolicy": "NoProtection", "OperatingSystem": "WINDOWS_2012", "MetricGroups": [ "default" ], "CertificateConfiguration": { "CertificateType": "DISABLED" } }, { "FleetId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "FleetArn": "arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "FleetType": "SPOT", "InstanceType": "c4.large", "Description": "On-demand hosts for v2 North America", "Name": "MegaFrogRaceServer.NA.v2-spot", "CreationTime": 1568838275.379, "Status": "ACTIVATING", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE33333", "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE33333", "ServerLaunchPath": "C:\\game\\MegaFrogRace_Server.exe", "NewGameSessionProtectionPolicy": "NoProtection", "OperatingSystem": "WINDOWS_2012", "MetricGroups": [ "default" ], "CertificateConfiguration": { "CertificateType": "GENERATED" } } ] }

示例 2:请求所有舰队的属性

以下内容describe-fleet-attributes返回所有处于任何状态的舰队的舰队属性。此示例说明如何使用分页参数一次返回一个舰队。

aws gamelift describe-fleet-attributes \ --limit 1

输出:

{ "FleetAttributes": [ { "FleetId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "FleetArn": "arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "FleetType": "SPOT", "InstanceType": "c4.large", "Description": "On-demand hosts for v2 North America", "Name": "MegaFrogRaceServer.NA.v2-spot", "CreationTime": 1568838275.379, "Status": "ACTIVATING", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE33333", "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE33333", "ServerLaunchPath": "C:\\game\\MegaFrogRace_Server.exe", "NewGameSessionProtectionPolicy": "NoProtection", "OperatingSystem": "WINDOWS_2012", "MetricGroups": [ "default" ], "CertificateConfiguration": { "CertificateType": "GENERATED" } } ], "NextToken": "eyJhd3NBY2NvdW50SWQiOnsicyI6IjMwMjc3NjAxNjM5OCJ9LCJidWlsZElkIjp7InMiOiJidWlsZC01NWYxZTZmMS1jY2FlLTQ3YTctOWI5ZS1iYjFkYTQwMjEXAMPLE2" }

输出包含一个NextToken值,您可以在第二次调用该命令时使用该值。将该值传递给--next-token参数以指定从何处获取输出。以下命令返回输出中的第二个结果。

aws gamelift describe-fleet-attributes \ --limit 1 \ --next-token eyJhd3NBY2NvdW50SWQiOnsicyI6IjMwMjc3NjAxNjM5OCJ9LCJidWlsZElkIjp7InMiOiJidWlsZC01NWYxZTZmMS1jY2FlLTQ3YTctOWI5ZS1iYjFkYTQwMjEXAMPLE1

重复此操作,直到响应中不包含NextToken值。

有关更多信息,请参阅《Amazon GameLift 开发者指南》中的设置 GameLift 队列。

以下代码示例显示了如何使用describe-fleet-capacity

Amazon CLI

查看舰队列表的容量状态

以下describe-fleet-capacity示例检索两个指定队列的当前容量。

aws gamelift describe-fleet-capacity \ --fleet-ids arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222

输出:

{ "FleetCapacity": [ { "FleetId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "InstanceType": "c5.large", "InstanceCounts": { "DESIRED": 10, "MINIMUM": 1, "MAXIMUM": 20, "PENDING": 0, "ACTIVE": 10, "IDLE": 3, "TERMINATING": 0 } }, { "FleetId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "InstanceType": "c5.large", "InstanceCounts": { "DESIRED": 13, "MINIMUM": 1, "MAXIMUM": 20, "PENDING": 0, "ACTIVE": 15, "IDLE": 2, "TERMINATING": 2 } } ] }

有关更多信息,请参阅《Amazon GameLift 开发者指南》中的舰队GameLift 指标

以下代码示例显示了如何使用describe-fleet-events

Amazon CLI

请求指定时间段内的事件

以下describe-fleet-events示例显示了在指定时间段内发生的所有舰队相关事件的详细信息。

aws gamelift describe-fleet-events \ --fleet-id arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 \ --start-time 1579647600 \ --end-time 1579649400 \ --limit 5

输出:

{ "Events": [ { "EventId": "a37b6892-5d07-4d3b-8b47-80244ecf66b9", "ResourceId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "EventCode": "FLEET_STATE_ACTIVE", "Message": "Fleet fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 changed state to ACTIVE", "EventTime": 1579649342.191 }, { "EventId": "67da4ec9-92a3-4d95-886a-5d6772c24063", "ResourceId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "EventCode": "FLEET_STATE_ACTIVATING", "Message": "Fleet fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 changed state to ACTIVATING", "EventTime": 1579649321.427 }, { "EventId": "23813a46-a9e6-4a53-8847-f12e6a8381ac", "ResourceId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "EventCode": "FLEET_STATE_BUILDING", "Message": "Fleet fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 changed state to BUILDING", "EventTime": 1579649321.243 }, { "EventId": "3bf217d0-1d44-42f9-9202-433ed475d2e8", "ResourceId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "EventCode": "FLEET_STATE_VALIDATING", "Message": "Fleet fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 changed state to VALIDATING", "EventTime": 1579649197.449 }, { "EventId": "2ecd0130-5986-44eb-99a7-62df27741084", "ResourceId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "EventCode": "FLEET_VALIDATION_LAUNCH_PATH_NOT_FOUND", "Message": "Failed to find a valid path", "EventTime": 1569319075.839, "PreSignedLogUrl": "https://gamelift-event-logs-prod-us-west-2.s3.us-west-2.amazonaws.com/logs/fleet-83422059-8329-42a2-a4d6-c4444386a6f8/events/2ecd0130-5986-44eb-99a7-62df27741084/FLEET_VALIDATION_LAUNCH_PATH_NOT_FOUND.txt?X-Amz-Security-Token=IQoJb3JpZ2luX2VjEB8aCXVzLXdlc3QtMiJHMEUCIHV5K%2FLPx8h310D%2FAvx0%2FZxsDy5XA3cJOwPdu3T0eBa%2FAiEA1yovokcZYy%2FV4CWW6l26aFyiSHO%2Bxz%2FBMAhEHYHMQNcqkQMImP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARAAGgw3NDEwNjE1OTIxNzEiDI8rsZtzLzlwEDQhXSrlAtl5Ae%2Fgo6FCIzqXPbXfBOnSvFYqeDlriZarEpKqKrUt8mXQv9iqHResqCph9AKo49lwgSYTT2QoSxnrD7%2FUgv%2BZm2pVuczvuKtUA0fcx6s0GxpjIAzdIE%2F5P%2FB7B9M%2BVZ%2F9KF82hbJi0HTE6Y7BjKsEgFCvk4UXILhfjtan9iQl8%2F21ZTurAcJbm7Y5tuLF9SWSK3%2BEa7VXOcCK4D4O1sMjmdRm0q0CKZ%2FIaXoHkNvg0RVTa0hIqdvpaDQlsSBNdqTXbjHTu6fETE9Y9Ky%2BiJK5KiUG%2F59GjCpDcvS1FqKeLUEmKT7wysGmvjMc2n%2Fr%2F9VxQfte7w9srXwlLAQuwhiXAAyI5ICMZ5JvzjzQwTqD4CHTVKUUDwL%2BRZzbuuqkJObZml02CkRGp%2B74RTAzLbWptVqZTIfzctiCTmWxb%2FmKyELRYsVLrwNJ%2BGJ7%2BCrN0RC%2FjlgfLYIZyeAqjPgAu5HjgX%2BM7jCo9M7wBTrnAXKOFQuf9dvA84SuwXOJFp17LYGjrHMKv0qC3GfbTMrZ6kzeNV9awKCpXB2Gnx9z2KvIlJdqirWVpvHVGwKCmJBCesDzjJHrae3neogI1uW%2F9C6%2B4jIZPME3jXmZcEHqqw5uvAVF7aeIavtUZU8pxpDIWT0YE4p3Kriy2AA7ziCRKtVfjV839InyLk8LUjsioWK2qlpg2HXKFLpAXw1QsQyxYmFMB9sGKOUlbL7Jdkk%2BYUq8%2FDTlLxqj1S%2FiO4TI0Wo7ilAo%2FKKWWF4guuNDexj8EOOynSp1yImB%2BZf2Fua3O44W4eEXAMPLE33333&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20170621T231808Z&X-Amz-SignedHeaders=host&X-Amz-Expires=900&X-Amz-Credential=AKIAIOSFODNN7EXAMPLE%2F20170621%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" } ], "NextToken": "eyJhd3NBY2NvdW50SWQiOnsicyI6IjMwMjc3NjAxNjM5OCJ9LCJidWlsZElkIjp7InMiOiJidWlsZC01NWYxZTZmMS1jY2FlLTQ3YTctOWI5ZS1iYjFkYTQwMjEXAMPLE2" }

有关更多信息,请参阅 Amazon GameLift 开发者指南中的调试 GameLift 队列问题

以下代码示例显示了如何使用describe-fleet-port-settings

Amazon CLI

查看队列的入站连接权限

以下describe-fleet-port-settings示例检索指定队列的连接设置。

aws gamelift describe-fleet-port-settings \ --fleet-id arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "InboundPermissions": [ { "FromPort": 33400, "ToPort": 33500, "IpRange": "0.0.0.0/0", "Protocol": "UDP" }, { "FromPort": 1900, "ToPort": 2000, "IpRange": "0.0.0.0/0", "Protocol": "TCP" } ] }

有关更多信息,请参阅《Amazon GameLift 开发者指南》中的设置 GameLift 队列。

以下代码示例显示了如何使用describe-fleet-utilization

Amazon CLI

示例 1:查看车队列表的使用数据

以下describe-fleet-utilization示例检索一个指定队列的当前使用情况信息。

aws gamelift describe-fleet-utilization \ --fleet-ids arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "FleetUtilization": [ { "FleetId": "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "ActiveServerProcessCount": 100, "ActiveGameSessionCount": 62, "CurrentPlayerSessionCount": 329, "MaximumPlayerSessionCount": 1000 } ] }

示例 2:请求所有车队的使用数据

以下内容describe-fleet-utilization返回所有处于任何状态的舰队的车队使用数据。此示例使用分页参数一次返回两个队列的数据。

aws gamelift describe-fleet-utilization \ --limit 2

输出:

{ "FleetUtilization": [ { "FleetId": "fleet-1111aaaa-22bb-33cc-44dd-5555eeee66ff", "ActiveServerProcessCount": 100, "ActiveGameSessionCount": 13, "CurrentPlayerSessionCount": 98, "MaximumPlayerSessionCount": 1000 }, { "FleetId": "fleet-2222bbbb-33cc-44dd-55ee-6666ffff77aa", "ActiveServerProcessCount": 100, "ActiveGameSessionCount": 62, "CurrentPlayerSessionCount": 329, "MaximumPlayerSessionCount": 1000 } ], "NextToken": "eyJhd3NBY2NvdW50SWQiOnsicyI6IjMwMjc3NjAxNjM5OCJ9LCJidWlsZElkIjp7InMiOiJidWlsZC01NWYxZTZmMS1jY2FlLTQ3YTctOWI5ZS1iYjFkYTQwMjEXAMPLE2" }

再次调用该命令,将该NextToken值作为参数传递给--next-token参数以查看接下来的两个结果。

aws gamelift describe-fleet-utilization \ --limit 2 \ --next-token eyJhd3NBY2NvdW50SWQiOnsicyI6IjMwMjc3NjAxNjM5OCJ9LCJidWlsZElkIjp7InMiOiJidWlsZC01NWYxZTZmMS1jY2FlLTQ3YTctOWI5ZS1iYjFkYTQwMjEXAMPLE2

重复此操作,直到响应不再在输出中包含NextToken值。

有关更多信息,请参阅《Amazon GameLift 开发者指南》中的舰队GameLift 指标

以下代码示例显示了如何使用describe-game-session-queues

Amazon CLI

查看游戏会话队列

以下describe-game-session-queues示例检索两个指定队列的属性。

aws gamelift describe-game-session-queues \ --names MegaFrogRace-NA MegaFrogRace-EU

输出:

{ "GameSessionQueues": [{ "Destinations": [{ "DestinationArn": "arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }, { "DestinationArn": "arn:aws:gamelift:us-west-2::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" } ], "Name": "MegaFrogRace-NA", "TimeoutInSeconds": 600, "GameSessionQueueArn": "arn:aws:gamelift:us-west-2::gamesessionqueue/MegaFrogRace-NA", "PlayerLatencyPolicies": [{ "MaximumIndividualPlayerLatencyMilliseconds": 200 }, { "MaximumIndividualPlayerLatencyMilliseconds": 100, "PolicyDurationSeconds": 60 } ], "FilterConfiguration": { "AllowedLocations": ["us-west-2", "ap-south-1", "us-east-1"] }, "PriorityConfiguration": { "PriorityOrder": ["LOCATION", "FLEET_TYPE", "DESTINATION"], "LocationOrder": ["us-west-2", "ap-south-1", "us-east-1"] } }, { "Destinations": [{ "DestinationArn": "arn:aws:gamelift:eu-west-3::fleet/fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" }], "Name": "MegaFrogRace-EU", "TimeoutInSeconds": 600, "GameSessionQueueArn": "arn:aws:gamelift:us-west-2::gamesessionqueue/MegaFrogRace-EU" } ] }

有关更多信息,请参阅 Amazon GameLift 开发者指南中的使用多区域队列

以下代码示例显示了如何使用describe-runtime-configuration

Amazon CLI

请求队列的运行时配置

以下describe-runtime-configuration示例检索有关指定队列的当前运行时配置的详细信息。

aws gamelift describe-runtime-configuration \ --fleet-id fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "RuntimeConfiguration": { "ServerProcesses": [ { "LaunchPath": "C:\game\Bin64.Release.Dedicated\MegaFrogRace_Server.exe", "Parameters": "+gamelift_start_server", "ConcurrentExecutions": 3 }, { "LaunchPath": "C:\game\Bin64.Release.Dedicated\MegaFrogRace_Server.exe", "Parameters": "+gamelift_start_server +debug", "ConcurrentExecutions": 1 } ], "MaxConcurrentGameSessionActivations": 2147483647, "GameSessionActivationTimeoutSeconds": 300 } }

有关更多信息,请参阅 Amazon GameLift 开发者指南中的在队列上运行多个进程

以下代码示例显示了如何使用list-builds

Amazon CLI

示例 1:获取自定义游戏版本列表

以下list-builds示例检索当前区域中所有游戏服务器版本的属性。示例请求说明了如何使用分页参数LimitNextToken按顺序检索结果。第一个命令检索前两个版本。由于有两个以上的可用结果,因此响应中包含 aNextToken,表示有更多结果可用。

aws gamelift list-builds \ --limit 2

输出:

{ "Builds": [ { "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "CreationTime": 1495664528.723, "Name": "My_Game_Server_Build_One", "OperatingSystem": "WINDOWS_2012", "SizeOnDisk": 8567781, "Status": "READY", "Version": "12345.678" }, { "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "CreationTime": 1495528748.555, "Name": "My_Game_Server_Build_Two", "OperatingSystem": "AMAZON_LINUX_2", "SizeOnDisk": 8567781, "Status": "FAILED", "Version": "23456.789" } ], "NextToken": "eyJhd3NBY2NvdW50SWQiOnsicyI6IjMwMjc3NjAxNjM5OCJ9LCJidWlsZElkIjp7InMiOiJidWlsZC01NWYxZTZmMS1jY2FlLTQ3YTctOWI5ZS1iYjFkYTQwMjJEXAMPLE=" }

然后,您可以使用--next-token参数再次调用该命令,如下所示,以查看接下来的两个版本。

aws gamelift list-builds \ --limit 2 --next-token eyJhd3NBY2NvdW50SWQiOnsicyI6IjMwMjc3NjAxNjM5OCJ9LCJidWlsZElkIjp7InMiOiJidWlsZC01NWYxZTZmMS1jY2FlLTQ3YTctOWI5ZS1iYjFkYTQwMjJEXAMPLE=

重复此操作,直到响应中不包含NextToken值。

示例 2:获取处于失败状态的自定义游戏版本列表

以下list-builds示例检索当前区域中所有具有状态FAILED的游戏服务器版本的属性。

aws gamelift list-builds \ --status FAILED

输出:

{ "Builds": [ { "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "CreationTime": 1495528748.555, "Name": "My_Game_Server_Build_Two", "OperatingSystem": "AMAZON_LINUX_2", "SizeOnDisk": 8567781, "Status": "FAILED", "Version": "23456.789" } ] }

以下代码示例显示了如何使用list-fleets

Amazon CLI

示例 1:获取一个地区内所有舰队的列表

以下list-fleets示例显示了当前区域IDs中所有舰队的舰队。此示例使用分页参数IDs一次检索两个舰队。响应中包含一个next-token属性,该属性表示还有更多结果需要检索。

aws gamelift list-fleets \ --limit 2

输出:

{ "FleetIds": [ "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" ], "NextToken": "eyJhd3NBY2NvdW50SWQiOnsicyI6IjMwMjc3NjAxNjM5OCJ9LCJidWlsZElkIjp7InMiOiJidWlsZC01NWYxZTZmMS1jY2FlLTQ3YTctOWI5ZS1iYjFkYTQwMjJEXAMPLE=" }

您可以在下一个命令中传递上一个响应中的NextToken值,如下所示,以获得接下来的两个结果。

aws gamelift list-fleets \ --limit 2 \ --next-token eyJhd3NBY2NvdW50SWQiOnsicyI6IjMwMjc3NjAxNjM5OCJ9LCJidWlsZElkIjp7InMiOiJidWlsZC00NDRlZjQxZS1hM2I1LTQ2NDYtODJmMy0zYzI4ZTgxNjVjEXAMPLE=

示例 2:获取具有特定版本或脚本的区域内所有舰队的列表

以下list-builds示例检索使用指定游戏版本部署的队列。IDs如果您使用的是实时服务器,则可以提供脚本 ID 来代替构建 ID。由于此示例未指定 limit 参数,因此结果最多可以包含 16 个舰队IDs。

aws gamelift list-fleets \ --build-id build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "FleetIds": [ "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE33333", "fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE44444" ] }

以下代码示例显示了如何使用request-upload-credentials

Amazon CLI

刷新上传版本的访问凭证

以下create-build示例获取新的有效访问凭证,用于将 GameLift 构建文件上传到 Amazon S3 位置。证书的有效期有限。您可以从对原始CreateBuild请求的响应中获得构建 ID。

aws gamelift request-upload-credentials \ --build-id build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "StorageLocation": { "Bucket": "gamelift-builds-us-west-2", "Key": "123456789012/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }, "UploadCredentials": { "AccessKeyId": "AKIAIOSFODNN7EXAMPLE", "SecretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "SessionToken": "AgoGb3JpZ2luENz...EXAMPLETOKEN==" } }

有关更多信息,请参阅《Amazon GameLift 开发者指南》 GameLift中的将自定义服务器版本上传到

以下代码示例显示了如何使用start-fleet-actions

Amazon CLI

要重新启动队列自动扩展活动

以下start-fleet-actions示例恢复使用为指定队列定义但因调stop-fleet-actions用 ````而停止的所有扩展策略。启动后,扩展策略会立即开始跟踪各自的指标。

aws gamelift start-fleet-actions \ --fleet-id fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 \ --actions AUTO_SCALING

此命令不生成任何输出。

以下代码示例显示了如何使用stop-fleet-actions

Amazon CLI

停止队列的自动扩展活动

以下stop-fleet-actions示例停止使用为指定队列定义的所有扩展策略。策略暂停后,除非您手动调整,否则队列容量将保持不变。

aws gamelift start-fleet-actions \ --fleet-id fleet-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 \ --actions AUTO_SCALING

此命令不生成任何输出。

以下代码示例显示了如何使用update-build

Amazon CLI

更新自定义游戏版本

以下update-build示例更改了与指定编译资源关联的名称和版本信息。返回的构建对象验证更改是否已成功完成。

aws gamelift update-build \ --build-id build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 \ --name MegaFrogRaceServer.NA.east \ --build-version 12345.east

输出:

{ "Build": { "BuildArn": "arn:aws:gamelift:us-west-2::build/build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "BuildId": "build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "CreationTime": 1496708916.18, "Name": "MegaFrogRaceServer.NA.east", "OperatingSystem": "AMAZON_LINUX_2", "SizeOnDisk": 1304924, "Status": "READY", "Version": "12345.east" } }

有关更多信息,请参阅《Amazon GameLift 开发者指南》中的 “更新您的构建文件”。

以下代码示例显示了如何使用update-game-session-queue

Amazon CLI

更新游戏会话队列配置

以下update-game-session-queue示例添加了一个新的目标并更新了现有游戏会话队列的玩家延迟策略。

aws gamelift update-game-session-queue \ --name MegaFrogRace-NA \ --destinations file://destinations.json \ --player-latency-policies file://latency-policies.json

destinations.json 的内容:

{ "Destinations": [ {"DestinationArn": "arn:aws:gamelift:us-west-2::fleet/fleet-1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d"}, {"DestinationArn": "arn:aws:gamelift:us-east-1::fleet/fleet-5c6d3c4d-5e6f-7a8b-9c0d-1e2f3a4b5a2b"}, {"DestinationArn": "arn:aws:gamelift:us-east-1::alias/alias-11aa22bb-3c4d-5e6f-000a-1111aaaa22bb"} ] }

latency-policies.json 的内容:

{ "PlayerLatencyPolicies": [ {"MaximumIndividualPlayerLatencyMilliseconds": 200}, {"MaximumIndividualPlayerLatencyMilliseconds": 150, "PolicyDurationSeconds": 120}, {"MaximumIndividualPlayerLatencyMilliseconds": 100, "PolicyDurationSeconds": 120} ] }

输出:

{ "GameSessionQueue": { "Destinations": [ {"DestinationArn": "arn:aws:gamelift:us-west-2::fleet/fleet-1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d"}, {"DestinationArn": "arn:aws:gamelift:us-east-1::fleet/fleet-5c6d3c4d-5e6f-7a8b-9c0d-1e2f3a4b5a2b"}, {"DestinationArn": "arn:aws:gamelift:us-east-1::alias/alias-11aa22bb-3c4d-5e6f-000a-1111aaaa22bb"} ], "GameSessionQueueArn": "arn:aws:gamelift:us-west-2:111122223333:gamesessionqueue/MegaFrogRace-NA", "Name": "MegaFrogRace-NA", "TimeoutInSeconds": 600, "PlayerLatencyPolicies": [ {"MaximumIndividualPlayerLatencyMilliseconds": 200}, {"MaximumIndividualPlayerLatencyMilliseconds": 150, "PolicyDurationSeconds": 120}, {"MaximumIndividualPlayerLatencyMilliseconds": 100, "PolicyDurationSeconds": 120} ] } }

有关更多信息,请参阅 Amazon GameLift 开发者指南中的使用多区域队列

以下代码示例显示了如何使用upload-build

Amazon CLI

示例 1:上传 Linux 游戏服务器版本

以下upload-build示例将 Linux 游戏服务器编译文件从文件目录上传到 GameLift 服务并创建构建资源。

aws gamelift upload-build \ --name MegaFrogRaceServer.NA \ --build-version 2.0.1 \ --build-root ~/MegaFrogRace_Server/release-na \ --operating-system AMAZON_LINUX_2 --server-sdk-version 4.0.2

输出:

Uploading ~/MegaFrogRace_Server/release-na: 16.0 KiB / 74.6 KiB (21.45%) Uploading ~/MegaFrogRace_Server/release-na: 32.0 KiB / 74.6 KiB (42.89%) Uploading ~/MegaFrogRace_Server/release-na: 48.0 KiB / 74.6 KiB (64.34%) Uploading ~/MegaFrogRace_Server/release-na: 64.0 KiB / 74.6 KiB (85.79%) Uploading ~/MegaFrogRace_Server/release-na: 74.6 KiB / 74.6 KiB (100.00%) Successfully uploaded ~/MegaFrogRace_Server/release-na to AWS GameLift Build ID: build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

示例 2:上传 Windows 游戏服务器版本

以下upload-build示例将 Windows 游戏服务器编译文件从目录上传到 GameLift 服务并创建构建记录。

aws gamelift upload-build \ --name MegaFrogRaceServer.NA \ --build-version 2.0.1 \ --build-root C:\MegaFrogRace_Server\release-na \ --operating-system WINDOWS_2012 --server-sdk-version 4.0.2

输出:

Uploading C:\MegaFrogRace_Server\release-na: 16.0 KiB / 74.6 KiB (21.45%) Uploading C:\MegaFrogRace_Server\release-na: 32.0 KiB / 74.6 KiB (42.89%) Uploading C:\MegaFrogRace_Server\release-na: 48.0 KiB / 74.6 KiB (64.34%) Uploading C:\MegaFrogRace_Server\release-na: 64.0 KiB / 74.6 KiB (85.79%) Uploading C:\MegaFrogRace_Server\release-na: 74.6 KiB / 74.6 KiB (100.00%) Successfully uploaded C:\MegaFrogRace_Server\release-na to AWS GameLift Build ID: build-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

有关更多信息,请参阅《Amazon GameLift 开发者指南》 GameLift中的将自定义服务器版本上传到