GS2-Inventory Deploy/CDK Reference

The template format used when creating stacks with GS2-Deploy, and implementation examples of template output in various languages using CDK

Entities

Resources targeted by the Deploy operation

Namespace

Namespace

A Namespace allows multiple independent instances of the same service within a single project by separating data spaces and usage contexts. Each GS2 service is managed on a per-namespace basis. Even when using the same service, if the namespace differs, the data is treated as a completely independent data space.

Therefore, you must create a namespace before you can start using each service.

Request

Resource creation and update requests

TypeConditionRequiredDefaultValue LimitsDescription
namestring
~ 128 charsNamespace name
Namespace-specific name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
descriptionstring~ 1024 charsDescription
transactionSettingTransactionSettingTransaction Setting
Configures distributed transaction processing for inventory operations such as acquiring and consuming items. Supports auto-run mode for seamless execution, atomic commit for consistent multi-resource operations, and async processing for large-scale reward distribution.
acquireScriptScriptSettingScript setting to be executed when an Items is acquired
Script Trigger Reference - acquire
overflowScriptScriptSettingScript to execute when unable to obtain due to reaching the acquisition limit
Script Trigger Reference - overflowDone
consumeScriptScriptSettingScript to run when consuming Items
Script Trigger Reference - consume
simpleItemAcquireScriptScriptSettingScript setting to be executed when acquiring Simple Items
Script Trigger Reference - simpleItemAcquire
simpleItemConsumeScriptScriptSettingScript to run when consuming Simple Items
Script Trigger Reference - simpleItemConsume
bigItemAcquireScriptScriptSettingScript setting to be executed when acquiring Big Items
Script Trigger Reference - bigItemAcquire
bigItemConsumeScriptScriptSettingScript to run when consuming Big Items
Script Trigger Reference - bigItemConsume
logSettingLogSettingLog Output Settings
Specifies the GS2-Log namespace for outputting API request and response logs of inventory operations. Useful for tracking item acquisition, consumption, and capacity changes for debugging and analytics.

GetAttr

Resource creation results that can be retrieved using the !GetAttr tag

TypeDescription
ItemNamespaceNamespace created

Implementation Example

Type: GS2::Inventory::Namespace
Properties:
  Name: namespace-0001
  Description: null
  TransactionSetting: null
  AcquireScript: null
  OverflowScript: null
  ConsumeScript: null
  SimpleItemAcquireScript: null
  SimpleItemConsumeScript: null
  BigItemAcquireScript: null
  BigItemConsumeScript: null
  LogSetting: 
    LoggingNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/inventory"
)


