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 🙏

© 2025 – Pkg Stats / Ryan Hefner

aws-lockbox

v3.1.0

Published

AWS SSM Parameter Store secrets manager with TypeScript support

Readme

AWS Lockbox

A TypeScript library for managing AWS Parameter Store (SSM) secrets in Node.js applications. Automatically loads parameters into process.env on startup.

Note: Requires Node.js 16 or later.

Development

Node.js Version

This project uses Node.js 20.15.0. We recommend using nvm to manage Node.js versions.

# Install the correct version
nvm install

# Use the correct version
nvm use

⚠️ Breaking Changes in Version 3.0.0

This version includes several breaking changes:

  1. AWS SDK v3 Migration

    • Upgraded from AWS SDK v2 to v3
    • New modular AWS SDK structure
    • Different error handling patterns
  2. TypeScript Support

    • Package is now written in TypeScript
    • Includes type definitions
    • Better error handling and type safety

Migration Guide from v2 to v3

Installation

# Remove old version
npm uninstall aws-lockbox

# Install new version
npm install aws-lockbox@3

Code Changes Required

Old code (v2):

const Lockbox = require('aws-lockbox');
const lb = new Lockbox.Lockbox(maxTries);
lb.exec();
lb.wait(maxWaits, waitMS);  // Synchronous wait

New code (v3):

const { Lockbox } = require('aws-lockbox');  // or import { Lockbox } from 'aws-lockbox';

async function init() {
  try {
    const maxTries = 100;  // Max retries for fetching parameters
    const lb = new Lockbox(maxTries);
    
    // Execute and fetch parameters
    await lb.exec();  // Now returns a Promise
    
    // Wait for parameters to be set (optional)
    const maxWaits = 10;   // Maximum number of retries
    const waitMS = 100;    // Time between retries in milliseconds
    await lb.wait(maxWaits, waitMS);  // Now returns a Promise
    
    console.log('Parameters loaded successfully');
  } catch (err) {
    console.error('Failed to load parameters:', err);
  }
}

init();

Configuration Changes

Your existing lockbox directory structure will continue to work with v3. The main differences are:

  1. Async/Await Support

    • All operations are now Promise-based
    • Need to use await with exec() and wait()
  2. AWS SDK v3 Error Handling

    try {
      const lb = new Lockbox();
      await lb.exec();
    } catch (err) {
      // AWS SDK v3 error format is different
      console.error('Failed to load parameters:', err);
    }
  3. TypeScript Support (Optional)

    • If using TypeScript, you can import types:
    import { Lockbox } from 'aws-lockbox';
    import type { LockboxConfig } from 'aws-lockbox';

Your existing configuration files in the lockbox directory will work without changes:

lockbox/
    - production.js
    - development.js
    - default.js

Getting Started

Installation

npm install aws-lockbox

Directory Structure

  1. Your variables need to be available in AWS Parameter Store (SSM)
  2. Create a lockbox directory in your project root with the following structure:
lockbox/
    - production.js
    - stage.js
    - development.js
    - local.js
    - default.js

Configuration Files

default.js

This is where you put the name of the keys that you wish to pull from Parameter Store:

module.exports = {
  parameters: [
    "/aws-lockbox/test/secret1",
    "/aws-lockbox/test/secret2",
    "/aws-lockbox/test/api-key"
  ],
  overrides: []
};

Environment-specific Files (e.g., development.js, production.js)

These files can extend the default configuration and provide environment-specific overrides:

const defaultConfig = require('./default.js');

module.exports = {
  parameters: defaultConfig.parameters,
  overrides: [
    {
      Name: "/aws-lockbox/test/secret1",
      Value: "local-development-value"
    }
  ]
};

Initialization

import { Lockbox } from 'aws-lockbox';

async function init() {
  // The max number of tries you want to attempt before throwing an error
  const maxTries = 100;
  const lb = new Lockbox(maxTries);
  
  // Execute and fetch parameters
  await lb.exec();
  
  // Optional: Wait for parameters to be set
  const waitMS = 100;    // Time between retries
  const maxWaits = 10;   // Maximum number of retries
  await lb.wait(maxWaits, waitMS);
}

