GameLift / Client / create_container_group_definition

create_container_group_definition#

GameLift.Client.create_container_group_definition(**kwargs)#

This operation is used with the Amazon GameLift containers feature, which is currently in public preview.

Creates a ContainerGroupDefinition resource that describes a set of containers for hosting your game server with Amazon GameLift managed EC2 hosting. An Amazon GameLift container group is similar to a container “task” and “pod”. Each container group can have one or more containers.

Use container group definitions when you create a container fleet. Container group definitions determine how Amazon GameLift deploys your containers to each instance in a container fleet.

You can create two types of container groups, based on scheduling strategy:

  • A replica container group manages the containers that run your game server application and supporting software. Replica container groups might be replicated multiple times on each fleet instance, depending on instance resources.

  • A daemon container group manages containers that run other software, such as background services, logging, or test processes. You might use a daemon container group for processes that need to run only once per fleet instance, or processes that need to persist independently of the replica container group.

To create a container group definition, specify a group name, a list of container definitions, and maximum total CPU and memory requirements for the container group. Specify an operating system and scheduling strategy or use the default values. When using the Amazon Web Services CLI tool, you can pass in your container definitions as a JSON file.

Note

This operation requires Identity and Access Management (IAM) permissions to access container images in Amazon ECR repositories. See IAM permissions for Amazon GameLift for help setting the appropriate permissions.

If successful, this operation creates a new ContainerGroupDefinition resource with an ARN value assigned. You can’t change the properties of a container group definition. Instead, create a new one.

Learn more

See also: AWS API Documentation

Request Syntax

