GS2-SerialKey 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 managed 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
Unique Namespace name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
descriptionstring~ 1024 charsDescription
transactionSettingV2TransactionSettingV2Transaction Setting (V2)
Decides how the transactions this Namespace issues are executed. There are only two things to set: the GS2-Distributor Namespace that executes them, and whether the actions in a transaction run one at a time – so that a later action can build on what an earlier one wrote – or all at once for a shorter response time.
Set this on a new Namespace. transactionSetting, the obsolete setting it replaces, is used only while this is unset.
logSettingLogSettingLog Output Setting
Specifies the GS2-Log Namespace for outputting API request/response logs related to serial code issuance and usage.

GetAttr

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

TypeDescription
ItemNamespaceNamespace created

Implementation Example

Type: GS2::SerialKey::Namespace
Properties:
  Name: namespace-0001
  Description: null
  TransactionSettingV2: 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/serialKey"
)


SampleStack := core.NewStack()
serialKey.NewNamespace(
    &SampleStack,
    "namespace-0001",
    serialKey.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\SerialKey\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\SerialKey\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.serialKey.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.serialKey.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.Gs2SerialKey.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2SerialKey.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 serialKey from "@/gs2cdk/serialKey";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new serialKey.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, serial_key

class SampleStack(Stack):

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

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

TransactionSettingV2

Transaction Setting (V2)

Transaction Setting (V2) decides how the transactions issued by a Namespace are executed.

There are only two things to set:

  • distributorNamespaceId: the GS2-Distributor Namespace used to execute the transaction
  • enableParallelExecution: whether the actions in a transaction run one at a time or all at once

Whichever you choose, the transaction is executed by the server the moment it is issued, and it succeeds or fails as a whole: when an action fails, the actions that already ran are undone with it and nothing is left applied. Everything else about how a transaction runs is fixed to the recommended configuration, so there is nothing else to set.

Running the actions one at a time (the default, enableParallelExecution is false) lets each action work on top of what the actions before it wrote. The actions run in verify, consume, acquire order, and this is what lets you:

  • update the same row from more than one action in a single transaction, which fails when they run all at once
  • read what an earlier action wrote, including from List and Query and from inside a nested transaction
  • use %{Gs2Xxx:ActionName.path[0].field} to feed the result of an earlier verify or consume action into the parameters of a later verify, consume or acquire action

In exchange, the response time is the sum of the time taken by each action, and a transaction may contain at most 20 actions. The order within each phase is decided by the action name and then by the target resource, so you cannot choose the execution order by rearranging the actions in the request, and execution stops at the first action that fails.

Running the actions all at once (enableParallelExecution is true) executes them in parallel against a single snapshot of the data, so the response time is that of the slowest single action and there is no limit on the number of actions.

In exchange, an action cannot see what the other actions wrote, and two actions that write the same row fail the transaction with database:transaction:same.resource (400), so choose this only when you can guarantee that no two actions in the same transaction write the same data. %{...} may reference only the results of an earlier phase (verify, then consume, then acquire); a reference to an action in the same phase is left unresolved, and a phase that contains %{...} waits for the earlier phases to complete, which lengthens the response time by that amount.

Transaction Setting is the obsolete setting that Transaction Setting (V2) replaces, kept for Namespaces created before Transaction Setting (V2) existed. It applies only while Transaction Setting (V2) is unset, and setting Transaction Setting (V2) supersedes it. Three behaviours it allowed are deliberately not offered here: executing a transaction as a client-run stamp sheet, running AutoRun asynchronously via GS2-Distributor, and folding acquire actions into GS2-JobQueue.

TypeConditionRequiredDefaultValue LimitsDescription
distributorNamespaceIdstring“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024 charsGS2-Distributor Namespace GRN used to execute transactions
enableParallelExecutionboolfalseWhether to execute the actions in parallel instead of sequentially

LogSetting

Log Output Setting

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:”.

TransactionSetting

Transaction Setting

Transaction Setting is obsolete: Transaction Setting (V2) replaces it. It is kept for Namespaces created before Transaction Setting (V2) existed, applies only while Transaction Setting (V2) is unset, and should not be chosen for a new Namespace.

It exposes each part of transaction execution as a separate field – AutoRun, AtomicCommit, asynchronous execution using GS2-Distributor, batch application of script results, asynchronous processing of acquire actions via GS2-JobQueue, and sequential execution – so combinations other than the recommended one can be built. Transaction Setting (V2) is that recommended combination expressed as a single setting. Keep using Transaction Setting only on a Namespace that already depends on a behaviour Transaction Setting (V2) does not offer: executing a transaction as a client-run stamp sheet, running AutoRun asynchronously via GS2-Distributor, or folding acquire actions into GS2-JobQueue.

TypeConditionRequiredDefaultValue LimitsDescription
enableAutoRunboolfalseWhether to automatically execute issued transactions on the server side
enableAtomicCommitbool{enableAutoRun} == truefalseWhether to commit transactions atomically
* Enabled only if enableAutoRun is true
transactionUseDistributorbool{enableAtomicCommit} == truefalseWhether to execute transactions asynchronously
* Enabled only if enableAtomicCommit is true
commitScriptResultInUseDistributorbool{transactionUseDistributor} == truefalseWhether to execute the commit processing of the script result asynchronously
* Enabled only if transactionUseDistributor is true
acquireActionUseJobQueuebool{enableAtomicCommit} == truefalseWhether to use GS2-JobQueue to execute the acquire action
* Enabled only if enableAtomicCommit is true
enableSequentialExecutionbool{enableAtomicCommit} == truefalseWhether to execute the actions of an atomic commit sequentially so that multiple actions may update the same row
* Enabled 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

CurrentCampaignMaster

Currently active Campaign Model master data

This master data defines the Campaign Models currently active within the Namespace. GS2 uses JSON format files for managing master data. By uploading these files, you can apply the master data to 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
Unique Namespace name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
modestring (enum)
enum {
  “direct”,
  “preUpload”
}
“direct”Update mode
DefinitionDescription
directDirectly update the master data
preUploadUpload master data and then update
settingsstring{mode} == “direct”
✓*
~ 5242880 bytes (5MB)Master 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
ItemCurrentCampaignMasterUpdated master data of the currently active Campaign Models

Implementation Example

Type: GS2::SerialKey::CurrentCampaignMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2022-09-13",
    "campaignModels": [
      {
        "name": "campaign-0001",
        "enableCampaignCode": true,
        "metadata": "CAMPAIGN_0001"
      }
    ]
  }
  UploadToken: null
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/serialKey"
    "github.com/openlyinc/pointy"
)