Features

  • Written in TypeScript for better type safety and development experience
  • Uses AWS SDK v3 for better modularity and performance
  • Automatic retries with exponential backoff for throttled requests
  • Environment-specific configuration support
  • Local parameter overrides for development
  • Async/await based API
  • Type definitions included

Configuration Details

Parameters Array

The parameters array in your configuration files defines what parameters to fetch from AWS SSM:

module.exports = {
  parameters: [
    "/my-app/database/url",
    "/my-app/api/key",
    "/my-app/secrets/token"
  ]
};

Overrides Array

The overrides array allows you to specify local values, particularly useful for development:

module.exports = {
  parameters: [...],
  overrides: [
    {
      Name: "/my-app/database/url",
      Value: "localhost:5432"
    }
  ]
};

Environment Selection

The library automatically selects the configuration file based on NODE_ENV:

  • If NODE_ENV=production, it looks for lockbox/production.js
  • If NODE_ENV=development, it looks for lockbox/development.js
  • If no environment-specific file is found, it falls back to lockbox/default.js

AWS Configuration

The library uses AWS SDK v3's SSMClient. Make sure you have proper AWS credentials configured either through:

  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  • AWS credentials file
  • IAM role (if running on AWS infrastructure)

Your IAM role/user needs permissions to access the AWS Systems Manager Parameter Store:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ssm:GetParameters"
      ],
      "Resource": "arn:aws:ssm:region:account-id:parameter/*"
    }
  ]
}

Error Handling

The library includes built-in error handling for common scenarios:

  • Throttling: Automatically retries with exponential backoff
  • Missing parameters: Returns clear error messages
  • Timeout: Configurable timeout with maxTries and waitMS
  • Configuration: Validates configuration format and provides clear error messages

Publishing to npm

For maintainers, there are two ways to publish a new version:

Option 1: Using the Publish Script (Recommended)

First, make the script executable (one-time setup):

chmod +x publish.sh

Then run the automated publish script:

./publish.sh

The script will:

  1. Verify npm login status
  2. Verify Node.js version using nvm
  3. Clean install dependencies
  4. Show current version and optionally update it
    • Choose to keep current version
    • Or update to patch/minor/major version
  5. Build and test
  6. Preview package contents
  7. Confirm before publishing
  8. Publish to npm
  9. Show git tags that need to be pushed

After publishing, you'll need to manually:

  1. Review the generated git tags
  2. Push the tags when ready: git push origin main --tags

Option 2: Manual Publishing

Follow these steps to publish manually:

  1. Ensure correct Node.js version:
# Verify and switch to the correct Node.js version
nvm use

# Verify @types/node matches Node.js version
npm run update-types
  1. Clean install dependencies:
# Remove existing dependencies
rm -rf node_modules package-lock.json

# Fresh install
npm install
  1. Update version:
# For patches (bug fixes)
npm version patch

# For minor releases (new features)
npm version minor

# For major releases (breaking changes)
npm version major
  1. Build and test:
# Rebuild the package
npm run rebuild

# Run tests
npm test
  1. Preview package contents:
# Create tarball without publishing
npm pack

# Review the contents
tar -tf aws-lockbox-*.tgz
  1. Publish to npm:
# Login to npm (if not already logged in)
npm login

# Publish the package
npm publish

# Push git tags
git push origin main --tags

Publishing Checklist

  • [ ] Correct Node.js version (check .nvmrc)
  • [ ] Dependencies are clean installed
  • [ ] Version updated in package.json
  • [ ] CHANGELOG.md updated (if exists)
  • [ ] All tests pass
  • [ ] Build is clean (no warnings)
  • [ ] Package contents reviewed
  • [ ] Published to npm
  • [ ] Git tags pushed
  • [ ] TypeScript types verified (@types/node matches Node.js version)

License

ISC