response = client.create_container_group_definition(
    Name='string',
    SchedulingStrategy='REPLICA'|'DAEMON',
    TotalMemoryLimit=123,
    TotalCpuLimit=123,
    ContainerDefinitions=[
        {
            'ContainerName': 'string',
            'ImageUri': 'string',
            'MemoryLimits': {
                'SoftLimit': 123,
                'HardLimit': 123
            },
            'PortConfiguration': {
                'ContainerPortRanges': [
                    {
                        'FromPort': 123,
                        'ToPort': 123,
                        'Protocol': 'TCP'|'UDP'
                    },
                ]
            },
            'Cpu': 123,
            'HealthCheck': {
                'Command': [
                    'string',
                ],
                'Interval': 123,
                'Timeout': 123,
                'Retries': 123,
                'StartPeriod': 123
            },
            'Command': [
                'string',
            ],
            'Essential': True|False,
            'EntryPoint': [
                'string',
            ],
            'WorkingDirectory': 'string',
            'Environment': [
                {
                    'Name': 'string',
                    'Value': 'string'
                },
            ],
            'DependsOn': [
                {
                    'ContainerName': 'string',
                    'Condition': 'START'|'COMPLETE'|'SUCCESS'|'HEALTHY'
                },
            ]
        },
    ],
    OperatingSystem='AMAZON_LINUX_2023',
    Tags=[
        {
            'Key': 'string',
            'Value': 'string'
        },
    ]
)
Parameters:
  • Name (string) –

    [REQUIRED]

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

  • SchedulingStrategy (string) – The method for deploying the container group across fleet instances. A replica container group might have multiple copies on each fleet instance. A daemon container group has one copy per fleet instance. Default value is REPLICA.

  • TotalMemoryLimit (integer) –

    [REQUIRED]

    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 individual containers, set this parameter based on the following guidelines. The value must be (1) greater than the sum of the soft memory limits for all containers in the group, and (2) greater than any individual container’s hard memory limit.

  • TotalCpuLimit (integer) –

    [REQUIRED]

    The maximum amount of CPU units to allocate to the container group. Set this parameter to an integer value in CPU units (1 vCPU is equal to 1024 CPU units). All containers in the group share this memory. If you specify CPU limits for individual containers, set this parameter based on the following guidelines. The value must be equal to or greater than the sum of the CPU limits for all containers in the group.

  • ContainerDefinitions (list) –

    [REQUIRED]

    Definitions for all containers in this group. Each container definition identifies the container image and specifies configuration settings for the container. See the Container fleet design guide for container guidelines.

    • (dict) –

      This data type is used with the Amazon GameLift containers feature, which is currently in public preview.

      Describes a container’s configuration, resources, and start instructions. Use this data type to create a container group definition. For the properties of a container that’s been deployed to a fleet, see ContainerDefinition. You can’t change these properties after you’ve created the container group definition. If you need a container group with different properties, then you must create a new one.

      Used with: CreateContainerGroupDefinition

      • ContainerName (string) – [REQUIRED]

        A string that uniquely identifies the container definition within a container group.

      • ImageUri (string) – [REQUIRED]

        The location of a container image that $short; will copy and deploy to a container fleet. Images in Amazon Elastic Container Registry private repositories are supported. The repository must be in the same Amazon Web Services account and Amazon Web Services Region where you’re creating the container group definition. For limits on image size, see Amazon GameLift endpoints and quotas. You can use any of the following image URI formats:

        • Image ID only: [AWS account].dkr.ecr.[AWS region].amazonaws.com/[repository ID]

        • Image ID and digest: [AWS account].dkr.ecr.[AWS region].amazonaws.com/[repository ID]@[digest]

        • Image ID and tag: [AWS account].dkr.ecr.[AWS region].amazonaws.com/[repository ID]:[tag]

      • MemoryLimits (dict) –

        The amount of memory to make available to the container. If you don’t specify memory limits for this container, then it shares the container group’s total memory allocation.

        Related data type: ContainerGroupDefinition$TotalMemoryLimit

        • SoftLimit (integer) –

          The amount of memory that is reserved for a container. When the container group’s shared memory is under contention, the system attempts to maintain the container memory usage at this soft limit. However, the container can use more memory when needed, if available. This property is similar to the Amazon ECS container definition parameter memoryreservation (Amazon Elastic Container Service Developer Guide).

        • HardLimit (integer) –

          The maximum amount of memory that the container can use. If a container attempts to exceed this limit, the container is stopped. This property is similar to the Amazon ECS container definition parameter memory in the Amazon Elastic Container Service Developer Guide.

      • PortConfiguration (dict) –

        A set of ports that Amazon GameLift can assign to processes in the container. All processes that accept inbound traffic connections, including game server processes, must be assigned a port from this set. The set of ports must be large enough to assign one to each process in the container that needs one. If the container includes your game server, include enough ports to assign one port to each concurrent server process (as defined in a container fleet’s RuntimeConfiguration). For more details, see Networking for container fleets.

        Container ports aren’t directly accessed by inbound traffic. Amazon GameLift maps these container ports to externally accessible connection ports, which are assigned as needed from the container fleet’s ConnectionPortRange.

        • ContainerPortRanges (list) – [REQUIRED]

          Specifies one or more ranges of ports on a container. These ranges must not overlap.

          • (dict) –

            This data type is used with the Amazon GameLift containers feature, which is currently in public preview.

            A set of one or more port numbers that can be opened on the container.

            Part of: ContainerPortConfiguration

            • FromPort (integer) – [REQUIRED]

              A starting value for the range of allowed port numbers.

            • ToPort (integer) – [REQUIRED]

              An ending value for the range of allowed port numbers. Port numbers are end-inclusive. This value must be equal to or greater than FromPort.

            • Protocol (string) – [REQUIRED]

              The network protocol that these ports support.

      • Cpu (integer) –

        The number of CPU units to reserve for this container. The container can use more resources when needed, if available. Note: 1 vCPU unit equals 1024 CPU units. If you don’t reserve CPU units for this container, then it shares the total CPU limit for the container group. This property is similar to the Amazon ECS container definition parameter environment (Amazon Elastic Container Service Developer Guide).

        Related data type: ContainerGroupDefinition$TotalCpuLimit

      • HealthCheck (dict) –

        Configuration for a non-terminal health check. A container automatically restarts if it stops functioning. This parameter lets you define additional reasons to consider a container unhealthy and restart it. You can set a health check for any container except for the essential container in the replica container group. If an essential container in the daemon group fails a health check, the entire container group is restarted.

        • Command (list) – [REQUIRED]

          A string array that specifies the command that the container runs to determine if it’s healthy.

          • (string) –

        • Interval (integer) –

          The time period (in seconds) between each health check.

        • Timeout (integer) –

          The time period (in seconds) to wait for a health check to succeed before a failed health check is counted.

        • Retries (integer) –

          The number of times to retry a failed health check before the container is considered unhealthy. The first run of the command does not count as a retry.

        • StartPeriod (integer) –

          The optional grace period (in seconds) to give a container time to bootstrap before the first failed health check counts toward the number of retries.

      • Command (list) –

        A command to pass to the container on startup. Add multiple arguments as additional strings in the array. See the ContainerDefinition command parameter in the Amazon Elastic Container Service API reference.

        • (string) –

      • Essential (boolean) –

        Specifies whether the container is vital for the container group to function properly. If an essential container fails, it causes the entire container group to restart. Each container group must have an essential container.

        Replica container groups - A replica group must have exactly one essential container. Use the following to configure an essential replica container:

        • Choose a container is running your game server and the Amazon GameLift Agent.

        • Include a port configuration. This container runs your game server processes, and each process requires a container port to allow access to game clients.

        • Don’t configure a health check. The Agent handles this task for the essential replica container.

        Daemon container groups - A daemon group must have at least one essential container.

      • EntryPoint (list) –

        An entry point to pass to the container on startup. Add multiple arguments as additional strings in the array. See the ContainerDefinition::entryPoint parameter in the Amazon Elastic Container Service API Reference.

        • (string) –

      • WorkingDirectory (string) –

        The directory in the container where commands are run. See the ContainerDefinition::workingDirectory parameter in the Amazon Elastic Container Service API Reference.

      • Environment (list) –

        A set of environment variables to pass to the container on startup. See the ContainerDefinition::environment parameter in the Amazon Elastic Container Service API Reference.

        • (dict) –

          This data type is used with the Amazon GameLift containers feature, which is currently in public preview.

          An environment variable to set inside a container, in the form of a key-value pair.

          Related data type: ContainerDefinition$Environment

          • Name (string) – [REQUIRED]

            The environment variable name.

          • Value (string) – [REQUIRED]

            The environment variable value.

      • DependsOn (list) –

        Sets up dependencies between this container and the status of other containers in the same container group. A container can have dependencies on multiple different containers.

        You can use dependencies to establish a startup/shutdown sequence across the container group. A container startup dependency is reversed on shutdown.

        For example, you might specify that SideCarContainerB has a START dependency on SideCarContainerA. This dependency means that SideCarContainerB can’t start until after SideCarContainerA has started. This dependency is reversed on shutdown, which means that SideCarContainerB must shut down before SideCarContainerA can shut down.

        • (dict) –

          This data type is used with the Amazon GameLift containers feature, which is currently in public preview.

          A container’s dependency on another container in the same container group. The dependency impacts how the dependent container is able to start or shut down based the status of the other container.

          For example, ContainerA is configured with the following dependency: a START dependency on ContainerB. This means that ContainerA can’t start until ContainerB has started. It also means that ContainerA must shut down before ContainerB.

          Part of: ContainerDefinition

          • ContainerName (string) – [REQUIRED]

            A descriptive label for the container definition that this container depends on.

          • Condition (string) – [REQUIRED]

            The condition that the dependency container must reach before the dependent container can start. Valid conditions include:

            • START - The dependency container must have started.

            • COMPLETE - The dependency container has run to completion (exits). Use this condition with nonessential containers, such as those that run a script and then exit. The dependency container can’t be an essential container.

            • SUCCESS - The dependency container has run to completion and exited with a zero status. The dependency container can’t be an essential container.

            • HEALTHY - The dependency container has passed its Docker health check. Use this condition with dependency containers that have health checks configured. This condition is confirmed at container group startup only.

  • OperatingSystem (string) –

    [REQUIRED]

    The platform that is used by containers in the container group definition. All containers in a group must run on the same operating system.

    Note

    Amazon Linux 2 (AL2) will reach end of support on 6/30/2025. See more details in the Amazon Linux 2 FAQs. For game servers that are hosted on AL2 and use Amazon GameLift server SDK 4.x., first update the game server build to server SDK 5.x, and then deploy to AL2023 instances. See Migrate to Amazon GameLift server SDK version 5.

  • Tags (list) –

    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.

    • (dict) –

      A label that you can assign to a Amazon GameLift resource.

      Learn more

      Tagging Amazon Web Services Resources in the Amazon Web Services General Reference

      Amazon Web Services Tagging Strategies

      Related actions

      All APIs by task

      • Key (string) – [REQUIRED]

        The key for a developer-defined key value pair for tagging an Amazon Web Services resource.

      • Value (string) – [REQUIRED]

        The value for a developer-defined key value pair for tagging an Amazon Web Services resource.

