1.0.5 • Published 3 years ago

nestjs-config-aws-ksm v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

NestJS ConfigModule With AWS Secret Manager

Table of Contents

Installation

Using npm:

npm install nestjs-config-aws-ksm

Using yarn:

yarn add nestjs-config-aws-ksm

Initialization

  1. Import ConfigModule in your module.
import { Module } from '@nestjs/common';
import { ConfigModule } from 'nestjs-config-aws-ksm';
import { NameService } from './name.service';

@Module({
  imports: [
    ConfigModule.register({
      accessKey: 'AWS_ACCESS_KEY',
      secretAccessKey: 'AWS_ACCESS_SECRET_KEY',
      region: 'AWS_REGION',
      storage: 'STORAGE_NAME'
    }),
  ],
  providers: :[NameService],
  exports: [NameService],
})

export class NameModule {}
  1. Import and use ConfigService in your Service.
import { Injectable } from '@nestjs/common';
import { ConfigService } from 'nestjs-config-aws-ksm';

@Injectable()
export class NameService {
  constructor(configService: ConfigService) {
    configService.get('SECRET_AWS_OR_ENV_VARIABLE');
  }
}

Notes

Given that the register method is asynchronous the variables may not be loaded yet. If you need to load it via registerAsync we recommend using the loadStorage method. Example:

import { Module } from '@nestjs/common';
import { ConfigModule } from 'nestjs-config-aws-ksm';
import { NameService } from './name.service';

@Module({
  imports: [
    JwtModule.registerAsync({
      imports: [ConfigModule.register({
        accessKey: 'AWS_ACCESS_KEY',
        secretAccessKey: 'AWS_ACCESS_SECRET_KEY',
        region: 'AWS_REGION',
        storage: 'STORAGE_NAME'
      })],
      useFactory: async (configService: ConfigService) => {
        await configService.loadStorage('STORAGE_NAME');
        return ({
          secret: configService.get('JWT_SECRET'),
          signOptions: { expiresIn: "72h" },
        })
      },
      inject: [ConfigService],
    }),
  ],
  providers: :[NameService],
  exports: [NameService],
})

export class NameModule {}

Who are we

We are the development partner of choice for several different sized companies who need a team that delivers fast & scalable code understanding users needs and commercial scope.

Our services

  • Website development
  • UX/UI Design
  • Webapp Development
  • Mobile Development
  • Ecommerce
  • Specialized enterprise software
  • Legacy migrations, debugging and refactors

Why us?

We don't outsource a single thing. Each wireframe, design and every piece of code is written with outmost care by Blackstone's diverse teams.

🛠 Built With

🤝 Contributing

Contributions, issues and feature requests are welcome!

You can also suggest a new feature by creating an Issue. Please wait for confirmation before working on it.

📝 License

Copyright © 2020 Blackstone Studio.

This project is MIT licensed.