Slide 22
Slide 22 text
• ํ๏
• cdk.json ʹ֤ڥͷݸผͷఆΛهࡌ
• σϓϩΠ࣌ͷ Context Ͱڥ͝ͱͷใΛ͢
• ελοΫଆҾͷ Props ܕΛ֦ுͯ͠ఆΛ͢
ෳΞΧϯτͷσϓϩΠ
cdk.json:
{
"app": "npx ts-node --prefer-ts-exts bin/hoge-app.ts”,
"context": {
"projectName": "hoge-fuga",
"dev": {
"description": "Develop environment variables",
"envName": "dev",
"env": {
"account": "123456789012",
"region": "ap-northeast-1"
}
},
"stg": {
"description": "Staging environment variables",
"envName": “stg",
...
}
...
}
}
σϓϩΠ࣌ͷίϚϯυɿ
cdk deploy -c environment=dev ~~
hoge-app.ts:
const app = new cdk.App();
const projectName = app.node.tryGetContext(‘projectName');
const envKey = app.node.tryGetContext(‘environment’);
const envValues = app.node.tryGetContext(envKey);
new HogeHogeStack(app,
`${envValues.env}-${projectName}-hogehoge-stack’, {
env: envValues.env,
envName: envValues.envName,
projectName: projectName,
});