@nona-creative/aws-cdk-config
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

AWS Config (CDK)

Installation

npm i -S @nona-creative/aws-cdk-config

Usage

  1. Create a config directory in the AWS CDK package that needs access to environment specific configuration variables

    +-- packages
        +-- some-api-aws-cdk
            +-- src
                +-- config
    
  2. Then add any of the following json files:

    • paramstore.json
    • secrets-manager.json
  3. 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:

  1. from AWS Paramstore
  2. 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

Package Sidebar

Install

npm i @nona-creative/aws-cdk-config

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

34.3 kB

Total Files

27

Last publish

Collaborators

  • ian-cawood
  • yesitsdave
  • syntaxza
  • rollyourowned
  • neilrussell6