createContainerGroupDefinition method

Future<CreateContainerGroupDefinitionOutput> createContainerGroupDefinition({
  1. required String name,
  2. required ContainerOperatingSystem operatingSystem,
  3. required int totalMemoryLimitMebibytes,
  4. required double totalVcpuLimit,
  5. ContainerGroupType? containerGroupType,
  6. GameServerContainerDefinitionInput? gameServerContainerDefinition,
  7. List<SupportContainerDefinitionInput>? supportContainerDefinitions,
  8. List<Tag>? tags,
  9. String? versionDescription,
})

This API works with the following fleet types: Container

Creates a ContainerGroupDefinition that describes a set of containers for hosting your game server with Amazon GameLift Servers managed containers hosting. An Amazon GameLift Servers container group is similar to a container task or pod. Use container group definitions when you create a container fleet with CreateContainerFleet.

A container group definition determines how Amazon GameLift Servers deploys your containers to each instance in a container fleet. You can maintain multiple versions of a container group definition.

There are two types of container groups:

  • A game server container group has the containers that run your game server application and supporting software. A game server container group can have these container types:
    • Game server container. This container runs your game server. You can define one game server container in a game server container group.
    • Support container. This container runs software in parallel with your game server. You can define up to 8 support containers in a game server group.
    When building a game server container group definition, you can choose to bundle your game server executable and all dependent software into a single game server container. Alternatively, you can separate the software into one game server container and one or more support containers.

    On a container fleet instance, a game server container group can be deployed multiple times (depending on the compute resources of the instance). This means that all containers in the container group are replicated together.

  • A per-instance container group has containers for processes that aren't replicated on a container fleet instance. This might include background services, logging, test processes, or processes that need to persist independently of the game server container group. When building a per-instance container group, you can define up to 10 support containers.
Request options

Use this operation to make the following types of requests. You can specify values for the minimum required parameters and customize optional values later.

  • Create a game server container group definition. Provide the following required parameter values:
    • Name
    • ContainerGroupType (GAME_SERVER)
    • OperatingSystem (omit to use default value)
    • TotalMemoryLimitMebibytes (omit to use default value)
    • TotalVcpuLimit (omit to use default value)
    • At least one GameServerContainerDefinition
      • ContainerName
      • ImageUrl
      • PortConfiguration
      • ServerSdkVersion (omit to use default value)
  • Create a per-instance container group definition. Provide the following required parameter values:
    • Name
    • ContainerGroupType (PER_INSTANCE)
    • OperatingSystem (omit to use default value)
    • TotalMemoryLimitMebibytes (omit to use default value)
    • TotalVcpuLimit (omit to use default value)
    • At least one SupportContainerDefinition
      • ContainerName
      • ImageUrl
Results

If successful, this request creates a ContainerGroupDefinition resource and assigns a unique ARN value. You can update most properties of a container group definition by calling UpdateContainerGroupDefinition, and optionally save the update as a new version.

May throw ConflictException. May throw InternalServiceException. May throw InvalidRequestException. May throw LimitExceededException. May throw TaggingFailedException. May throw UnauthorizedException. May throw UnsupportedRegionException.

Parameter name : A descriptive identifier for the container group definition. The name value must be unique in an Amazon Web Services Region.

Parameter operatingSystem : The platform that all containers in the group use. Containers in a group must run on the same operating system.

Default value: AMAZON_LINUX_2023

Parameter totalMemoryLimitMebibytes : The maximum amount of memory (in MiB) to allocate to the container group. All containers in the group share this memory. If you specify memory limits for an individual container, the total value must be greater than any individual container's memory limit.

Default value: 1024

Parameter totalVcpuLimit : The maximum amount of vCPU units to allocate to the container group (1 vCPU is equal to 1024 CPU units). All containers in the group share this memory. If you specify vCPU limits for individual containers, the total value must be equal to or greater than the sum of the CPU limits for all containers in the group.

Default value: 1

Parameter containerGroupType : The type of container group being defined. Container group type determines how Amazon GameLift Servers deploys the container group on each fleet instance.

Default value: GAME_SERVER

Parameter gameServerContainerDefinition : The definition for the game server container in this group. Define a game server container only when the container group type is GAME_SERVER. Game server containers specify a container image with your game server build. You can pass in your container definitions as a JSON file.

Parameter supportContainerDefinitions : One or more definition for support containers in this group. You can define a support container in any type of container group. You can pass in your container definitions as a JSON file.

Parameter tags : A list of labels to assign to the container group definition resource. Tags are developer-defined key-value pairs. Tagging Amazon Web Services resources are useful for resource management, access management and cost allocation. For more information, see Tagging Amazon Web Services Resources in the Amazon Web Services General Reference.

Parameter versionDescription : A description for the initial version of this container group definition.

Implementation

Future<CreateContainerGroupDefinitionOutput> createContainerGroupDefinition({
  required String name,
  required ContainerOperatingSystem operatingSystem,
  required int totalMemoryLimitMebibytes,
  required double totalVcpuLimit,
  ContainerGroupType? containerGroupType,
  GameServerContainerDefinitionInput? gameServerContainerDefinition,
  List<SupportContainerDefinitionInput>? supportContainerDefinitions,
  List<Tag>? tags,
  String? versionDescription,
}) async {
  _s.validateNumRange(
    'totalMemoryLimitMebibytes',
    totalMemoryLimitMebibytes,
    4,
    1024000,
    isRequired: true,
  );
  _s.validateNumRange(
    'totalVcpuLimit',
    totalVcpuLimit,
    0.125,
    10,
    isRequired: true,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'GameLift.CreateContainerGroupDefinition'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Name': name,
      'OperatingSystem': operatingSystem.value,
      'TotalMemoryLimitMebibytes': totalMemoryLimitMebibytes,
      'TotalVcpuLimit': totalVcpuLimit,
      if (containerGroupType != null)
        'ContainerGroupType': containerGroupType.value,
      if (gameServerContainerDefinition != null)
        'GameServerContainerDefinition': gameServerContainerDefinition,
      if (supportContainerDefinitions != null)
        'SupportContainerDefinitions': supportContainerDefinitions,
      if (tags != null) 'Tags': tags,
      if (versionDescription != null)
        'VersionDescription': versionDescription,
    },
  );

  return CreateContainerGroupDefinitionOutput.fromJson(jsonResponse.body);
}