Deploy/CDK Reference of GS2-Distributor

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

Entity

Resources operated in Deploy process

Namespace

Namespace

A namespace is a mechanism that allows multiple uses of the same service for different purposes within a single project. 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 generation request

TypeConditionRequiredDefaultValue LimitsDescription
namestring
~ 128 charsNamespace name
Namespace-specific name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
descriptionstring~ 1024 charsDescription
transactionSettingTransactionSettingTransaction settings
assumeUserIdstring~ 1024 charsGS2-Identifier User GRN
autoRunStampSheetNotificationNotificationSetting
Push notification when transaction auto-execution is complete(Old specification)
autoRunTransactionNotificationNotificationSetting
Push notification when transaction auto-execution is complete
logSettingLogSettingLog output settings

GetAttr

Generation results of resources that can be obtained with the !GetAttr tag

TypeDescription
ItemNamespaceThe created Namespace

Implementation Example

Type: GS2::Distributor::Namespace
Properties:
  Name: namespace-0001
  Description: null
  TransactionSetting: null
  AssumeUserId: grn:gs2::YourOwnerId:identifier:user:user-0001
  AutoRunStampSheetNotification: null
  AutoRunTransactionNotification: 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/distributor"
    "github.com/openlyinc/pointy"
)

SampleStack := core.NewStack()
distributor.NewNamespace(
    &SampleStack,
    "namespace-0001",
    distributor.NamespaceOptions{
        AssumeUserId: pointy.String("grn:gs2::YourOwnerId:identifier:user:user-0001"),
        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\Distributor\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Distributor\Model\Options\NamespaceOptions(
                assumeUserId: "grn:gs2::YourOwnerId:identifier:user:user-0001",
                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.distributor.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.distributor.model.options.NamespaceOptions()
                        .withAssumeUserId("grn:gs2::YourOwnerId:identifier:user:user-0001")
                        .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.Gs2Distributor.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2Distributor.Model.Options.NamespaceOptions
            {
                assumeUserId = "grn:gs2::YourOwnerId:identifier:user:user-0001",
                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 distributor from "@/gs2cdk/distributor";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new distributor.model.Namespace(
            this,
            "namespace-0001",
            {
                assumeUserId: "grn:gs2::YourOwnerId:identifier:user:user-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, distributor

class SampleStack(Stack):

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

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

TransactionSetting

Transaction settings

Transaction settings control how transactions are executed, 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 acquisition actions via GS2-JobQueue enables robust transaction management tailored to game logic.

TypeConditionRequiredDefaultValue LimitsDescription
enableAutoRunbool
falseWhether to automatically execute issued transactions on the server side
enableAtomicCommitbool{enableAutoRun} == true
✓*
falseWhether to commit the execution of transactions atomically
* Required if enableAutoRun is true
transactionUseDistributorbool{enableAtomicCommit} == true
✓*
falseWhether to execute transactions asynchronously
* Required if enableAtomicCommit is true
commitScriptResultInUseDistributorbool{transactionUseDistributor} == true
✓*
falseWhether to execute the commit processing of the script result asynchronously
* Required if transactionUseDistributor is true
acquireActionUseJobQueuebool{enableAtomicCommit} == true
✓*
falseWhether to use GS2-JobQueue to execute the acquire action
* Required if enableAtomicCommit is true
distributorNamespaceIdstring
“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024 charsGS2-Distributor namespace GRN used for transaction execution
queueNamespaceIdstring
“grn:gs2:{region}:{ownerId}:queue:default”~ 1024 charsNamespace GRN in GS2-JobQueue used to run the transaction

NotificationSetting

Push notification settings

This is a setting for sending push notifications when an event occurs in a GS2 microservice. The push notification here refers to the processing via the WebSocket interface provided by GS2-Gateway, and is different from the push notification of a smartphone. For example, when a matchmaking is completed or a friend request is received, the GS2-Gateway can send a push notification via the WebSocket interface, and the game client can detect the change of the state.

GS2-Gateway’s push notifications can be used to send additional processing to mobile push notifications when the destination device is offline. If you use mobile push notifications well, you may be able to realize a flow in which you can notify the player by using mobile push notifications even if you end the game during matchmaking and return to the game.

TypeConditionRequiredDefaultValue LimitsDescription
gatewayNamespaceIdstring
“grn:gs2:{region}:{ownerId}:gateway:default”~ 1024 charsGS2-Gateway namespace to use for push notifications
Specify the GS2-Gateway namespace ID in GRN format starting with “grn:gs2:”.
enableTransferMobileNotificationbool?falseForwarding to mobile push notification
When this notification is sent, if the destination device is offline, specify whether to forward it to mobile push notification.
soundstring{enableTransferMobileNotification} == true~ 1024 charsSound file name to be used for mobile push notifications
The sound file name specified here is used when sending mobile push notifications, and you can send notifications with a special sound.

* Enabled if enableTransferMobileNotification is true
enableString Enum
enum {
  “Enabled”,
  “Disabled”
}
“Enabled”Whether to enable push notifications
Enumerator String DefinitionDescription
“Enabled”Enabled
“Disabled”Disabled

LogSetting

Log setting

This type manages log output settings. This type holds the identifier of the log namespace used to output log data. The log namespace ID specifies the GS2-Log namespace to aggregate and store the log data. Through this setting, API request and response log data under this namespace will be output to the target GS2-Log. GS2-Log provides logs in real time, which can be used for system monitoring, analysis, debugging, etc.

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

CurrentDistributorMaster

Currently Active Master Data

Currently active master data describing the Distributor Model definitions 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 operating your game and export JSON files in the appropriate format.

Request

Resource generation request

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
Enumerator String 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

Generation results of resources that can be obtained with the !GetAttr tag

TypeDescription
ItemCurrentDistributorMasterUpdated Currently Active Distributor Model Master Data

Implementation Example

Type: GS2::Distributor::CurrentDistributorMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2019-03-01",
    "distributorModels": [
      {
        "name": "basic",
        "metadata": "BASIC",
        "inboxNamespaceId": "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"
      },
      {
        "name": "special",
        "metadata": "SPECIAL",
        "inboxNamespaceId": "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001",
        "whiteListTargetIds": [
          "test"
        ]
      }
    ]
  }
  UploadToken: null
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/distributor"
    "github.com/openlyinc/pointy"
)

SampleStack := core.NewStack()
distributor.NewNamespace(
    &SampleStack,
    "namespace-0001",
    distributor.NamespaceOptions{},
).MasterData(
    []distributor.DistributorModel{
        distributor.NewDistributorModel(
            "basic",
            distributor.DistributorModelOptions{
                Metadata: pointy.String("BASIC"),
                InboxNamespaceId: pointy.String("grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"),
            },
        ),
        distributor.NewDistributorModel(
            "special",
            distributor.DistributorModelOptions{
                Metadata: pointy.String("SPECIAL"),
                InboxNamespaceId: pointy.String("grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"),
                WhiteListTargetIds: []string{
                    "test",
                },
            },
        ),
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Distributor\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\Distributor\Model\DistributorModel(
                    name:"basic",
                    options: new \Gs2Cdk\Distributor\Model\Options\DistributorModelOptions(
                        metadata:"BASIC",
                        inboxNamespaceId:"grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"
                    )
                ),
                new \Gs2Cdk\Distributor\Model\DistributorModel(
                    name:"special",
                    options: new \Gs2Cdk\Distributor\Model\Options\DistributorModelOptions(
                        metadata:"SPECIAL",
                        inboxNamespaceId:"grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001",
                        whiteListTargetIds:[
                            "test",
                        ]
                    )
                )
            ]
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.distributor.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.distributor.model.DistributorModel(
                    "basic",
                    new io.gs2.cdk.distributor.model.options.DistributorModelOptions()
                        .withMetadata("BASIC")
                        .withInboxNamespaceId("grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001")
                ),
                new io.gs2.cdk.distributor.model.DistributorModel(
                    "special",
                    new io.gs2.cdk.distributor.model.options.DistributorModelOptions()
                        .withMetadata("SPECIAL")
                        .withInboxNamespaceId("grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001")
                        .withWhiteListTargetIds(Arrays.asList(
                            "test"
                        ))
                )
            )
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Distributor.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2Distributor.Model.DistributorModel[] {
                new Gs2Cdk.Gs2Distributor.Model.DistributorModel(
                    name: "basic",
                    options: new Gs2Cdk.Gs2Distributor.Model.Options.DistributorModelOptions
                    {
                        metadata = "BASIC",
                        inboxNamespaceId = "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"
                    }
                ),
                new Gs2Cdk.Gs2Distributor.Model.DistributorModel(
                    name: "special",
                    options: new Gs2Cdk.Gs2Distributor.Model.Options.DistributorModelOptions
                    {
                        metadata = "SPECIAL",
                        inboxNamespaceId = "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001",
                        whiteListTargetIds = new string[]
                        {
                            "test"
                        }
                    }
                )
            }
        );
    }
}

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

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new distributor.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new distributor.model.DistributorModel(
                    "basic",
                    {
                        metadata: "BASIC",
                        inboxNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"
                    }
                ),
                new distributor.model.DistributorModel(
                    "special",
                    {
                        metadata: "SPECIAL",
                        inboxNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001",
                        whiteListTargetIds: [
                            "test",
                        ]
                    }
                )
            ]
        );
    }
}

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

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        distributor.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            distributor_models=[
                distributor.DistributorModel(
                    name='basic',
                    options=distributor.DistributorModelOptions(
                        metadata = 'BASIC',
                        inbox_namespace_id = 'grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001'
                    ),
                ),
                distributor.DistributorModel(
                    name='special',
                    options=distributor.DistributorModelOptions(
                        metadata = 'SPECIAL',
                        inbox_namespace_id = 'grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001',
                        white_list_target_ids = [
                            'test',
                        ]
                    ),
                ),
            ],
        )

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

DistributorModel

Distributor Model

Distributor Model is an entity that sets the policy when an entity’s acquisition exceeds its possession quota. By processing acquisitions through GS2-Distributor, overflow resources can be forwarded as GS2-Inbox messages.

TypeConditionRequiredDefaultValue LimitsDescription
distributorModelIdstring
✓*
~ 1024 charsDistributor Model GRN
* Automatically configured on the server
namestring
~ 128 charsDistributor Model name
Distributor 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.
inboxNamespaceIdstring~ 1024 charsGS2-Inbox namespace GRN to transfer overflow resources
whiteListTargetIdsList<string>[]0 ~ 1000 itemsWhitelist of target resources GRN that can be processed through GS2-Distributor
Specify the GRN prefix of the target resources that can be processed for acquisition using this Distributor Model.