Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to SDK v3 #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 4.0.0 (2023-04-07

* aws-sdk updated to version 3, with a dependency only on `@aws-sdk/client-ssm`, instead of using a peer dependency.


## 3.2.0 (2019-12-04)

Updated:
Expand Down
35 changes: 14 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
[![Build Status](https://travis-ci.org/vandium-io/aws-param-store.svg?branch=master)](https://travis-ci.org/vandium-io/aws-param-store)
[![npm version](https://badge.fury.io/js/aws-param-store.svg)](https://badge.fury.io/js/aws-param-store)
[![npm version](https://badge.fury.io/js/aws-param-store-sdkv3.svg)](https://badge.fury.io/js/aws-param-store-sdkv3)

# aws-param-store

Module for loading parameter-store values from AWS SSM

Now updated to use the AWS SDK v3, only requiring the SSMClient module.

## Features
* Gets parameters by name(s) or path
* Recursively resolves paths and decodes parameters by default
* Paginates results automatically
* Supports both synchronous and asynchronous querying of parameters
* Uses Promises for asynchronous calls
* Can run inside AWS Lambda environment
* AWS Lambda Node.js 8.10.x compatible
* Lightweight and does not require additional dependencies other than the AWS-SDK


## Installation
Install via npm.

npm install aws-param-store --save

**Note**: `aws-param-store` does not contain a dependency on `aws-sdk` and it should be installed within your application.
npm install aws-param-store-sdkv3 --save

## Getting Started

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

awsParamStore.getParametersByPath( '/project1/service1/production' )
.then( (parameters) => {
Expand All @@ -39,7 +37,7 @@ If your AWS region is not set in your environment variables, then it can be set
options when calling `newQuery()`:

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

awsParamStore.getParametersByPath( '/project1/service1/production', { region: 'us-east-1' } )
.then( (parameters) => {
Expand All @@ -64,7 +62,7 @@ further control, please use the `parameterQuery()` method.
Gets a parameter by name. This method returns a promise that resolves the Parameter.

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

awsParamStore.getParameter( '/project1/my-parameter', { region: 'us-east-1' } )
.then( (parameter) => {
Expand All @@ -78,7 +76,7 @@ awsParamStore.getParameter( '/project1/my-parameter', { region: 'us-east-1' } )
Gets a parameter by name. This method will block until the operation completes.

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

let parameter = awsParamStore.getParameterSync( '/project1/my-parameter',
{ region: 'us-east-1' } );
Expand All @@ -93,7 +91,7 @@ Gets one or more parameters by name. This method returns a promise that resolves
an object that contains `Parameters` and `InvalidParameters`.

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

awsParamStore.getParameters( ['/project1/my-parameter1', '/project1/my-parameter2'],
{ region: 'us-east-1' } )
Expand All @@ -112,7 +110,7 @@ block until the operation completes, and will return an object that contains
`Parameters` and `InvalidParameters`.

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

let results = awsParamStore.getParametersSync( ['/project1/my-parameter1', '/project1/my-parameter2'],
{ region: 'us-east-1' } );
Expand All @@ -128,7 +126,7 @@ Gets parameters by recursively traversing the supplied path. This method returns
a promise that resolves the parameters that were found.

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

awsParamStore.getParametersByPath( '/project1' )
.then( (parameters) => {
Expand All @@ -144,7 +142,7 @@ block until the operation completes, and will return a list of matching
parameters.

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

let parameters = awsParamStore.getParametersByPathSync( '/project1' );

Expand All @@ -156,7 +154,7 @@ let parameters = awsParamStore.getParametersByPathSync( '/project1' );
Puts parameter. This method returns a promise that resolves to the version returned back.

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

awsParamStore.putParameter('key', 'value1,value2', 'StringList', {region: 'us-east-1', Overwrite: false})
.then( (results) => {
Expand All @@ -170,7 +168,7 @@ awsParamStore.putParameter('key', 'value1,value2', 'StringList', {region: 'us-ea
Puts parameter. This method. This method will block until the version returned back.

```js
const awsParamStore = require( 'aws-param-store' );
const awsParamStore = require( 'aws-param-store-sdkv3' );

let results = awsParamStore.putParameterSync('key', 'securedstring', 'SecureString', {region: 'us-east-1'});

Expand Down Expand Up @@ -213,11 +211,6 @@ Executes the query based on path or name(s) that were selected. This operation
will block until complete.


## Feedback

We'd love to get feedback on how to make this tool better. Feel free to contact
us at `[email protected]`

## License

[BSD-3-Clause](https://en.wikipedia.org/wiki/BSD_licenses)
40 changes: 0 additions & 40 deletions lib/aws_paginated_call.js

This file was deleted.

47 changes: 23 additions & 24 deletions lib/ssm.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
'use strict';

const AWS = require( 'aws-sdk' );

const AWSPaginatedCall = require( './aws_paginated_call' );

function collect( list, additions ) {

list.push( ...(additions || []) );
}
const { SSMClient, GetParameterCommand, PutParameterCommand, GetParametersCommand, GetParametersByPathCommand } = require("@aws-sdk/client-ssm");

class SSM {

constructor( options ) {

this._ssm = new AWS.SSM( options );
this._ssm = new SSMClient( options );
}

getParametersByPath( params ) {

return this._paginatedCall( 'getParametersByPath' )
.execute( params, [], (data, parameters) => {

collect( parameters, data.Parameters );
});
return this._getParamatersByPathPaginated( params ).then( (data) => {
return data;
});
}

getParameter( params ) {

return this._ssm.getParameter( params ).promise()
return this._ssm.send(new GetParameterCommand(params))
.then( (data) => {

return data.Parameter;
Expand All @@ -36,25 +26,34 @@ class SSM {

getParameters( params ) {

return this._paginatedCall( 'getParameters' )
.execute( params, { Parameters: [], InvalidParameters: []}, (data, results) => {
return this._ssm.send(new GetParametersCommand(params))
.then( (data) => {

collect( results.Parameters, data.Parameters );
collect( results.InvalidParameters, data.InvalidParameters );
return data;
});
}

putParameter( params ) {
return this._ssm.putParameter( params ).promise()
return this._ssm.send(new PutParameterCommand(params))
.then( (data) => {

return data;
});
}

_paginatedCall( functionName ) {

return new AWSPaginatedCall( this._ssm, functionName );
async _getParamatersByPathPaginated( params ) {
let results = [];
let NextToken;
do {
const result = await this._ssm.send(
new GetParametersByPathCommand(Object.assign({}, params, NextToken? {NextToken} : undefined))
);
NextToken = result.NextToken;
if (result.Parameters && result.Parameters.length) {
results.push(result.Parameters);
}
} while (NextToken);
return [].concat(...results);
}
}

Expand Down
Loading