SampleStack := core.NewStack()
inventory.NewNamespace(
    &SampleStack,
    "namespace-0001",
    inventory.NamespaceOptions{
        LogSetting: &core.LogSetting{
            LoggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001",
        },
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Inventory\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Inventory\Model\Options\NamespaceOptions(
                logSetting: new \Gs2Cdk\Core\Model\LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            )
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.inventory.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.inventory.model.options.NamespaceOptions()
                        .withLogSetting(new io.gs2.cdk.core.model.LogSetting(
                            "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                        ))
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Inventory.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2Inventory.Model.Options.NamespaceOptions
            {
                logSetting = new Gs2Cdk.Core.Model.LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import inventory from "@/gs2cdk/inventory";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new inventory.model.Namespace(
            this,
            "namespace-0001",
            {
                logSetting: new core.LogSetting(
                    "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, inventory

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        inventory.Namespace(
            stack=self,
            name='namespace-0001',
            options=inventory.NamespaceOptions(
                log_setting=core.LogSetting(
                    logging_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001',
                ),
            ),
        )

print(SampleStack().yaml())  # Generate Template

TransactionSetting

Transaction Setting

Transaction Setting controls how transactions are executed, including their consistency, asynchronous processing, and conflict avoidance mechanisms. Combining features like AutoRun, AtomicCommit, asynchronous execution using GS2-Distributor, batch application of script results, and asynchronous Acquire Actions via GS2-JobQueue enables robust transaction management tailored to game logic.

TypeConditionRequiredDefaultValue LimitsDescription
enableAutoRunboolfalseWhether to automatically execute issued transactions on the server side
enableAtomicCommitbool{enableAutoRun} == truefalseWhether to commit the execution of transactions atomically
* Applicable only if enableAutoRun is true
transactionUseDistributorbool{enableAtomicCommit} == truefalseWhether to execute transactions asynchronously
* Applicable only if enableAtomicCommit is true
commitScriptResultInUseDistributorbool{transactionUseDistributor} == truefalseWhether to execute the commit processing of the script result asynchronously
* Applicable only if transactionUseDistributor is true
acquireActionUseJobQueuebool{enableAtomicCommit} == truefalseWhether to use GS2-JobQueue to execute the acquire action
* Applicable only if enableAtomicCommit is true
distributorNamespaceIdstring“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024 charsGS2-Distributor Namespace GRN used to execute transactions
queueNamespaceIdstring“grn:gs2:{region}:{ownerId}:queue:default”~ 1024 charsGS2-JobQueue Namespace GRN used to execute transactions

ScriptSetting

Script Setting

In GS2, you can associate custom scripts with microservice events and execute them. This model holds the settings for triggering script execution.

There are two main ways to execute a script: synchronous execution and asynchronous execution. Synchronous execution blocks processing until the script has finished executing. Instead, you can use the script’s execution results to halt API execution or control the API’s response content.

In contrast, asynchronous execution does not block processing until the script has finished executing. However, because the script result cannot be used to stop the API execution or modify the API response, asynchronous execution does not affect the API response flow and is generally recommended.

There are two types of asynchronous execution methods: GS2-Script and Amazon EventBridge. By using Amazon EventBridge, you can write processing in languages other than Lua.

TypeConditionRequiredDefaultValue LimitsDescription
triggerScriptIdstring~ 1024 charsGS2-Script script GRN executed synchronously when the API is executed
Must be specified in GRN format starting with “grn:gs2:”.
doneTriggerTargetTypeString Enum
enum {
  “none”,
  “gs2_script”,
  “aws”
}
“none”How to execute asynchronous scripts
Specifies the type of script to use for asynchronous execution.
You can choose from “Do not use asynchronous execution (none)”, “Use GS2-Script (gs2_script)”, and “Use Amazon EventBridge (aws)”.
DefinitionDescription
“none”None
“gs2_script”GS2-Script
“aws”Amazon EventBridge
doneTriggerScriptIdstring{doneTriggerTargetType} == “gs2_script”~ 1024 charsGS2-Script script GRN for asynchronous execution
Must be specified in GRN format starting with “grn:gs2:”.
* Applicable only if doneTriggerTargetType is “gs2_script”
doneTriggerQueueNamespaceIdstring{doneTriggerTargetType} == “gs2_script”~ 1024 charsGS2-JobQueue namespace GRN to execute asynchronous execution scripts
If you want to execute asynchronous execution scripts via GS2-JobQueue instead of executing them directly, specify the GS2-JobQueue namespace GRN.
There are not many cases where GS2-JobQueue is required, so you generally do not need to specify it unless you have a specific reason.
* Applicable only if doneTriggerTargetType is “gs2_script”

LogSetting

Log Output Setting

Log Output Settings define how log data is exported. This type holds the GS2-Log namespace identifier (Namespace ID) used to export log data. Specify the GS2-Log namespace where log data is collected and stored in the GRN format for the Log Namespace ID (loggingNamespaceId). Configuring this setting ensures that log data for API requests and responses occurring within the specified namespace is output to the target GS2-Log namespace. GS2-Log provides real-time logs that can be used for system monitoring, analysis, debugging, and other operational purposes.

TypeConditionRequiredDefaultValue LimitsDescription
loggingNamespaceIdstring
~ 1024 charsGS2-Log namespace GRN to output logs
Must be specified in GRN format starting with “grn:gs2:”.

CurrentItemModelMaster

Currently active Item Model master data

This master data describes the definitions of Item Models currently active within the namespace. GS2 uses JSON format files for managing master data. By uploading these files, the master data settings are updated on the server.

To create JSON files, GS2 provides a master data editor within the management console. Additionally, you can create tools better suited for game operations and export JSON files in the appropriate format.

Request

Resource creation and update requests

TypeConditionRequiredDefaultValue LimitsDescription
namespaceNamestring
~ 128 charsNamespace name
Namespace-specific name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
modeString Enum
enum {
  “direct”,
  “preUpload”
}
“direct”Update mode
DefinitionDescription
“direct”Directly update master data
“preUpload”Upload master data and then update
settingsstring{mode} == “direct”
✓*
~ 5242880 charsMaster Data
* Required if mode is “direct”
uploadTokenstring{mode} == “preUpload”
✓*
~ 1024 charsToken obtained by pre-upload
Used to apply the uploaded master data.
* Required if mode is “preUpload”

GetAttr

Resource creation results that can be retrieved using the !GetAttr tag

TypeDescription
ItemCurrentItemModelMasterUpdated master data of the currently active Item Models

Implementation Example

Type: GS2::Inventory::CurrentItemModelMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2019-02-05",
    "inventoryModels": [
      {
        "name": "item",
        "initialCapacity": 100,
        "maxCapacity": 999,
        "itemModels": [
          {
            "name": "item-0001",
            "metadata": "ITEM_0001",
            "stackingLimit": 99,
            "allowMultipleStacks": false,
            "sortValue": 1
          },
          {
            "name": "item-0002",
            "metadata": "ITEM_0002",
            "stackingLimit": 49,
            "allowMultipleStacks": true,
            "sortValue": 2
          },
          {
            "name": "item-0003",
            "metadata": "ITEM_0003",
            "stackingLimit": 9,
            "allowMultipleStacks": false,
            "sortValue": 3
          }
        ],
        "metadata": "INVENTORY_ITEM"
      },
      {
        "name": "character",
        "initialCapacity": 50,
        "maxCapacity": 99,
        "itemModels": [
          {
            "name": "character-0001",
            "metadata": "CHARACTER_0001",
            "stackingLimit": 99,
            "allowMultipleStacks": false,
            "sortValue": 1
          },
          {
            "name": "character-0002",
            "metadata": "CHARACTER_0002",
            "stackingLimit": 49,
            "allowMultipleStacks": true,
            "sortValue": 2
          },
          {
            "name": "character-0003",
            "metadata": "CHARACTER_0003",
            "stackingLimit": 9,
            "allowMultipleStacks": false,
            "sortValue": 3
          }
        ],
        "metadata": "INVENTORY_CHARACTER"
      }
    ],
    "simpleInventoryModels": [
      {
        "name": "item",
        "simpleItemModels": [
          {
            "name": "item-0001",
            "metadata": "ITEM_0001"
          },
          {
            "name": "item-0002",
            "metadata": "ITEM_0002"
          },
          {
            "name": "item-0003",
            "metadata": "ITEM_0003"
          }
        ],
        "metadata": "INVENTORY_ITEM"
      }
    ],
    "bigInventoryModels": [
      {
        "name": "item",
        "bigItemModels": [
          {
            "name": "item-0001",
            "metadata": "ITEM_0001"
          },
          {
            "name": "item-0002",
            "metadata": "ITEM_0002"
          },
          {
            "name": "item-0003",
            "metadata": "ITEM_0003"
          }
        ],
        "metadata": "INVENTORY_ITEM"
      }
    ]
  }
  UploadToken: null
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/inventory"
    "github.com/openlyinc/pointy"
)


SampleStack := core.NewStack()
inventory.NewNamespace(
    &SampleStack,
    "namespace-0001",
    inventory.NamespaceOptions{},
).MasterData(
    []inventory.InventoryModel{
        inventory.NewInventoryModel(
            "item",
            100,
            999,
            []inventory.ItemModel{
                inventory.NewItemModel(
                    "item-0001",
                    99,
                    false,
                    1,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("ITEM_0001"),
                    },
                ),
                inventory.NewItemModel(
                    "item-0002",
                    49,
                    true,
                    2,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("ITEM_0002"),
                    },
                ),
                inventory.NewItemModel(
                    "item-0003",
                    9,
                    false,
                    3,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("ITEM_0003"),
                    },
                ),
            },
            inventory.InventoryModelOptions{
                Metadata: pointy.String("INVENTORY_ITEM"),
            },
        ),
        inventory.NewInventoryModel(
            "character",
            50,
            99,
            []inventory.ItemModel{
                inventory.NewItemModel(
                    "character-0001",
                    99,
                    false,
                    1,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("CHARACTER_0001"),
                    },
                ),
                inventory.NewItemModel(
                    "character-0002",
                    49,
                    true,
                    2,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("CHARACTER_0002"),
                    },
                ),
                inventory.NewItemModel(
                    "character-0003",
                    9,
                    false,
                    3,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("CHARACTER_0003"),
                    },
                ),
            },
            inventory.InventoryModelOptions{
                Metadata: pointy.String("INVENTORY_CHARACTER"),
            },
        ),
    },
    []inventory.SimpleInventoryModel{
        inventory.NewSimpleInventoryModel(
            "item",
            []inventory.SimpleItemModel{
                inventory.NewSimpleItemModel(
                    "item-0001",
                    inventory.SimpleItemModelOptions{
                        Metadata: pointy.String("ITEM_0001"),
                    },
                ),
                inventory.NewSimpleItemModel(
                    "item-0002",
                    inventory.SimpleItemModelOptions{
                        Metadata: pointy.String("ITEM_0002"),
                    },
                ),
                inventory.NewSimpleItemModel(
                    "item-0003",
                    inventory.SimpleItemModelOptions{
                        Metadata: pointy.String("ITEM_0003"),
                    },
                ),
            },
            inventory.SimpleInventoryModelOptions{
                Metadata: pointy.String("INVENTORY_ITEM"),
            },
        ),
    },
    []inventory.BigInventoryModel{
        inventory.NewBigInventoryModel(
            "item",
            []inventory.BigItemModel{
                inventory.NewBigItemModel(
                    "item-0001",
                    inventory.BigItemModelOptions{
                        Metadata: pointy.String("ITEM_0001"),
                    },
                ),
                inventory.NewBigItemModel(
                    "item-0002",
                    inventory.BigItemModelOptions{
                        Metadata: pointy.String("ITEM_0002"),
                    },
                ),
                inventory.NewBigItemModel(
                    "item-0003",
                    inventory.BigItemModelOptions{
                        Metadata: pointy.String("ITEM_0003"),
                    },
                ),
            },
            inventory.BigInventoryModelOptions{
                Metadata: pointy.String("INVENTORY_ITEM"),
            },
        ),
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Inventory\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\Inventory\Model\InventoryModel(
                    name:"item",
                    initialCapacity:100,
                    maxCapacity:999,
                    itemModels:[
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "item-0001",
                            stackingLimit: 99,
                            allowMultipleStacks: false,
                            sortValue: 1,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "ITEM_0001",
                            )
                        ),
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "item-0002",
                            stackingLimit: 49,
                            allowMultipleStacks: true,
                            sortValue: 2,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "ITEM_0002",
                            )
                        ),
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "item-0003",
                            stackingLimit: 9,
                            allowMultipleStacks: false,
                            sortValue: 3,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "ITEM_0003",
                            )
                        ),
                    ],
                    options: new \Gs2Cdk\Inventory\Model\Options\InventoryModelOptions(
                        metadata:"INVENTORY_ITEM"
                    )
                ),
                new \Gs2Cdk\Inventory\Model\InventoryModel(
                    name:"character",
                    initialCapacity:50,
                    maxCapacity:99,
                    itemModels:[
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "character-0001",
                            stackingLimit: 99,
                            allowMultipleStacks: false,
                            sortValue: 1,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "CHARACTER_0001",
                            )
                        ),
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "character-0002",
                            stackingLimit: 49,
                            allowMultipleStacks: true,
                            sortValue: 2,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "CHARACTER_0002",
                            )
                        ),
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "character-0003",
                            stackingLimit: 9,
                            allowMultipleStacks: false,
                            sortValue: 3,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "CHARACTER_0003",
                            )
                        ),
                    ],
                    options: new \Gs2Cdk\Inventory\Model\Options\InventoryModelOptions(
                        metadata:"INVENTORY_CHARACTER"
                    )
                )
            ],
            [
                new \Gs2Cdk\Inventory\Model\SimpleInventoryModel(
                    name:"item",
                    simpleItemModels:[
                        new \Gs2Cdk\Inventory\Model\SimpleItemModel(
                            name: "item-0001",
                            options: new \Gs2Cdk\Inventory\Model\Options\SimpleItemModelOptions(
                                metadata: "ITEM_0001",
                            )
                        ),
                        new \Gs2Cdk\Inventory\Model\SimpleItemModel(
                            name: "item-0002",
                            options: new \Gs2Cdk\Inventory\Model\Options\SimpleItemModelOptions(
                                metadata: "ITEM_0002",
                            )
                        ),
                        new \Gs2Cdk\Inventory\Model\SimpleItemModel(
                            name: "item-0003",
                            options: new \Gs2Cdk\Inventory\Model\Options\SimpleItemModelOptions(
                                metadata: "ITEM_0003",
                            )
                        ),
                    ],
                    options: new \Gs2Cdk\Inventory\Model\Options\SimpleInventoryModelOptions(
                        metadata:"INVENTORY_ITEM"
                    )
                )
            ],
            [
                new \Gs2Cdk\Inventory\Model\BigInventoryModel(
                    name:"item",
                    bigItemModels:[
                        new \Gs2Cdk\Inventory\Model\BigItemModel(
                            name: "item-0001",
                            options: new \Gs2Cdk\Inventory\Model\Options\BigItemModelOptions(
                                metadata: "ITEM_0001",
                            )
                        ),
                        new \Gs2Cdk\Inventory\Model\BigItemModel(
                            name: "item-0002",
                            options: new \Gs2Cdk\Inventory\Model\Options\BigItemModelOptions(
                                metadata: "ITEM_0002",
                            )
                        ),
                        new \Gs2Cdk\Inventory\Model\BigItemModel(
                            name: "item-0003",
                            options: new \Gs2Cdk\Inventory\Model\Options\BigItemModelOptions(
                                metadata: "ITEM_0003",
                            )
                        ),
                    ],
                    options: new \Gs2Cdk\Inventory\Model\Options\BigInventoryModelOptions(
                        metadata:"INVENTORY_ITEM"
                    )
                )
            ]
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.inventory.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.inventory.model.InventoryModel(
                    "item",
                    100,
                    999,
                    Arrays.asList(
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "item-0001",
                            99L,
                            false,
                            1,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("ITEM_0001")
                        ),
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "item-0002",
                            49L,
                            true,
                            2,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("ITEM_0002")
                        ),
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "item-0003",
                            9L,
                            false,
                            3,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("ITEM_0003")
                        )
                    ),
                    new io.gs2.cdk.inventory.model.options.InventoryModelOptions()
                        .withMetadata("INVENTORY_ITEM")
                ),
                new io.gs2.cdk.inventory.model.InventoryModel(
                    "character",
                    50,
                    99,
                    Arrays.asList(
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "character-0001",
                            99L,
                            false,
                            1,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("CHARACTER_0001")
                        ),
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "character-0002",
                            49L,
                            true,
                            2,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("CHARACTER_0002")
                        ),
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "character-0003",
                            9L,
                            false,
                            3,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("CHARACTER_0003")
                        )
                    ),
                    new io.gs2.cdk.inventory.model.options.InventoryModelOptions()
                        .withMetadata("INVENTORY_CHARACTER")
                )
            ),
            Arrays.asList(
                new io.gs2.cdk.inventory.model.SimpleInventoryModel(
                    "item",
                    Arrays.asList(
                        new io.gs2.cdk.inventory.model.SimpleItemModel(
                            "item-0001",
                            new io.gs2.cdk.inventory.model.options.SimpleItemModelOptions()
                                .withMetadata("ITEM_0001")
                        ),
                        new io.gs2.cdk.inventory.model.SimpleItemModel(
                            "item-0002",
                            new io.gs2.cdk.inventory.model.options.SimpleItemModelOptions()
                                .withMetadata("ITEM_0002")
                        ),
                        new io.gs2.cdk.inventory.model.SimpleItemModel(
                            "item-0003",
                            new io.gs2.cdk.inventory.model.options.SimpleItemModelOptions()
                                .withMetadata("ITEM_0003")
                        )
                    ),
                    new io.gs2.cdk.inventory.model.options.SimpleInventoryModelOptions()
                        .withMetadata("INVENTORY_ITEM")
                )
            ),
            Arrays.asList(
                new io.gs2.cdk.inventory.model.BigInventoryModel(
                    "item",
                    Arrays.asList(
                        new io.gs2.cdk.inventory.model.BigItemModel(
                            "item-0001",
                            new io.gs2.cdk.inventory.model.options.BigItemModelOptions()
                                .withMetadata("ITEM_0001")
                        ),
                        new io.gs2.cdk.inventory.model.BigItemModel(
                            "item-0002",
                            new io.gs2.cdk.inventory.model.options.BigItemModelOptions()
                                .withMetadata("ITEM_0002")
                        ),
                        new io.gs2.cdk.inventory.model.BigItemModel(
                            "item-0003",
                            new io.gs2.cdk.inventory.model.options.BigItemModelOptions()
                                .withMetadata("ITEM_0003")
                        )
                    ),
                    new io.gs2.cdk.inventory.model.options.BigInventoryModelOptions()
                        .withMetadata("INVENTORY_ITEM")
                )
            )
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Inventory.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2Inventory.Model.InventoryModel[] {
                new Gs2Cdk.Gs2Inventory.Model.InventoryModel(
                    name: "item",
                    initialCapacity: 100,
                    maxCapacity: 999,
                    itemModels: new Gs2Cdk.Gs2Inventory.Model.ItemModel[]
                    {
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "item-0001",
                            stackingLimit: 99L,
                            allowMultipleStacks: false,
                            sortValue: 1,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "ITEM_0001"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "item-0002",
                            stackingLimit: 49L,
                            allowMultipleStacks: true,
                            sortValue: 2,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "ITEM_0002"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "item-0003",
                            stackingLimit: 9L,
                            allowMultipleStacks: false,
                            sortValue: 3,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "ITEM_0003"
                            }
                        )
                    },
                    options: new Gs2Cdk.Gs2Inventory.Model.Options.InventoryModelOptions
                    {
                        metadata = "INVENTORY_ITEM"
                    }
                ),
                new Gs2Cdk.Gs2Inventory.Model.InventoryModel(
                    name: "character",
                    initialCapacity: 50,
                    maxCapacity: 99,
                    itemModels: new Gs2Cdk.Gs2Inventory.Model.ItemModel[]
                    {
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "character-0001",
                            stackingLimit: 99L,
                            allowMultipleStacks: false,
                            sortValue: 1,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "CHARACTER_0001"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "character-0002",
                            stackingLimit: 49L,
                            allowMultipleStacks: true,
                            sortValue: 2,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "CHARACTER_0002"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "character-0003",
                            stackingLimit: 9L,
                            allowMultipleStacks: false,
                            sortValue: 3,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "CHARACTER_0003"
                            }
                        )
                    },
                    options: new Gs2Cdk.Gs2Inventory.Model.Options.InventoryModelOptions
                    {
                        metadata = "INVENTORY_CHARACTER"
                    }
                )
            },
            new Gs2Cdk.Gs2Inventory.Model.SimpleInventoryModel[] {
                new Gs2Cdk.Gs2Inventory.Model.SimpleInventoryModel(
                    name: "item",
                    simpleItemModels: new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel[]
                    {
                        new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel(
                            name: "item-0001",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleItemModelOptions
                            {
                                metadata = "ITEM_0001"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel(
                            name: "item-0002",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleItemModelOptions
                            {
                                metadata = "ITEM_0002"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel(
                            name: "item-0003",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleItemModelOptions
                            {
                                metadata = "ITEM_0003"
                            }
                        )
                    },
                    options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleInventoryModelOptions
                    {
                        metadata = "INVENTORY_ITEM"
                    }
                )
            },
            new Gs2Cdk.Gs2Inventory.Model.BigInventoryModel[] {
                new Gs2Cdk.Gs2Inventory.Model.BigInventoryModel(
                    name: "item",
                    bigItemModels: new Gs2Cdk.Gs2Inventory.Model.BigItemModel[]
                    {
                        new Gs2Cdk.Gs2Inventory.Model.BigItemModel(
                            name: "item-0001",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.BigItemModelOptions
                            {
                                metadata = "ITEM_0001"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.BigItemModel(
                            name: "item-0002",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.BigItemModelOptions
                            {
                                metadata = "ITEM_0002"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.BigItemModel(
                            name: "item-0003",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.BigItemModelOptions
                            {
                                metadata = "ITEM_0003"
                            }
                        )
                    },
                    options: new Gs2Cdk.Gs2Inventory.Model.Options.BigInventoryModelOptions
                    {
                        metadata = "INVENTORY_ITEM"
                    }
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import inventory from "@/gs2cdk/inventory";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new inventory.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new inventory.model.InventoryModel(
                    "item",
                    100,
                    999,
                    [
                        new inventory.model.ItemModel(
                            "item-0001",
                            99,
                            false,
                            1,
                            {
                                metadata: "ITEM_0001"
                            }
                        ),
                        new inventory.model.ItemModel(
                            "item-0002",
                            49,
                            true,
                            2,
                            {
                                metadata: "ITEM_0002"
                            }
                        ),
                        new inventory.model.ItemModel(
                            "item-0003",
                            9,
                            false,
                            3,
                            {
                                metadata: "ITEM_0003"
                            }
                        ),
                    ],
                    {
                        metadata: "INVENTORY_ITEM"
                    }
                ),
                new inventory.model.InventoryModel(
                    "character",
                    50,
                    99,
                    [
                        new inventory.model.ItemModel(
                            "character-0001",
                            99,
                            false,
                            1,
                            {
                                metadata: "CHARACTER_0001"
                            }
                        ),
                        new inventory.model.ItemModel(
                            "character-0002",
                            49,
                            true,
                            2,
                            {
                                metadata: "CHARACTER_0002"
                            }
                        ),
                        new inventory.model.ItemModel(
                            "character-0003",
                            9,
                            false,
                            3,
                            {
                                metadata: "CHARACTER_0003"
                            }
                        ),
                    ],
                    {
                        metadata: "INVENTORY_CHARACTER"
                    }
                )
            ],
            [
                new inventory.model.SimpleInventoryModel(
                    "item",
                    [
                        new inventory.model.SimpleItemModel(
                            "item-0001",
                            {
                                metadata: "ITEM_0001"
                            }
                        ),
                        new inventory.model.SimpleItemModel(
                            "item-0002",
                            {
                                metadata: "ITEM_0002"
                            }
                        ),
                        new inventory.model.SimpleItemModel(
                            "item-0003",
                            {
                                metadata: "ITEM_0003"
                            }
                        ),
                    ],
                    {
                        metadata: "INVENTORY_ITEM"
                    }
                )
            ],
            [
                new inventory.model.BigInventoryModel(
                    "item",
                    [
                        new inventory.model.BigItemModel(
                            "item-0001",
                            {
                                metadata: "ITEM_0001"
                            }
                        ),
                        new inventory.model.BigItemModel(
                            "item-0002",
                            {
                                metadata: "ITEM_0002"
                            }
                        ),
                        new inventory.model.BigItemModel(
                            "item-0003",
                            {
                                metadata: "ITEM_0003"
                            }
                        ),
                    ],
                    {
                        metadata: "INVENTORY_ITEM"
                    }
                )
            ]
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, inventory

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        inventory.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            inventory_models=[
                inventory.InventoryModel(
                    name='item',
                    initial_capacity=100,
                    max_capacity=999,
                    item_models=[
                        inventory.ItemModel(
                            name='item-0001',
                            stacking_limit=99,
                            allow_multiple_stacks=False,
                            sort_value=1,
                            options=inventory.ItemModelOptions(
                                metadata='ITEM_0001',
                            ),
                        ),
                        inventory.ItemModel(
                            name='item-0002',
                            stacking_limit=49,
                            allow_multiple_stacks=True,
                            sort_value=2,
                            options=inventory.ItemModelOptions(
                                metadata='ITEM_0002',
                            ),
                        ),
                        inventory.ItemModel(
                            name='item-0003',
                            stacking_limit=9,
                            allow_multiple_stacks=False,
                            sort_value=3,
                            options=inventory.ItemModelOptions(
                                metadata='ITEM_0003',
                            ),
                        ),
                    ],
                    options=inventory.InventoryModelOptions(
                        metadata = 'INVENTORY_ITEM'
                    ),
                ),
                inventory.InventoryModel(
                    name='character',
                    initial_capacity=50,
                    max_capacity=99,
                    item_models=[
                        inventory.ItemModel(
                            name='character-0001',
                            stacking_limit=99,
                            allow_multiple_stacks=False,
                            sort_value=1,
                            options=inventory.ItemModelOptions(
                                metadata='CHARACTER_0001',
                            ),
                        ),
                        inventory.ItemModel(
                            name='character-0002',
                            stacking_limit=49,
                            allow_multiple_stacks=True,
                            sort_value=2,
                            options=inventory.ItemModelOptions(
                                metadata='CHARACTER_0002',
                            ),
                        ),
                        inventory.ItemModel(
                            name='character-0003',
                            stacking_limit=9,
                            allow_multiple_stacks=False,
                            sort_value=3,
                            options=inventory.ItemModelOptions(
                                metadata='CHARACTER_0003',
                            ),
                        ),
                    ],
                    options=inventory.InventoryModelOptions(
                        metadata = 'INVENTORY_CHARACTER'
                    ),
                ),
            ],
            simple_inventory_models=[
                inventory.SimpleInventoryModel(
                    name='item',
                    simple_item_models=[
                        inventory.SimpleItemModel(
                            name='item-0001',
                            options=inventory.SimpleItemModelOptions(
                                metadata='ITEM_0001',
                            ),
                        ),
                        inventory.SimpleItemModel(
                            name='item-0002',
                            options=inventory.SimpleItemModelOptions(
                                metadata='ITEM_0002',
                            ),
                        ),
                        inventory.SimpleItemModel(
                            name='item-0003',
                            options=inventory.SimpleItemModelOptions(
                                metadata='ITEM_0003',
                            ),
                        ),
                    ],
                    options=inventory.SimpleInventoryModelOptions(
                        metadata = 'INVENTORY_ITEM'
                    ),
                ),
            ],
            big_inventory_models=[
                inventory.BigInventoryModel(
                    name='item',
                    big_item_models=[
                        inventory.BigItemModel(
                            name='item-0001',
                            options=inventory.BigItemModelOptions(
                                metadata='ITEM_0001',
                            ),
                        ),
                        inventory.BigItemModel(
                            name='item-0002',
                            options=inventory.BigItemModelOptions(
                                metadata='ITEM_0002',
                            ),
                        ),
                        inventory.BigItemModel(
                            name='item-0003',
                            options=inventory.BigItemModelOptions(
                                metadata='ITEM_0003',
                            ),
                        ),
                    ],
                    options=inventory.BigInventoryModelOptions(
                        metadata = 'INVENTORY_ITEM'
                    ),
                ),
            ],
        )

print(SampleStack().yaml())  # Generate Template

InventoryModel

Inventory Model

Inventory is like a bag that stores items owned by game players. Inventory can have a set capacity and cannot be owned beyond its capacity.

TypeConditionRequiredDefaultValue LimitsDescription
inventoryModelIdstring
*
~ 1024 charsInventory Model GRN
* Set automatically by the server
namestring
~ 128 charsInventory Model name
Inventory Model-specific name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
initialCapacityint
0 ~ 2147483646Initial Capacity
The number of inventory slots available to a user when the inventory is first created. Each slot can hold one item stack. Users can expand their capacity up to maxCapacity through gameplay actions.
maxCapacityint
0 ~ 2147483646Maximum Capacity
The upper limit of inventory slots that a user can expand to. Capacity cannot be increased beyond this value. When all slots are occupied and items cannot be stacked further, acquisition attempts will fail unless the overflow script handles the excess.
protectReferencedItembool?falseProtect Referenced Items
When enabled, item sets that have references registered (via the referenceOf mechanism) cannot be consumed or deleted. This prevents items that are in use by other systems (e.g., equipped gear, items bound to formations) from being accidentally removed.
itemModelsList<ItemModel>[]1 ~ 1000 itemsList of Item Models
The item types that can be stored in this inventory. Each item model defines the stacking and acquisition behavior for one type of item. Up to 1000 item models per inventory model.

ItemModel

Item Model

Items can be held in groups within a single inventory slot, such as Potion ×99. This grouping of multiple items into one slot is called “stacking,” and a maximum stack size can be set for each item.

The behavior when the stack limit is reached can also be set for each item. Specifically, you can choose one of the following:

  • Add a new inventory slot to allow further acquisition
  • Prevent further acquisition once the limit is reached
TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
*
~ 1024 charsItem Model GRN
* Set automatically by the server
namestring
~ 128 charsItem Model name
Item Model-specific name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
GS2-Enhance features a mechanism that works in conjunction with GS2-Inventory to perform enhancements. It sets the experience value when used as enhancement material in JSON format within the ItemModel metadata.
Details are explained in the Microservices Introduction / GS2-Enhance section.
stackingLimitlong
1 ~ 9223372036854775805Maximum Stackable Quantity
The maximum number of this item that can be held in a single inventory slot (stack). When this limit is reached, the behavior depends on the allowMultipleStacks setting: either a new slot is allocated or further acquisition is blocked.
allowMultipleStacksbool
Allow Multiple Stacks
When enabled, if the stacking limit is reached, a new inventory slot is automatically allocated to store additional quantities of this item (consuming additional capacity). When disabled, acquisition is blocked once the stacking limit is reached in the existing slot.
sortValueint
0 ~ 2147483646Display Order
A numeric value used to sort items within the inventory for display purposes. Lower values are displayed first. This value is also copied to ItemSet records to enable consistent ordering of possessed items.

SimpleInventoryModel

Simple Inventory Model

In a normal InventoryModel, you could limit the amount of items that could be stored in your inventory. Simple Inventory, however, has no such functionality and simply stores the number of items in the inventory.

However, the Simple Inventory provides APIs that allow increasing or decreasing multiple items in a single operation.

TypeConditionRequiredDefaultValue LimitsDescription
inventoryModelIdstring
*
~ 1024 charsSimple Inventory Model GRN
* Set automatically by the server
namestring
~ 128 charsSimple Inventory Model name
Simple Inventory Model-specific name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
simpleItemModelsList<SimpleItemModel>[]1 ~ 1000 itemsList of Simple Item Models
The item types that can be stored in this simple inventory. Unlike standard inventory, simple items have no stacking limits or capacity constraints. Up to 1000 item models per simple inventory model.

SimpleItemModel

Simple Item Model

ItemModel allowed setting a maximum stackable quantity, enabling implementation where items exceeding a certain number could be split into multiple stacks. SimpleItem does not have such a function and simply stores the number of items in the possession of the item.

TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
*
~ 1024 charsSimple Item Model GRN
* Set automatically by the server
namestring
~ 128 charsSimple Item Model name
Simple Item Model-specific name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.

BigInventoryModel

Big Inventory Model

In the normal InventoryModel and SimpleInventoryModel, the number of items that can be stored in the inventory is limited to the range of int64. In inflationary games, you may need a wider range of values.

In the Big Inventory Model, the number of items that can be stored in the inventory can have an integer value of 1024 digits.

TypeConditionRequiredDefaultValue LimitsDescription
inventoryModelIdstring
*
~ 1024 charsBig Inventory Model GRN
* Set automatically by the server
namestring
~ 128 charsBig Inventory Model name
Big Inventory Model-specific name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
bigItemModelsList<BigItemModel>[]1 ~ 1000 itemsList of Big Item Models
The item types that can be stored in this big inventory. Each big item model can hold quantities represented as integer strings up to 1024 digits. Up to 1000 item models per big inventory model.

BigItemModel

Big Item Model

The Big Item Model defines items stored in a Big Inventory Model. Big Items can hold quantities that exceed the range of int64.

TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
*
~ 1024 charsBig Item Model GRN
* Set automatically by the server
namestring
~ 128 charsBig Item Model name
Big Item Model-specific name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.