https://github.com/allejo/aws-parameter-store-to-object
A simple function to pull values from AWS Parameter Store and make them accessible as an object
https://github.com/allejo/aws-parameter-store-to-object
aws typescript
Last synced: 3 months ago
JSON representation
A simple function to pull values from AWS Parameter Store and make them accessible as an object
- Host: GitHub
- URL: https://github.com/allejo/aws-parameter-store-to-object
- Owner: allejo
- License: mit
- Created: 2021-02-07T00:40:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-08T05:34:48.000Z (about 4 years ago)
- Last Synced: 2025-01-15T03:05:24.904Z (5 months ago)
- Topics: aws, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@allejo/aws-parameter-store-to-object
- Size: 132 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AWS Parameter Store to Object (JavaScript)
In the spirit of the dependency hell that is the JavaScript world, here is a simple function that I ended up reusing a lot at work to query parameters from AWS' Parameter Store.
## Installation
```bash
npm install @allejo/aws-parameter-store-to-object
# or
yarn add @allejo/aws-parameter-store-to-object
```## Usage
```typescript
import { getParameterStoreValues } from '@allejo/aws-parameter-store-to-object';interface Settings {
appID: number;
installID: number;
ghOrg: string;
privateKey: string;
}const strToNum = (value?: string) => value ? Number.parseInt(value) : 0;
const variables = await getParameterStoreValues(
{
app_id: { appID: strToNum },
installation_id: { installID: strToNum },
gh_org: 'ghOrg',
private_key: 'privateKey',
},
{
prefix: '/application/github_application/',
}
);// variables.appID
// variables.installID
// etc.
```### Value Mapping
Give you have a Parameter Store key in the format of `/application/app_id`, then you will set the key of the object to the 'app_id' (this is coming from Parameter Store) and the value to 'appID' (this is the value in the object being created, i.e. `Settings`).
```javascript
{
app_id: 'appID'
}
```By default, everything from Parameter Store will be coming in as a string. In the situation where you'd like to convert the string to an integer, you give it an object with the key of the `Settings` object, and a callback that converts a nullable string to whatever data type the field is.
For example, if we need to convert the `app_id` Parameter Store value from a string to an integer and assign it to the `appID` field of a `Settings` object.
```typescript
{
app_id: { appID: (val?: string) => val ? Number.parseInt(val) : 0 }
}
```