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

nestjs-parameter-store

v1.0.1

Published

Use nestjs managed AWS Parameter Store

Downloads

2

Readme

Table of Contents

Installation

npm install nestjs-parameter-store @aws-sdk/client-ssm

pnpm install nestjs-parameter-store @aws-sdk/client-ssm

Configuration

Configure the module forRoot() or forRootAsync() to access all the AWS System Manager service in production.

Configure the module registerParamStore() or registerParamStoreAsync() to loaded all the parameters in AWS Parameter Store in production using @Inject(GET_PARAMETERS)

Static configuration

import {Module} from "@nestjs/common";
import {NestjsParameterStoreModule} from "nestjs-parameter-store";

@Module({
    imports: [
        NestjsParameterStoreModule.forRoot({region: "region"}),
        NestjsParameterStoreModule.registerParamStore({
            Path: "/test",
            Recursive: true,
            WithDecryption: true,
        }),
    ],
})
export class AppModule {
}

Async configuration

import {Module} from "@nestjs/common";
import {NestjsParameterStoreModule} from "nestjs-parameter-store";

@Module({
    imports: [
        NestjsParameterStoreModule.forRootAsync({
            imports: [ConfigModule],
            inject: [ConfigService],
            useFactory: async (config: ConfigService) => {
                const {region, accessKeyId, secretAccessKey} = config.get("aws");
                return {region, accessKeyId, secretAccessKey};
            },
        }),
        NestjsParameterStoreModule.registerParamStoreAsync({
            imports: [ConfigModule],
            inject: [ConfigService],
            useFactory: async (config: ConfigService) => {
                const {path} = config.get("aws-param-store");
                return {Path: path, Recursive: true, WithDecryption: true};
            },
        }),
    ],
})
export class AppModule {
}

Service

This module exposes the following services.

AwsParamStoreService

The AwsParamStoreService allows you to access the configuration loaded from AWS Parameter Store. Use its own class name as the injection token.

The AwsParamStoreService exposes the following methods:

  • getParameter({ Name: String, WithDecryption: Boolean })
  • getParameters({ Name: String[], WithDecryption: Boolean })
  • getParametersByPath({ Path: String, Recursive: boolean, WithDecryption: boolean, OnlyValue: boolean })

You can use OnlyValue option to get the object like { [parameter name]: [value], ... }.

import {Injectable} from "@nestjs/common";
import {AwsParamStoreService} from "nestjs-parameter-store";

@Injectable()
export class TestService {
    constructor(private readonly awsParameterStore: AwsParameterStore) {
        console.log(awsParamStoreService.getParameter({Name: "/test/parameter"}));
        console.log(
            awsParamStoreService.getParameters({
                Names: ["/test/parameter", "/test/secure"],
                WithDecryption: true,
            }),
        );
        console.log(
            awsParamStoreService.getParametersByPath({
                Path: "/test",
                Recursive: true,
                WithDecryption: true,
                OnlyValue: true,
            }),
        );
    }
}

GET_PARAMETERS

You can access the parameters loaded from the Parameter Store by configuration registerParamStore() or registerParamStoreAsync()

@Inject(GET_PARAMETERS) is functionally the same as getParametersByPath().

import {Inject, Injectable} from "@nestjs/common";
import {GET_PARAMETERS} from "nestjs-parameter-store";
import {Parameter} from "@aws-sdk/client-ssm";

@Injectable()
export class ParameterStoreService {
    constructor(@Inject(GET_PARAMETERS) private readonly parameters: Parameter[]) {
        console.log(parameters)
    }
}