stackconfig v1.0.1
CDK Stack Config for Stacks creates using CDK
The CDK Stack Config library is used to definde the two important parameters that will differentiate the stacks in your AWS Accounts. You can use this library and deploy the same stack to multiple environments or same environments with different name.
Installation
Using npm:
$ npm i -g npm
$ npm i stackconfig
You can also mention the same in your package.json
in the devDependencies
section and use npm install
or yarn install
to install the package as part of your build process:
devDependencies: {
"stackconfig": "^1.0.0"
}
Parameters from the library
The parameters and context obtained from this library are as follows.
-c stackPrefix
: A string that can be used as prefix for stack name and resources created in it-c environment
: Environment for which the stack is being deployedThe following are the predefined environments in the library
default dev staging prod review test qa uat
Please contact the dev team if you need more environments.
Stack Context
Along with the parameters, this library relies on the Stack Context that is generated as part of CDK. The generated file will be named as cdk.context.json
which contains information like:
- AWS Account ID
- AWS Default Region
- AWS Default imported resources like VPC, Route53 HostedZone, etc
How to use in code
Classic import:
import { StackConfigService } from "stackconfig"
From the import in index.ts
, the following can be used
const config = new StackConfigService().stackConfig;
const stackName = config.stackPrefix;
const stackEnv = config.environment;
const stackProps: StackProps = {
env: {
region: config.region,
account: config.accountId,
},
};
The cdk command will look like:
cdk synth/diff/deploy/destroy -c stackPrefix="my-stack" -c environment="dev"
Dependencies
The library relies on the AWS CLI and AWS CDK installation and configuration to be completed before using it. The Stack Context information are collected using the credentials and config in the .aws
folder or from the exported variables in the terminal.
This is also dependent on the version of AWS CDK Library used. Currently, we support v2 of the AWS CDK.