https://github.com/essential2189/nestjs-parameter-store
NestJS Parameter Store
https://github.com/essential2189/nestjs-parameter-store
aws nestjs param-store parameter-store
Last synced: 10 days ago
JSON representation
NestJS Parameter Store
- Host: GitHub
- URL: https://github.com/essential2189/nestjs-parameter-store
- Owner: essential2189
- Created: 2023-05-01T12:33:36.000Z (almost 3 years ago)
- Default Branch: v1.x
- Last Pushed: 2023-05-02T01:12:44.000Z (almost 3 years ago)
- Last Synced: 2025-06-23T02:40:17.009Z (10 months ago)
- Topics: aws, nestjs, param-store, parameter-store
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/nestjs-parameter-store
- Size: 126 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Table of Contents
## Installation
```sh
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
```typescript
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
```typescript
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], ... }`.
```typescript
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()`.
```typescript
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)
}
}
```