Setup using GS2-CDK
GS2-Deploy did a great job of setting up the environment. However, there was still a challenge in writing templates. That is, you cannot get any input help to write a template file.
I have already explained that I used AWS’ Cloud Formation as a reference to design GS2-Deploy, but In 2019, AWS announced the AWS CDK (Cloud Development Kit).
This was the result of an effort to enable template writing in various programming languages, as a solution to the problem of not getting input support for writing template files in traditional JSON or YAML.
Since its launch in 2019, GS2 has always provided the ability to deploy templates in JSON/YAML, and in November 2022, GS2 began supporting CDK as well. CDK currently supports Go / Java / PHP / Python / TypeScript.
Below is an example of code written in each of these programming languages to generate a template for GS2-Inventory’s GS2-Deploy.
stack := core.NewStack()
inventory.NewNamespace(
&stack,
"test",
inventory.NamespaceOptions{
},
).MasterData(
[]inventory.InventoryModel{
inventory.NewInventoryModel(
"inventory",
5,
10,
[]inventory.ItemModel{
inventory.NewItemModel(
"Potion",
99,
true,
1,
inventory.ItemModelOptions{},
),
},
inventory.InventoryModelOptions{},
),
},
)
stack.Yaml();
class SampleStack extends Stack {
public SampleStack() {
new io.gs2.cdk.inventory.model.Namespace(
this,
"test",
new io.gs2.cdk.inventory.model.options.NamespaceOptions()
).masterData(
Arrays.asList(
new io.gs2.cdk.inventory.model.InventoryModel(
"inventory",
5,
10,
Arrays.asList(
new io.gs2.cdk.inventory.model.ItemModel(
"Potion",
99L,
true,
1
)
)
)
)
);
}
}
new SampleStack().yaml();
class SampleStack extends Stack {
function __construct() {
parent::__construct();
(new \Gs2Cdk\Inventory\Model\Namespace_(
stack: $this,
name: "test",
))->masterData(
[
new \Gs2Cdk\Inventory\Model\InventoryModel(
name: "inventory",
initialCapacity: 5,
maxCapacity: 10,
itemModels: [
new \Gs2Cdk\Inventory\Model\ItemModel(
name: "Potion",
stackingLimit: 99,
allowMultipleStacks: true,
sortValue: 1,
)
],
),
],
);
}
}
(new SampleStack())->yaml();
class SampleStack(gs2_cdk.Stack):
def __init__(self):
super().__init__()
inventory.Namespace(
stack=self,
name="test",
).master_data(
[
inventory.InventoryModel(
name="inventory",
initial_capacity=5,
max_capacity=10,
item_models=[
inventory.ItemModel(
name="Potion",
stacking_limit=99,
allow_multiple_stacks=True,
sort_value=1,
),
],
),
]
)
SampleStack().yaml()
class SampleStack extends core.Stack {
public constructor() {
super();
new inventory.model.Namespace(
this,
"test",
).masterData(
[
new inventory.model.InventoryModel(
"inventory",
5,
10,
[
new inventory.model.ItemModel(
"Potion",
99,
true,
1,
)
],
),
]
);
}
}
new SampleStack().yaml();
If the generated template files are linked to the point where they are reflected as master data using GS2-SDK, GS2 resource maintenance can be done entirely in the programming language.