Skip to content

Commit 69e6c00

Browse files
authored
Merge pull request #1 from valiton/fix-review-comments
Fix review comments
2 parents 9277920 + 29d45e2 commit 69e6c00

File tree

5 files changed

+31
-29
lines changed

5 files changed

+31
-29
lines changed

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# AWS PARAM REPLACE
1+
# AWS PARAM INJECT
22

3-
This is a simple tool to replace this patter `${ssm:/my/path/to/param}` with the
4-
value of `/my/path/to/param` in the AWS Parameter store.
3+
This is a simple tool to inject AWS SSM Parameters into text.
4+
If text contains pattern like this `${ssm:/my/path/to/param}`,
5+
it will be injected with the value of the parameter `/my/path/to/param`.
56

67
This can for example be used in a Deployment script when we want to fetch and
78
inject variables from the Parameter Store into an ECS Task definition.
@@ -29,7 +30,7 @@ MY_TEXT="
2930
Value=\${ssm:/my/path/to/param1}
3031
OtherValue=\${ssm:/my/path/to/param2}
3132
"
32-
npx -p @valiton/aws-param-replace aws-param-replace "$MY_TEXT"
33+
npx -p @valiton/aws-param-inject aws-param-inject "$MY_TEXT"
3334

3435
# Outputs:
3536
#
@@ -41,23 +42,24 @@ npx -p @valiton/aws-param-replace aws-param-replace "$MY_TEXT"
4142

4243
Since `npm ci` will not be available install the package globally first
4344
```sh
44-
npm i -g aws-param-replace
45+
npm i -g aws-param-inject
4546
# then run it
46-
aws-param-replace "..."
47+
aws-param-inject "..."
4748
```
4849

4950
### Node API
5051

5152
```js
52-
const replaceSsmParams = require('aws-param-replace');
53+
const injectSsmParams = require('@valiton/aws-param-inject');
5354

5455
// Make sure to escape the dollar sign in the template string
5556
const input = `
5657
Value=\${ssm:/my/path/to/param1}
5758
OtherValue=\${ssm:/my/path/to/param2}
5859
`
5960

60-
replaceSsmParams(input)
61+
injectSsmParams(input)
62+
.then(inputWithInjectedParameters => ...)
6163
```
6264

6365
## Requirements
@@ -66,4 +68,5 @@ Node 8+
6668

6769
## Credits
6870

69-
Made by [Valiton](https://www.valiton.com/).
71+
Inspired by the awesome [serverless framework](https://serverless.com/).
72+
Made my [Valiton](https://www.valiton.com/).

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "@valiton/aws-param-replace",
2+
"name": "@valiton/aws-param-inject",
33
"version": "1.0.0",
4-
"description": "Simple tool to fetch and replace parameters from AWS SSM into a string.",
4+
"description": "Simple tool to fetch and inject parameters from AWS SSM into a string.",
55
"bin": "src/index.js",
6-
"main": "src/replace-ssm-params.js",
6+
"main": "src/inject-ssm-params.js",
77
"files": [
88
"/src/"
99
],

src/index.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
#!/usr/bin/env node
2-
const replaceSsmParams = require('./replace-ssm-params');
2+
const injectSsmParams = require('./inject-ssm-params');
33

4-
const input = process.argv[2];
5-
6-
if (!input) {
7-
const usageMsg = `
8-
Usage: aws-param-replace <String>
4+
const usageMsg = `\
5+
Usage: aws-param-inject <String>
96
107
<String> can contain any number of patterns like \${ssm:/path/to/param},
11-
which will be replaced into the input string.
8+
which will be injected into the input string.
129
1310
Example:
1411
1512
MY_TEXT="
1613
Value=\${ssm:/my/path/to/param1}
1714
OtherValue=\${ssm:/my/path/to/param2}
1815
"
19-
aws-param-replace "$MY_TEXT"
20-
`;
21-
console.info(usageMsg);
22-
process.exit(1);
23-
}
16+
aws-param-inject "$MY_TEXT"`;
17+
18+
const readInput = () => {
19+
const input = process.argv[2];
20+
return input ? Promise.resolve(input) : Promise.reject(new Error(usageMsg));
21+
};
2422

25-
replaceSsmParams(input)
23+
readInput()
24+
.then(injectSsmParams)
2625
.then(console.log)
2726
.catch(err => {
2827
console.error(err.message);

src/replace-ssm-params.js renamed to src/inject-ssm-params.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const responseToMap = data =>
1010
{}
1111
);
1212

13-
const handleError = invalidParameters => {
13+
const makeError = invalidParameters => {
1414
const formattedParams = invalidParameters.join(', ');
15-
const errMsg = `\nThe following Parameters could not be fetched from SSM. [${formattedParams}\n]`;
15+
const errMsg = `The following Parameters could not be fetched from SSM. [${formattedParams}]`;
1616
return new Error(errMsg);
1717
};
1818

@@ -24,7 +24,7 @@ const fetchParameters = names =>
2424
data =>
2525
data.InvalidParameters.length === 0
2626
? Promise.resolve(responseToMap(data))
27-
: Promise.reject(handleError(data.InvalidParameters))
27+
: Promise.reject(makeError(data.InvalidParameters))
2828
);
2929

3030
const replaceParameters = input => paramsMap =>

0 commit comments

Comments
 (0)