@nona-creative/aws-cdk-config
v1.0.2
Published
AWS Config package
Downloads
6
Readme
AWS Config (CDK)
Installation
npm i -S @nona-creative/aws-cdk-config
Usage
Create a
config
directory in the AWS CDK package that needs access to environment specific configuration variables+-- packages +-- some-api-aws-cdk +-- src +-- config
Then add any of the following json files:
paramstore.json
secrets-manager.json
Configure each of these config files as described in the
Config Files
below
Config Files
There are 2 ways to load environment specific configuration variables into a AWS CDK App, Stack or Construct using this package:
- from AWS Paramstore
- from AWS Secrets Manager
The resulting values from both approaches are returned together when you call loadConfig
on the AWSConfig
instance as follows:
const awsConfig = new AWSConfig(...)
const configData = awsConfig.loadConfig()
AWS Paramstore config file
src/config/paramstore.json
syntax:
{
"<env name>": "<paramstore path>"
}
example:
{
"EMAIL_FROM": "email/fromAddress"
}
The param store paths will have the App & Package names, as well as the stage prepended eg. the example above will become:
{
"EMAIL_FROM": "/some-project/some-package/dev/email/fromAddress"
}
These are set in the .env
file corresponding to the deployment stage, eg.
if you are deploying some-api-aws-cdk
to dev
stage, then:
pacakges/some-api-aws-cdk/.env.dev
will contain App & Package names, eg.
APP_NAME=some-project
PACKAGE_NAME=some-api
usage:
import * as paramStoreKeys from '../config/aws-params.json'
const awsConfig = new AWSConfig(stack, `${id}-config`, {
stage,
paramStoreKeys,
})
const configData = awsConfig.loadConfig()
const { EMAIL_FROM } = configData
AWS Secrets Manager config file
src/config/paramstore.json
syntax:
{
"<env name>": "<secret key>"
}
example:
{
"PG_PASSWORD": "dbMasterPassword"
}
usage:
As well as providing the config as demonstrated above,
you will also need to provide the AWS Secrets Manager Secret ARN when instantiating the AWSConfig
class,
do this by defining an SECRETS_ARN
env in the .env
file corresponding to the deployment stage, eg.
in:
pacakges/some-api-aws-cdk/.env.dev
, add the following:
SECRETS_ARN=<your secret's ARN>
Then use this env when you instantiating the AWSConfig
class:
import * as secretsManagerKeys from '../config/aws-secrets.json'
const awsConfig = new AWSConfig(stack, `${id}-config`, {
stage,
secretsManagerKeys,
secretsArn: process.env.SECRETS_ARN,
})
const configData = awsConfig.loadConfig()
const { PG_PASSWORD } = awsConfig