SampleStack := core.NewStack()
serialKey.NewNamespace(
    &SampleStack,
    "namespace-0001",
    serialKey.NamespaceOptions{},
).MasterData(
    []serialKey.CampaignModel{
        serialKey.NewCampaignModel(
            "campaign-0001",
            true,
            serialKey.CampaignModelOptions{
                Metadata: pointy.String("CAMPAIGN_0001"),
            },
        ),
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\SerialKey\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\SerialKey\Model\CampaignModel(
                    name:"campaign-0001",
                    enableCampaignCode:true,
                    options: new \Gs2Cdk\SerialKey\Model\Options\CampaignModelOptions(
                        metadata:"CAMPAIGN_0001"
                    )
                )
            ]
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.serialKey.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.serialKey.model.CampaignModel(
                    "campaign-0001",
                    true,
                    new io.gs2.cdk.serialKey.model.options.CampaignModelOptions()
                        .withMetadata("CAMPAIGN_0001")
                )
            )
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2SerialKey.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2SerialKey.Model.CampaignModel[] {
                new Gs2Cdk.Gs2SerialKey.Model.CampaignModel(
                    name: "campaign-0001",
                    enableCampaignCode: true,
                    options: new Gs2Cdk.Gs2SerialKey.Model.Options.CampaignModelOptions
                    {
                        metadata = "CAMPAIGN_0001"
                    }
                )
            }
        );
    }
}

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

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new serialKey.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new serialKey.model.CampaignModel(
                    "campaign-0001",
                    true,
                    {
                        metadata: "CAMPAIGN_0001"
                    }
                )
            ]
        );
    }
}

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

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        serial_key.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            campaign_models=[
                serial_key.CampaignModel(
                    name='campaign-0001',
                    enable_campaign_code=True,
                    options=serial_key.CampaignModelOptions(
                        metadata = 'CAMPAIGN_0001'
                    ),
                ),
            ],
        )

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

CampaignModel

Campaign Model

A Campaign Model is used to define and manage campaigns, linking them to serial codes.

TypeConditionRequiredDefaultValue LimitsDescription
campaignIdstring
*
~ 1024 charsGRN of the Campaign Model
* Set automatically by the server
namestring
~ 128 charsCampaign Model name
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.
enableCampaignCodeboolfalseWhether to allow redemption with campaign code
When enabled, users can redeem rewards using a shared campaign code (the campaign name) instead of individual serial codes. This allows a single code to be used by multiple users.