GS2-Enhance GS2-Deploy/CDK リファレンス

GS2-Deployのスタックの作成に使用するテンプレートのフォーマットと、CDKによる各種言語のテンプレート出力の実装例

エンティティ

Namespace

ネームスペース

ネームスペースは一つのプロジェクトで同じサービスを異なる用途で複数利用できるようにするための仕組みです。
GS2 のサービスは基本的にネームスペースというレイヤーがあり、ネームスペースが異なれば同じサービスでもまったく別のデータ空間として取り扱われます。

そのため、各サービスの利用を開始するにあたってネームスペースを作成する必要があります。

必須デフォルト値の制限説明
namestring~ 128文字ネームスペース名
descriptionstring~ 1024文字説明文
transactionSettingTransactionSettingトランザクション設定
enhanceScriptScriptSetting強化時に実行するスクリプト
logSettingLogSettingログの出力設定

GetAttr

説明
ItemNamespace作成したネームスペース

実装例

Type: GS2::Enhance::Namespace Properties: Name: namespace-0001 Description: null TransactionSetting: EnableAutoRun: true QueueNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-0001 KeyId: grn:gs2:ap-northeast-1:YourOwnerId:key:namespace-0001:key:key-0001 EnhanceScript: 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/enhance" "github.com/openlyinc/pointy" ) SampleStack := core.NewStack() enhance.NewNamespace( &SampleStack, "namespace-0001", enhance.NamespaceOptions{ TransactionSetting: core.NewTransactionSetting( core.TransactionSettingOptions{ QueueNamespaceId: pointy.String("grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-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\Enhance\Model\Namespace_( stack: $this, name: "namespace-0001", options: new \Gs2Cdk\Enhance\Model\Options\NamespaceOptions( transactionSetting: new \Gs2Cdk\Core\Model\TransactionSetting( new \Gs2Cdk\Core\Model\TransactionSettingOptions( queueNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-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.enhance.model.Namespace( this, "namespace-0001", new io.gs2.cdk.enhance.model.options.NamespaceOptions() .withTransactionSetting(new io.gs2.cdk.core.model.TransactionSetting( new io.gs2.cdk.core.model.options.TransactionSettingOptions() .withQueueNamespaceId("grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-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.Gs2Enhance.Model.Namespace( stack: this, name: "namespace-0001", options: new Gs2Cdk.Gs2Enhance.Model.Options.NamespaceOptions { transactionSetting = new Gs2Cdk.Core.Model.TransactionSetting( options: new Gs2Cdk.Core.Model.TransactionSettingOptions { queueNamespaceId = "grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-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 enhance from "@/gs2cdk/enhance"; class SampleStack extends core.Stack { public constructor() { super(); new enhance.model.Namespace( this, "namespace-0001", { transactionSetting: new core.TransactionSetting( { queueNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-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, enhance class SampleStack(Stack): def __init__(self): super().__init__() enhance.Namespace( stack=self, name='namespace-0001', options=enhance.NamespaceOptions( transaction_setting=core.TransactionSetting( options=core.TransactionSettingOptions( queue_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:queue:queue-0001', ) ), log_setting=core.LogSetting( logging_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001', ), ), ) print(SampleStack().yaml()) # Generate Template

CurrentRateMaster

現在有効な強化レートマスター

GS2ではマスターデータの管理にJSON形式のファイルを使用します。
ファイルをアップロードすることで、実際にサーバーに設定を反映することができます。

JSONファイルを作成する方法として、マネージメントコンソール上でのマスターデータエディタを提供していますが
よりゲームの運営に相応しいツールを作成し、適切なフォーマットのJSONファイルを書き出すことでもサービスを利用可能です。

必須デフォルト値の制限説明
namespaceNamestring~ 128文字ネームスペース名
settingsstring~ 5242880文字マスターデータ

GetAttr

説明
ItemCurrentRateMaster更新した現在有効な強化レート設定

実装例

Type: GS2::Enhance::CurrentRateMaster Properties: NamespaceName: namespace-0001 Settings: { "version": "2020-08-22", "rateModels": [ { "name": "character-friendly", "targetInventoryModelId": "grn:inventory:character", "acquireExperienceSuffix": ":friendly", "materialInventoryModelId": "grn:inventory:sweet", "experienceModelId": "grn:experience:friendly", "metadata": "CHARACTER_FRIENDLY", "acquireExperienceHierarchy": [ "taste" ], "bonusRates": [ { "rate": 1, "weight": 90 } ] }, { "name": "character-level", "targetInventoryModelId": "grn:inventory:character", "acquireExperienceSuffix": ":level", "materialInventoryModelId": "grn:inventory:material", "experienceModelId": "grn:experience:level", "metadata": "CHARACTER_LEVEL", "acquireExperienceHierarchy": [ "experience" ], "bonusRates": [ { "rate": 1, "weight": 90 }, { "rate": 1.5, "weight": 9 }, { "rate": 2, "weight": 1 } ] } ], "unleashRateModels": [ ] }
import ( "github.com/gs2io/gs2-golang-cdk/core" "github.com/gs2io/gs2-golang-cdk/enhance" "github.com/openlyinc/pointy" ) SampleStack := core.NewStack() enhance.NewNamespace( &SampleStack, "namespace-0001", enhance.NamespaceOptions{}, ).MasterData( []enhance.RateModel{ enhance.NewRateModel( "character-friendly", "grn:inventory:character", ":friendly", "grn:inventory:sweet", "grn:experience:friendly", enhance.RateModelOptions{ Metadata: pointy.String("CHARACTER_FRIENDLY"), AcquireExperienceHierarchy: []string{ "taste", }, BonusRates: []enhance.BonusRate{ enhance.NewBonusRate( 1, 90, enhance.BonusRateOptions{}, ), }, }, ), enhance.NewRateModel( "character-level", "grn:inventory:character", ":level", "grn:inventory:material", "grn:experience:level", enhance.RateModelOptions{ Metadata: pointy.String("CHARACTER_LEVEL"), AcquireExperienceHierarchy: []string{ "experience", }, BonusRates: []enhance.BonusRate{ enhance.NewBonusRate( 1, 90, enhance.BonusRateOptions{}, ), enhance.NewBonusRate( 1.5, 9, enhance.BonusRateOptions{}, ), enhance.NewBonusRate( 2, 1, enhance.BonusRateOptions{}, ), }, }, ), }, []enhance.UnleashRateModel{ }, ) println(SampleStack.Yaml()) // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack { function __construct() { parent::__construct(); (new \Gs2Cdk\Enhance\Model\Namespace_( stack: $this, name: "namespace-0001" ))->masterData( [ new \Gs2Cdk\Enhance\Model\RateModel( name:"character-friendly", targetInventoryModelId:"grn:inventory:character", acquireExperienceSuffix:":friendly", materialInventoryModelId:"grn:inventory:sweet", experienceModelId:"grn:experience:friendly", options: new \Gs2Cdk\Enhance\Model\Options\RateModelOptions( metadata:"CHARACTER_FRIENDLY", acquireExperienceHierarchy:[ "taste", ], bonusRates:[ new \Gs2Cdk\Enhance\Model\BonusRate( rate: 1, weight: 90, ), ] ) ), new \Gs2Cdk\Enhance\Model\RateModel( name:"character-level", targetInventoryModelId:"grn:inventory:character", acquireExperienceSuffix:":level", materialInventoryModelId:"grn:inventory:material", experienceModelId:"grn:experience:level", options: new \Gs2Cdk\Enhance\Model\Options\RateModelOptions( metadata:"CHARACTER_LEVEL", acquireExperienceHierarchy:[ "experience", ], bonusRates:[ new \Gs2Cdk\Enhance\Model\BonusRate( rate: 1, weight: 90, ), new \Gs2Cdk\Enhance\Model\BonusRate( rate: 1.5, weight: 9, ), new \Gs2Cdk\Enhance\Model\BonusRate( rate: 2, weight: 1, ), ] ) ) ], [ ] ); } } print((new SampleStack())->yaml()); // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack { public SampleStack() { super(); new io.gs2.cdk.enhance.model.Namespace( this, "namespace-0001" ).masterData( Arrays.asList( new io.gs2.cdk.enhance.model.RateModel( "character-friendly", "grn:inventory:character", ":friendly", "grn:inventory:sweet", "grn:experience:friendly", new io.gs2.cdk.enhance.model.options.RateModelOptions() .withMetadata("CHARACTER_FRIENDLY") .withAcquireExperienceHierarchy(Arrays.asList( "taste" )) .withBonusRates(Arrays.asList( new io.gs2.cdk.enhance.model.BonusRate( 1f, 90 ) )) ), new io.gs2.cdk.enhance.model.RateModel( "character-level", "grn:inventory:character", ":level", "grn:inventory:material", "grn:experience:level", new io.gs2.cdk.enhance.model.options.RateModelOptions() .withMetadata("CHARACTER_LEVEL") .withAcquireExperienceHierarchy(Arrays.asList( "experience" )) .withBonusRates(Arrays.asList( new io.gs2.cdk.enhance.model.BonusRate( 1f, 90 ), new io.gs2.cdk.enhance.model.BonusRate( 1.5f, 9 ), new io.gs2.cdk.enhance.model.BonusRate( 2f, 1 ) )) ) ), Arrays.asList( ) ); } } System.out.println(new SampleStack().yaml()); // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack { public SampleStack() { new Gs2Cdk.Gs2Enhance.Model.Namespace( stack: this, name: "namespace-0001" ).MasterData( new Gs2Cdk.Gs2Enhance.Model.RateModel[] { new Gs2Cdk.Gs2Enhance.Model.RateModel( name: "character-friendly", targetInventoryModelId: "grn:inventory:character", acquireExperienceSuffix: ":friendly", materialInventoryModelId: "grn:inventory:sweet", experienceModelId: "grn:experience:friendly", options: new Gs2Cdk.Gs2Enhance.Model.Options.RateModelOptions { metadata = "CHARACTER_FRIENDLY", acquireExperienceHierarchy = new string[] { "taste" }, bonusRates = new Gs2Cdk.Gs2Enhance.Model.BonusRate[] { new Gs2Cdk.Gs2Enhance.Model.BonusRate( rate: 1f, weight: 90 ) } } ), new Gs2Cdk.Gs2Enhance.Model.RateModel( name: "character-level", targetInventoryModelId: "grn:inventory:character", acquireExperienceSuffix: ":level", materialInventoryModelId: "grn:inventory:material", experienceModelId: "grn:experience:level", options: new Gs2Cdk.Gs2Enhance.Model.Options.RateModelOptions { metadata = "CHARACTER_LEVEL", acquireExperienceHierarchy = new string[] { "experience" }, bonusRates = new Gs2Cdk.Gs2Enhance.Model.BonusRate[] { new Gs2Cdk.Gs2Enhance.Model.BonusRate( rate: 1f, weight: 90 ), new Gs2Cdk.Gs2Enhance.Model.BonusRate( rate: 1.5f, weight: 9 ), new Gs2Cdk.Gs2Enhance.Model.BonusRate( rate: 2f, weight: 1 ) } } ) }, new Gs2Cdk.Gs2Enhance.Model.UnleashRateModel[] { } ); } } Debug.Log(new SampleStack().Yaml()); // Generate Template
import core from "@/gs2cdk/core"; import enhance from "@/gs2cdk/enhance"; class SampleStack extends core.Stack { public constructor() { super(); new enhance.model.Namespace( this, "namespace-0001", ).masterData( [ new enhance.model.RateModel( "character-friendly", "grn:inventory:character", ":friendly", "grn:inventory:sweet", "grn:experience:friendly", { metadata: "CHARACTER_FRIENDLY", acquireExperienceHierarchy: [ "taste", ], bonusRates: [ new enhance.model.BonusRate( 1, 90 ), ] } ), new enhance.model.RateModel( "character-level", "grn:inventory:character", ":level", "grn:inventory:material", "grn:experience:level", { metadata: "CHARACTER_LEVEL", acquireExperienceHierarchy: [ "experience", ], bonusRates: [ new enhance.model.BonusRate( 1, 90 ), new enhance.model.BonusRate( 1.5, 9 ), new enhance.model.BonusRate( 2, 1 ), ] } ) ], [ ] ); } } console.log(new SampleStack().yaml()); // Generate Template
from gs2_cdk import Stack, core, enhance class SampleStack(Stack): def __init__(self): super().__init__() enhance.Namespace( stack=self, name="namespace-0001", ).master_data( rate_models=[ enhance.RateModel( name='character-friendly', target_inventory_model_id='grn:inventory:character', acquire_experience_suffix=':friendly', material_inventory_model_id='grn:inventory:sweet', experience_model_id='grn:experience:friendly', options=enhance.RateModelOptions( metadata = 'CHARACTER_FRIENDLY', acquire_experience_hierarchy = [ 'taste', ], bonus_rates = [ enhance.BonusRate( rate=1, weight=90, ), ] ), ), enhance.RateModel( name='character-level', target_inventory_model_id='grn:inventory:character', acquire_experience_suffix=':level', material_inventory_model_id='grn:inventory:material', experience_model_id='grn:experience:level', options=enhance.RateModelOptions( metadata = 'CHARACTER_LEVEL', acquire_experience_hierarchy = [ 'experience', ], bonus_rates = [ enhance.BonusRate( rate=1, weight=90, ), enhance.BonusRate( rate=1.5, weight=9, ), enhance.BonusRate( rate=2, weight=1, ), ] ), ), ], unleash_rate_models=[ ], ) print(SampleStack().yaml()) # Generate Template

BonusRate

経験値獲得量ボーナス

必須デフォルト値の制限説明
ratefloat1.0~ 10000経験値ボーナスの倍率(1.0=ボーナスなし)
weightint1~ 2147483645抽選重み

Material

強化素材

必須デフォルト値の制限説明
materialItemSetIdstring~ 1024文字強化の素材となるアイテムセット(有効期限ごとのアイテム所持数量)のGRN
countint1~ 2147483645消費数量

UnleashRateEntryModel

限界突破レートエントリモデル

必須デフォルト値の制限説明
gradeValuelong1 ~ 1000対象グレード
needCountint1 ~ 1000同種のアイテムを何個消費するか

Config

コンフィグ設定

トランザクションの変数に適用する設定値

必須デフォルト値の制限説明
keystring~ 64文字名前
valuestring~ 51200文字

VerifyActionResult

検証アクションの実行結果

必須デフォルト値の制限説明
actionenum {
}
~ 128文字検証アクションで実行するアクションの種類
verifyRequeststring~ 1048576文字リクエストのJSON
statusCodeint~ 999ステータスコード
verifyResultstring~ 1048576文字結果内容

action に指定する列挙型の定義

定義説明

ConsumeActionResult

消費アクションの実行結果

必須デフォルト値の制限説明
actionenum {
}
~ 128文字消費アクションで実行するアクションの種類
consumeRequeststring~ 1048576文字リクエストのJSON
statusCodeint~ 999ステータスコード
consumeResultstring~ 1048576文字結果内容

action に指定する列挙型の定義

定義説明

AcquireActionResult

入手アクションの実行結果

必須デフォルト値の制限説明
actionenum {
}
~ 128文字入手アクションで実行するアクションの種類
acquireRequeststring~ 1048576文字リクエストのJSON
statusCodeint~ 999ステータスコード
acquireResultstring~ 1048576文字結果内容

action に指定する列挙型の定義

定義説明

TransactionResult

トランザクション実行結果

サーバーサイドでのトランザクションの自動実行機能を利用して実行されたトランザクションの実行結果

必須デフォルト値の制限説明
transactionIdstring36 ~ 36文字トランザクションID
verifyResultsList<VerifyActionResult>~ 10 items検証アクションの実行結果リスト
consumeResultsList<ConsumeActionResult>[]~ 10 items消費アクションの実行結果リスト
acquireResultsList<AcquireActionResult>[]~ 100 items入手アクションの実行結果リスト

GitHubCheckoutSetting

GitHubからマスターデータをチェックアウトする設定

必須デフォルト値の制限説明
apiKeyIdstring~ 1024文字GitHub のAPIキーGRN
repositoryNamestring~ 1024文字リポジトリ名
sourcePathstring~ 1024文字ソースコードのファイルパス
referenceTypeenum {
    “commit_hash”,
    “branch”,
    “tag”
}
~ 128文字コードの取得元
commitHashstring{referenceType} == “commit_hash”~ 1024文字コミットハッシュ
branchNamestring{referenceType} == “branch”~ 1024文字ブランチ名
tagNamestring{referenceType} == “tag”~ 1024文字タグ名

referenceType に指定する列挙型の定義

定義説明
commit_hashコミットハッシュ
branchブランチ
tagタグ

ScriptSetting

スクリプト設定

GS2 ではマイクロサービスのイベントに関連づけて、カスタムスクリプトを実行することができます。
このモデルは、スクリプトの実行をトリガーするための設定を保持します。

スクリプトの実行方式は大きく2種類あり、それは「同期実行」と「非同期実行」です。
同期実行は、スクリプトの実行が完了するまで処理がブロックされます。
かわりに、スクリプトの実行結果を使ってAPIの実行を止めたり、APIの結果を改ざんすることができます。

一方、非同期実行は、スクリプトの実行が完了するまで処理がブロックされません。
かわりに、スクリプトの実行結果を使ってAPIの実行を止めたり、APIの結果を改ざんすることはできません。
しかし、非同期実行は、スクリプトの実行が完了するまで処理がブロックされないため、APIの応答に影響を与えないため、原則非同期実行を使用することをおすすめします。

非同期実行には実行方式が2種類あり、GS2-Script と Amazon EventBridge があります。
Amazon EventBridge を使用することで、Lua 以外の言語で処理を記述することができます。

必須デフォルト値の制限説明
triggerScriptIdstring~ 1024文字スクリプトGRN
doneTriggerTargetTypeenum {
    “none”,
    “gs2_script”,
    “aws”
}
“none”~ 128文字完了通知の通知先
doneTriggerScriptIdstring{doneTriggerTargetType} == “gs2_script”~ 1024文字スクリプトGRN
doneTriggerQueueNamespaceIdstring{doneTriggerTargetType} == “gs2_script”~ 1024文字ネームスペースGRN

doneTriggerTargetType に指定する列挙型の定義

定義説明
noneなし
gs2_scriptGS2-Script
awsAmazon EventBridge

LogSetting

ログの書き出し設定

ログデータの書き出し設定を管理します。この型は、ログデータを書き出すために使用されるログ名前空間の識別子(Namespace ID)を保持します。
ログ名前空間IDは、ログデータを集約し、保存する対象の GS2-Log の名前空間を指定します。
この設定を通じて、この名前空間以下のAPIリクエスト・レスポンスログデータが対象の GS2-Log へ出力されるようになります。
GS2-Log にはリアルタイムでログが提供され、システムの監視や分析、デバッグなどに利用できます。

必須デフォルト値の制限説明
loggingNamespaceIdstring~ 1024文字ネームスペースGRN

TransactionSetting

トランザクション設定

必須デフォルト値の制限説明
enableAutoRunboolfalse発行したトランザクションをサーバーサイドで自動的に実行するか
enableAtomicCommitbool{enableAutoRun} == truefalseトランザクションの実行をアトミックにコミットするか
transactionUseDistributorbool{enableAtomicCommit} == truefalseトランザクションを非同期処理で実行する
acquireActionUseJobQueuebool{enableAtomicCommit} == truefalse入手アクションを実行する際に GS2-JobQueue を使用するか
distributorNamespaceIdstring“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024文字トランザクションの実行に使用する GS2-Distributor ネームスペース
queueNamespaceIdstring“grn:gs2:{region}:{ownerId}:queue:default”~ 1024文字トランザクションの実行に使用する GS2-JobQueue のネームスペース