Return type:

dict

Returns:

Response Syntax

{
    'ContainerGroupDefinition': {
        'ContainerGroupDefinitionArn': 'string',
        'CreationTime': datetime(2015, 1, 1),
        'OperatingSystem': 'AMAZON_LINUX_2023',
        'Name': 'string',
        'SchedulingStrategy': 'REPLICA'|'DAEMON',
        'TotalMemoryLimit': 123,
        'TotalCpuLimit': 123,
        'ContainerDefinitions': [
            {
                'ContainerName': 'string',
                'ImageUri': 'string',
                'ResolvedImageDigest': 'string',
                'MemoryLimits': {
                    'SoftLimit': 123,
                    'HardLimit': 123
                },
                'PortConfiguration': {
                    'ContainerPortRanges': [
                        {
                            'FromPort': 123,
                            'ToPort': 123,
                            'Protocol': 'TCP'|'UDP'
                        },
                    ]
                },
                'Cpu': 123,
                'HealthCheck': {
                    'Command': [
                        'string',
                    ],
                    'Interval': 123,
                    'Timeout': 123,
                    'Retries': 123,
                    'StartPeriod': 123
                },
                'Command': [
                    'string',
                ],
                'Essential': True|False,
                'EntryPoint': [
                    'string',
                ],
                'WorkingDirectory': 'string',
                'Environment': [
                    {
                        'Name': 'string',
                        'Value': 'string'
                    },
                ],
                'DependsOn': [
                    {
                        'ContainerName': 'string',
                        'Condition': 'START'|'COMPLETE'|'SUCCESS'|'HEALTHY'
                    },
                ]
            },
        ],
        'Status': 'READY'|'COPYING'|'FAILED',
        'StatusReason': 'string'
    }
}

