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

param-store-service

v2.2.2

Published

Service to read parameters from AWS Param Store.

Downloads

497

Readme

NestJS AWS SSM Param Store service NPM

Package to read parameters from AWS System Manager (SSM) parameter store. We can use "@nestjs/config" config service to read parameters from file and environment variables. And use paramStoreService to read environment specific parameters like password or endpoint URL on application start up.

Module exports 'ParamStoreService' to access downloaded parameters. Service has method 'get' to read property.

Example:

paramStoreService.get('nameOfProperty');

Note:

  1. If region (awsRegion) is not provided it defaults to 'us-east-1'.
  2. awsParamSorePath is required.

Installation

npm i param-store-service

Configuration

Two ways to configure param-store-service module:

  1. Static configuration
    @Module({
        imports: [
            ParamStoreModule.register({
                awsRegion: 'us-east-1',
                awsParamSorePath: '/application/config',
            }),
        ],
        controllers: [AppController],
        providers: [AppService],
    })
    export class AppModule {
        constructor(
            private paramStoreService: ParamStoreService,
        ) {
            console.log('name', paramStoreService.get('name'));
        }
    }
  2. Async configuration using config service
    1. Config service required properties:
      1. param-store.awsRegion - AWS Region
      2. param-store.awsParamStorePath - AWS Parameter store path prefix to fetch all related properties ( /prefix/property1, /prefix/property2)
    2. Config service optional properties:
      1. param-store.awsParamStoreContinueOnError - Default value is false. If set true, server will not stop if there is an error fetching properties from AWS parameter store
@Module({
    imports: [
        ConfigModule.forRoot({
            isGlobal: true,
            load: [configServiceParamStoreConfiguration],
            envFilePath: `config/${process.env.NODE_ENV || 'development'}.env`,
            validate,
        }),
        ParamStoreModule.registerAsync({
            import: ConfigModule,
            useClass: ConfigService,
        }),
    ],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {
    constructor(
        private paramStoreService: ParamStoreService,
    ) {
        console.log('name', paramStoreService.get('name'));
    }
}

Configuration to load for Config service

import {registerAs} from '@nestjs/config';

export default registerAs('param-store', () => ({
    awsRegion: process.env.AWS_REGION,
    awsParamStorePath: process.env.AWS_PARAM_STORE_PATH,
}));

Validator (Optional)

import {plainToClass} from 'class-transformer';
import {IsEnum, IsNumber, IsString, validateSync} from 'class-validator';

enum Environment {
    Development = 'development',
    Production = 'production',
    Test = 'test',
}

class EnvironmentVariables {
    @IsEnum(Environment)
    NODE_ENV: Environment = Environment.Test;

    @IsNumber()
    PORT = 3000;

    @IsString()
    AWS_REGION = 'us-east-1';

    @IsString()
    AWS_PARAM_STORE_PATH: string;

    @IsBoolean()
    CONTINUE_ON_ERROR = false;
}

export function validate(config: Record<string, unknown>) {
    const validatedConfig = plainToClass(EnvironmentVariables, config, {
        enableImplicitConversion: true,
    });
    const errors = validateSync(validatedConfig, {
        skipMissingProperties: false,
    });

    if (errors.length > 0) {
        throw new Error(errors.toString());
    }
    return validatedConfig;
}

.env file

message='hello'
name='Old name'
description='Hello there!'
AWS_REGION='us-east-1'
AWS_PARAM_STORE_PATH='/application/config'

Contributing

Contributions welcome!

Author

PM

License

Licensed under the MIT License.