npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@code-dome/cdk-parameter-store

v1.64.0

Published

CDK helper class that retrieves and stores values from AWS SSM Parameter Store and AWS Secrets Manager

Downloads

5

Readme

cdk-parameter-store

CDK helper class that retrieves and stores values from AWS SSM Parameter Store and AWS Secrets Manager

Installation

$ npm install @code-dome/cdk-parameter-store

Usage

const { ParameterStore } = require('@code-dome/cdk-parameter-store');

// 1.1 Define key/value relationships for your parameter names as found in SSM Parameter Store
const parameters = {
  myParameter: 'name/of/my/parameter/in/ssm',
  apiURL: 'project/backend/api/url',
};

// 1.2 Define key/value relationships for your secret names (and version) as found in Secrets Manager
const secrets = {
  superSecretValue :{
    name: 'name/of/my/secret/in/secretsManager',
    version: 1
  },
}

class MyStack extends Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    // 2. Create an instance of ParameterStore in the scope of your stack, construct or stage
    const store = new ParameterStore(this);

    // 3. Load parameter names
    const cleanParameters = store.loadStringsWithNames(parameters);
    const secureParameters = store.loadeSecureStringsWithNames(secrets);

    // 4. Retreive parameter values (CDK resolvables)
    const myParameter = cleanParameters.myParameter;
    const myParameterAgain = store.getResolvableByKey('myParameter');
    const myParameterYetAgain = store.getResolvableByName('name/of/my/parameter/in/ssm');

    // Bonus. You can load more parameters later
    const myOtherParameter = store.loadStringWithName('my/other/parameter', 'myOtherParameter');
    const myOtherParameterAgain = store.getResolvableByKey('myOtherParameter');
    const myOtherParameterYetAgain = store.getResolvableByName('my/other/parameter');
  }
}

Important Notes

  1. ParameterStore is not a construct or a stack, it does not create any resources in AWS
  2. The instance still needs the scope of your stack, construct or stage so that CDK knows which account/region to search in.
  3. If the parameter does not exist, CDK will crash and burn.
  4. Current version of this module will only retrieve the latest version of the secret or parameter.
  5. Secure strings in SSM Parameter Store are not available in CDK as of CDK 1.64.0

Class Definition

Properties

  • scope: The scope of the parent stack, construct or stage.
  • resolvableParametersByKey: { key1: 'value', ... } All loaded parameter and secret values by key.
  • resolvableParametersByName: { name1: 'value', ... } All loaded parameter and secret values by name.

Methods

  • constructor(scope: Construct): ParameterStore Initializes instance properties
  • exposeValue(value: string, name: string, key: string): string (IResolvable) Adds a value to the resolvableParametersByKey and resolvableParametersByName with the given name and key
  • getResolvableByKey(key: string): string (IResolvable) Returns the loaded value with key key
  • getResolvableByName(name: string): string (IResolvable) Returns the loaded value
  • loadSecureStringWithName({ name: string, version: Number }, key: string): string (IResolvable) Loads content of Secret with name name from Secrets Manager, then exposes the value by key and name using exposeValue()
  • loadSecureStringsWithNames(secretNames: Object <{ key: { name: string, version: Number }, ...}>): Object <{ key: string (IResolvable), ... }> Calls loadSecureStringWithName() for each key in secretNames
  • loadStringWithName(name: string, key: string): string (IResolvable) Lookup of string parameter named name in SSM, then exposes the value by key and name using exposeValue()
  • loadStringsWithNames(parameterNames: Object <{ key: 'name', ...}>): Object <{ key: string (IResolvable), ... }> Calls loadStringWithName() for each key in parameterNames

Test

npm test

TODO

  • Handle version in SSM and Secrets
  • Handle StringListParameter