Response Structure

  • (dict) –

    • ContainerGroupDefinition (dict) –

      The properties of the newly created container group definition resource. You use this resource to create a container fleet.

      • ContainerGroupDefinitionArn (string) –

        The Amazon Resource Name ( ARN) that is assigned to an Amazon GameLift ContainerGroupDefinition resource. It uniquely identifies the resource across all Amazon Web Services Regions. Format is arn:aws:gamelift:<region>::containergroupdefinition/[container group definition name].

      • CreationTime (datetime) –

        A time stamp indicating when this data object was created. Format is a number expressed in Unix time as milliseconds (for example "1469498468.057").

      • OperatingSystem (string) –

        The platform required for all containers in the container group definition.

        Note

        Amazon Linux 2 (AL2) will reach end of support on 6/30/2025. See more details in the Amazon Linux 2 FAQs. For game servers that are hosted on AL2 and use Amazon GameLift server SDK 4.x., first update the game server build to server SDK 5.x, and then deploy to AL2023 instances. See Migrate to Amazon GameLift server SDK version 5.

      • Name (string) –

        A descriptive identifier for the container group definition. The name value is unique in an Amazon Web Services Region.

      • SchedulingStrategy (string) –

        The method for deploying the container group across fleet instances. A replica container group might have multiple copies on each fleet instance. A daemon container group maintains only one copy per fleet instance.

      • TotalMemoryLimit (integer) –

        The amount of memory (in MiB) on a fleet instance to allocate for the container group. All containers in the group share these resources.

        You can set additional limits for each ContainerDefinition in the group. If individual containers have limits, this value must meet the following requirements:

        • Equal to or greater than the sum of all container-specific soft memory limits in the group.

        • Equal to or greater than any container-specific hard limits in the group.

        For more details on memory allocation, see the Container fleet design guide.

      • TotalCpuLimit (integer) –

        The amount of CPU units on a fleet instance to allocate for the container group. All containers in the group share these resources. This property is an integer value in CPU units (1 vCPU is equal to 1024 CPU units).

        You can set additional limits for each ContainerDefinition in the group. If individual containers have limits, this value must be equal to or greater than the sum of all container-specific CPU limits in the group.

        For more details on memory allocation, see the Container fleet design guide.

      • ContainerDefinitions (list) –

        The set of container definitions that are included in the container group.

        • (dict) –

          This data type is used with the Amazon GameLift containers feature, which is currently in public preview.

          Describes a container in a container fleet, the resources available to the container, and the commands that are run when the container starts. Container properties can’t be updated. To change a property, create a new container group definition. See also ContainerDefinitionInput.

          Part of: ContainerGroupDefinition

          Returned by: DescribeContainerGroupDefinition, ListContainerGroupDefinitions

          • ContainerName (string) –

            The container definition identifier. Container names are unique within a container group definition.

          • ImageUri (string) –

            The URI to the image that $short; copied and deployed to a container fleet. For a more specific identifier, see ResolvedImageDigest.

          • ResolvedImageDigest (string) –

            A unique and immutable identifier for the container image that is deployed to a container fleet. The digest is a SHA 256 hash of the container image manifest.

          • MemoryLimits (dict) –

            The amount of memory that Amazon GameLift makes available to the container. If memory limits aren’t set for an individual container, the container shares the container group’s total memory allocation.

            Related data type: ContainerGroupDefinition$TotalMemoryLimit

            • SoftLimit (integer) –

              The amount of memory that is reserved for a container. When the container group’s shared memory is under contention, the system attempts to maintain the container memory usage at this soft limit. However, the container can use more memory when needed, if available. This property is similar to the Amazon ECS container definition parameter memoryreservation (Amazon Elastic Container Service Developer Guide).

            • HardLimit (integer) –

              The maximum amount of memory that the container can use. If a container attempts to exceed this limit, the container is stopped. This property is similar to the Amazon ECS container definition parameter memory in the Amazon Elastic Container Service Developer Guide.

          • PortConfiguration (dict) –

            Defines the ports that are available to assign to processes in the container. For example, a game server process requires a container port to allow game clients to connect to it. Container ports aren’t directly accessed by inbound traffic. Amazon GameLift maps these container ports to externally accessible connection ports, which are assigned as needed from the container fleet’s ConnectionPortRange.

            • ContainerPortRanges (list) –

              Specifies one or more ranges of ports on a container. These ranges must not overlap.

              • (dict) –

                This data type is used with the Amazon GameLift containers feature, which is currently in public preview.

                A set of one or more port numbers that can be opened on the container.

                Part of: ContainerPortConfiguration

                • FromPort (integer) –

                  A starting value for the range of allowed port numbers.

                • ToPort (integer) –

                  An ending value for the range of allowed port numbers. Port numbers are end-inclusive. This value must be equal to or greater than FromPort.

                • Protocol (string) –

                  The network protocol that these ports support.

          • Cpu (integer) –

            The number of CPU units that are reserved for the container. Note: 1 vCPU unit equals 1024 CPU units. If no resources are reserved, the container shares the total CPU limit for the container group.

            Related data type: ContainerGroupDefinition$TotalCpuLimit

          • HealthCheck (dict) –

            A configuration for a non-terminal health check. A container, which automatically restarts if it stops functioning, also restarts if it fails this health check. If an essential container in the daemon group fails a health check, the entire container group is restarted. The essential container in the replica group doesn’t use this health check mechanism, because the Amazon GameLift Agent automatically handles the task.

            • Command (list) –

              A string array that specifies the command that the container runs to determine if it’s healthy.

              • (string) –

            • Interval (integer) –

              The time period (in seconds) between each health check.

            • Timeout (integer) –

              The time period (in seconds) to wait for a health check to succeed before a failed health check is counted.

            • Retries (integer) –

              The number of times to retry a failed health check before the container is considered unhealthy. The first run of the command does not count as a retry.

            • StartPeriod (integer) –

              The optional grace period (in seconds) to give a container time to bootstrap before the first failed health check counts toward the number of retries.

          • Command (list) –

            A command that’s passed to the container on startup. Each argument for the command is an additional string in the array. See the ContainerDefinition::command parameter in the Amazon Elastic Container Service API reference.

            • (string) –

          • Essential (boolean) –

            Indicates whether the container is vital to the container group. If an essential container fails, the entire container group is restarted.

          • EntryPoint (list) –

            The entry point that’s passed to the container on startup. If there are multiple arguments, each argument is an additional string in the array. See the ContainerDefinition::entryPoint parameter in the Amazon Elastic Container Service API Reference.

            • (string) –

          • WorkingDirectory (string) –

            The directory in the container where commands are run. See the ContainerDefinition::workingDirectory parameter in the Amazon Elastic Container Service API Reference.

          • Environment (list) –

            A set of environment variables that’s passed to the container on startup. See the ContainerDefinition::environment parameter in the Amazon Elastic Container Service API Reference.

            • (dict) –

              This data type is used with the Amazon GameLift containers feature, which is currently in public preview.

              An environment variable to set inside a container, in the form of a key-value pair.

              Related data type: ContainerDefinition$Environment

              • Name (string) –

                The environment variable name.

              • Value (string) –

                The environment variable value.

          • DependsOn (list) –

            Indicates that the container relies on the status of other containers in the same container group during its startup and shutdown sequences. A container might have dependencies on multiple containers.

            • (dict) –

              This data type is used with the Amazon GameLift containers feature, which is currently in public preview.

              A container’s dependency on another container in the same container group. The dependency impacts how the dependent container is able to start or shut down based the status of the other container.

              For example, ContainerA is configured with the following dependency: a START dependency on ContainerB. This means that ContainerA can’t start until ContainerB has started. It also means that ContainerA must shut down before ContainerB.

              Part of: ContainerDefinition

              • ContainerName (string) –

                A descriptive label for the container definition that this container depends on.

              • Condition (string) –

                The condition that the dependency container must reach before the dependent container can start. Valid conditions include:

                • START - The dependency container must have started.

                • COMPLETE - The dependency container has run to completion (exits). Use this condition with nonessential containers, such as those that run a script and then exit. The dependency container can’t be an essential container.

                • SUCCESS - The dependency container has run to completion and exited with a zero status. The dependency container can’t be an essential container.

                • HEALTHY - The dependency container has passed its Docker health check. Use this condition with dependency containers that have health checks configured. This condition is confirmed at container group startup only.

      • Status (string) –

        Current status of the container group definition resource. Values include:

        • COPYING – Amazon GameLift is in the process of making copies of all container images that are defined in the group. While in this state, the resource can’t be used to create a container fleet.

        • READY – Amazon GameLift has copied the registry images for all containers that are defined in the group. You can use a container group definition in this status to create a container fleet.

        • FAILED – Amazon GameLift failed to create a valid container group definition resource. For more details on the cause of the failure, see StatusReason. A container group definition resource in failed status will be deleted within a few minutes.

      • StatusReason (string) –

        Additional information about a container group definition that’s in FAILED status. Possible reasons include:

        • An internal issue prevented Amazon GameLift from creating the container group definition resource. Delete the failed resource and call CreateContainerGroupDefinitionagain.

        • An access-denied message means that you don’t have permissions to access the container image on ECR. See IAM permission examples for help setting up required IAM permissions for Amazon GameLift.

        • The ImageUri value for at least one of the containers in the container group definition was invalid or not found in the current Amazon Web Services account.

        • At least one of the container images referenced in the container group definition exceeds the allowed size. For size limits, see Amazon GameLift endpoints and quotas.

        • At least one of the container images referenced in the container group definition uses a different operating system than the one defined for the container group.

Exceptions

  • GameLift.Client.exceptions.UnauthorizedException

  • GameLift.Client.exceptions.InvalidRequestException

  • GameLift.Client.exceptions.ConflictException

  • GameLift.Client.exceptions.LimitExceededException

  • GameLift.Client.exceptions.TaggingFailedException

  • GameLift.Client.exceptions.InternalServiceException

  • GameLift.Client.exceptions.UnsupportedRegionException