Created
December 16, 2019 08:25
-
-
Save farminf/0efcdc4d243a22e88b32c11fadfe24d6 to your computer and use it in GitHub Desktop.
Deploying different stacks based on different account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-new */ | |
const AWS = require("aws-sdk"); | |
const cdk = require("@aws-cdk/core"); | |
const { CommonStack } = require("./stack"); | |
const { DevStack } = require("./dev-stack"); | |
const { ProdStack } = require("./prod-stack"); | |
const sts = new AWS.STS({}); | |
const TEST_REGION = "eu-west-1"; | |
const DEV_REGION = "eu-west-1"; | |
const AWS_ACCOUNT_IDS = { | |
development: "000000000", | |
quality: "00000000", | |
production: "000000000", | |
}; | |
class App extends cdk.App { | |
deployCommonStacks() { | |
this.commonStack = new CommonStack( | |
this, | |
"commonStack", | |
{} | |
); | |
} | |
deployDevStacks() { | |
this.devStack = new DevStack( | |
this, | |
"devStack", | |
{} | |
); | |
} | |
deployProdStacks() { | |
this.prodStack = new ProdStack( | |
this, | |
"prodStack", | |
{} | |
); | |
} | |
async deployStacks() { | |
const assumed = await sts.getCallerIdentity({}).promise(); | |
console.log("deployStacks() caller identity:", assumed); | |
this.deployCommonStacks(); | |
if (assumed.Account === AWS_ACCOUNT_IDS.development) { | |
console.log("Deploying to development account:"); | |
this.deployDevStacks(); | |
} | |
if (assumed.Account === AWS_ACCOUNT_IDS.production) { | |
console.log("Deploying to production account:"); | |
this.deployProdStacks(); | |
} | |
return assumed.Account; | |
} | |
} | |
const app = new App(); | |
app | |
.deployStacks() | |
.then(acc => { | |
console.log(`deployStacks() completed for account: ${acc}`); | |
}) | |
.catch(e => { | |
console.log("error in deployStacks():", e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment