Skip to content

Resource: awsGameliftGameServerGroup

Provides an GameLift Game Server Group resource.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.gameliftGameServerGroup.GameliftGameServerGroup(this, "example", {
  depends_on: ["${aws_iam_role_policy_attachment.example}"],
  gameServerGroupName: "example",
  instanceDefinition: [
    {
      instanceType: "c5.large",
    },
    {
      instanceType: "c5a.large",
    },
  ],
  launchTemplate: {
    id: "${aws_launch_template.example.id}",
  },
  maxSize: 1,
  minSize: 1,
  roleArn: "${aws_iam_role.example.arn}",
});

Full usage:

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.gameliftGameServerGroup.GameliftGameServerGroup(this, "example", {
  autoScalingPolicy: {
    estimatedInstanceWarmup: 60,
    targetTrackingConfiguration: {
      targetValue: 75,
    },
  },
  balancingStrategy: "SPOT_ONLY",
  depends_on: ["${aws_iam_role_policy_attachment.example}"],
  gameServerGroupName: "example",
  gameServerProtectionPolicy: "FULL_PROTECTION",
  instanceDefinition: [
    {
      instanceType: "c5.large",
      weightedCapacity: "1",
    },
    {
      instanceType: "c5.2xlarge",
      weightedCapacity: "2",
    },
  ],
  launchTemplate: {
    id: "${aws_launch_template.example.id}",
    version: "1",
  },
  maxSize: 1,
  minSize: 1,
  roleArn: "${aws_iam_role.example.arn}",
  tags: {
    Name: "example",
  },
  vpcSubnets: ["subnet-12345678", "subnet-23456789"],
});

Example IAM Role for GameLift Game Server Group

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const dataAwsIamPolicyDocumentAssumeRole =
  new aws.dataAwsIamPolicyDocument.DataAwsIamPolicyDocument(
    this,
    "assume_role",
    {
      statement: [
        {
          actions: ["sts:AssumeRole"],
          effect: "Allow",
          principals: [
            {
              identifiers: [
                "autoscaling.amazonaws.com",
                "gamelift.amazonaws.com",
              ],
              type: "Service",
            },
          ],
        },
      ],
    }
  );
const dataAwsPartitionCurrent = new aws.dataAwsPartition.DataAwsPartition(
  this,
  "current",
  {}
);
const awsIamRoleExample = new aws.iamRole.IamRole(this, "example", {
  assumeRolePolicy: dataAwsIamPolicyDocumentAssumeRole.json,
  name: "gamelift-game-server-group-example",
});
const awsIamRolePolicyAttachmentExample =
  new aws.iamRolePolicyAttachment.IamRolePolicyAttachment(this, "example_3", {
    policyArn: `arn:\${${dataAwsPartitionCurrent.partition}}:iam::aws:policy/GameLiftGameServerGroupPolicy`,
    role: awsIamRoleExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsIamRolePolicyAttachmentExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • balancingStrategy - (Optional) Indicates how GameLift FleetIQ balances the use of Spot Instances and On-Demand Instances. Valid values: SPOT_ONLY, SPOT_PREFERRED, ON_DEMAND_ONLY. Defaults to SPOT_PREFERRED.
  • gameServerGroupName - (Required) Name of the game server group. This value is used to generate unique ARN identifiers for the EC2 Auto Scaling group and the GameLift FleetIQ game server group.
  • gameServerProtectionPolicy - (Optional) Indicates whether instances in the game server group are protected from early termination. Unprotected instances that have active game servers running might be terminated during a scale-down event, causing players to be dropped from the game. Protected instances cannot be terminated while there are active game servers running except in the event of a forced game server group deletion. Valid values: NO_PROTECTION, FULL_PROTECTION. Defaults to NO_PROTECTION.
  • maxSize - (Required) The maximum number of instances allowed in the EC2 Auto Scaling group. During automatic scaling events, GameLift FleetIQ and EC2 do not scale up the group above this maximum.
  • minSize - (Required) The minimum number of instances allowed in the EC2 Auto Scaling group. During automatic scaling events, GameLift FleetIQ and EC2 do not scale down the group below this minimum.
  • roleArn - (Required) ARN for an IAM role that allows Amazon GameLift to access your EC2 Auto Scaling groups.
  • tags - (Optional) Key-value map of resource tags
  • vpcSubnets - (Optional) A list of VPC subnets to use with instances in the game server group. By default, all GameLift FleetIQ-supported Availability Zones are used.

autoScalingPolicy

Configuration settings to define a scaling policy for the Auto Scaling group that is optimized for game hosting. The scaling policy uses the metric percentUtilizedGameServers to maintain a buffer of idle game servers that can immediately accommodate new games and players.

  • estimatedInstanceWarmup - (Optional) Length of time, in seconds, it takes for a new instance to start new game server processes and register with GameLift FleetIQ. Specifying a warm-up time can be useful, particularly with game servers that take a long time to start up, because it avoids prematurely starting new instances. Defaults to 60.

targetTrackingConfiguration

Settings for a target-based scaling policy applied to Auto Scaling group. These settings are used to create a target-based policy that tracks the GameLift FleetIQ metric percentUtilizedGameServers and specifies a target value for the metric.

  • targetValue - (Required) Desired value to use with a game server group target-based scaling policy.

instanceDefinition

The EC2 instance types and sizes to use in the Auto Scaling group. The instance definitions must specify at least two different instance types that are supported by GameLift FleetIQ.

  • instanceType - (Required) An EC2 instance type.
  • weightedCapacity - (Optional) Instance weighting that indicates how much this instance type contributes to the total capacity of a game server group. Instance weights are used by GameLift FleetIQ to calculate the instance type's cost per unit hour and better identify the most cost-effective options.

launchTemplate

The EC2 launch template that contains configuration settings and game server code to be deployed to all instances in the game server group. You can specify the template using either the template name or ID.

  • id - (Optional) A unique identifier for an existing EC2 launch template.
  • name - (Optional) A readable identifier for an existing EC2 launch template.
  • version - (Optional) The version of the EC2 launch template to use. If none is set, the default is the first version created.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - The name of the GameLift Game Server Group.
  • arn - The ARN of the GameLift Game Server Group.
  • autoScalingGroupArn - The ARN of the created EC2 Auto Scaling group.

Timeouts

Configuration options:

  • create - (Default 10M)
  • delete - (Default 30M)

Import

GameLift Game Server Group can be imported using the name, e.g.

$ terraform import aws_gamelift_game_server_group.example example