node-env-resolver-aws 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -97
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ import { resolveSsm, resolveSecrets } from 'node-env-resolver-aws';
|
|
|
21
21
|
const config = await resolveSsm({
|
|
22
22
|
path: '/myapp/config'
|
|
23
23
|
}, {
|
|
24
|
-
API_ENDPOINT: '
|
|
24
|
+
API_ENDPOINT: 'string',
|
|
25
25
|
TIMEOUT: 30
|
|
26
26
|
});
|
|
27
27
|
|
|
@@ -29,26 +29,26 @@ const config = await resolveSsm({
|
|
|
29
29
|
const secrets = await resolveSecrets({
|
|
30
30
|
secretId: 'myapp/production/secrets'
|
|
31
31
|
}, {
|
|
32
|
-
DATABASE_URL: '
|
|
32
|
+
DATABASE_URL: 'string',
|
|
33
33
|
API_KEY: 'string'
|
|
34
34
|
});
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
### Using with
|
|
37
|
+
### Using with resolve.with() (for combining multiple sources)
|
|
38
38
|
|
|
39
39
|
```ts
|
|
40
40
|
import { resolve } from 'node-env-resolver';
|
|
41
41
|
import { awsSecrets, awsSsm } from 'node-env-resolver-aws';
|
|
42
42
|
|
|
43
|
-
const config = await resolve(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
]
|
|
51
|
-
|
|
43
|
+
const config = await resolve.with(
|
|
44
|
+
[awsSecrets({ secretId: 'myapp/production/secrets' }), {
|
|
45
|
+
DATABASE_URL: 'postgres',
|
|
46
|
+
API_KEY: 'string',
|
|
47
|
+
}],
|
|
48
|
+
[awsSsm({ path: '/myapp/config' }), {
|
|
49
|
+
TIMEOUT: 30,
|
|
50
|
+
}]
|
|
51
|
+
);
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
## Features
|
|
@@ -73,7 +73,7 @@ export const handler = async (event) => {
|
|
|
73
73
|
const config = await resolveSecrets({
|
|
74
74
|
secretId: 'myapp/secrets'
|
|
75
75
|
}, {
|
|
76
|
-
DATABASE_URL: '
|
|
76
|
+
DATABASE_URL: 'postgres',
|
|
77
77
|
API_KEY: 'string'
|
|
78
78
|
});
|
|
79
79
|
// 200ms delay on EVERY request + AWS API costs
|
|
@@ -83,26 +83,24 @@ export const handler = async (event) => {
|
|
|
83
83
|
### With caching (recommended)
|
|
84
84
|
|
|
85
85
|
```typescript
|
|
86
|
-
import {
|
|
87
|
-
import {
|
|
86
|
+
import { resolve, cached, TTL } from 'node-env-resolver';
|
|
87
|
+
import { awsSecrets } from 'node-env-resolver-aws';
|
|
88
88
|
|
|
89
|
-
// Cache AWS calls - call resolve every time, let cached() make it fast
|
|
89
|
+
// Cache AWS calls - call resolve.with() every time, let cached() make it fast
|
|
90
90
|
export const getConfig = async () => {
|
|
91
|
-
return await resolve(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
]
|
|
105
|
-
});
|
|
91
|
+
return await resolve.with(
|
|
92
|
+
[cached(
|
|
93
|
+
awsSecrets({ secretId: 'myapp/secrets' }),
|
|
94
|
+
{
|
|
95
|
+
ttl: TTL.minutes5,
|
|
96
|
+
maxAge: TTL.hour,
|
|
97
|
+
staleWhileRevalidate: true
|
|
98
|
+
}
|
|
99
|
+
), {
|
|
100
|
+
DATABASE_URL: 'postgres',
|
|
101
|
+
API_KEY: 'string',
|
|
102
|
+
}]
|
|
103
|
+
);
|
|
106
104
|
};
|
|
107
105
|
|
|
108
106
|
// Call in your handler
|
|
@@ -119,16 +117,14 @@ import { resolve, cached, TTL } from 'node-env-resolver';
|
|
|
119
117
|
import { awsSecrets } from 'node-env-resolver-aws';
|
|
120
118
|
|
|
121
119
|
const getConfig = async () => {
|
|
122
|
-
return await resolve(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
]
|
|
131
|
-
});
|
|
120
|
+
return await resolve.with(
|
|
121
|
+
[cached(
|
|
122
|
+
awsSecrets({ secretId: 'myapp/lambda' }),
|
|
123
|
+
{ ttl: TTL.minutes5, staleWhileRevalidate: true }
|
|
124
|
+
), {
|
|
125
|
+
DATABASE_URL: 'postgres',
|
|
126
|
+
}]
|
|
127
|
+
);
|
|
132
128
|
};
|
|
133
129
|
|
|
134
130
|
export const handler = async (event) => {
|
|
@@ -140,7 +136,7 @@ export const handler = async (event) => {
|
|
|
140
136
|
### Best Practices
|
|
141
137
|
|
|
142
138
|
1. **Always use `cached()` wrapper** when accessing AWS Secrets Manager or SSM
|
|
143
|
-
2. **Call `resolve()` every time** - don't cache the result in a variable
|
|
139
|
+
2. **Call `resolve.with()` every time** - don't cache the result in a variable
|
|
144
140
|
3. **Use `staleWhileRevalidate: true`** for zero-latency updates
|
|
145
141
|
4. **Choose appropriate TTL** based on how often secrets change:
|
|
146
142
|
- Frequently rotating: `TTL.minutes5`
|
|
@@ -169,7 +165,7 @@ This package uses the standard AWS SDK credential provider chain. Credentials ar
|
|
|
169
165
|
region: 'us-east-1',
|
|
170
166
|
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
|
|
171
167
|
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
|
|
172
|
-
}, { API_ENDPOINT: '
|
|
168
|
+
}, { API_ENDPOINT: 'string' });
|
|
173
169
|
```
|
|
174
170
|
|
|
175
171
|
**In most cases, you don't need to pass credentials explicitly** - just set the standard AWS environment variables or use IAM roles.
|
|
@@ -190,7 +186,7 @@ const config = await resolveSsm({
|
|
|
190
186
|
region: 'us-east-1',
|
|
191
187
|
recursive: true
|
|
192
188
|
}, {
|
|
193
|
-
API_ENDPOINT: '
|
|
189
|
+
API_ENDPOINT: 'string',
|
|
194
190
|
TIMEOUT: 30
|
|
195
191
|
});
|
|
196
192
|
```
|
|
@@ -205,7 +201,7 @@ import { safeResolveSsm } from 'node-env-resolver-aws';
|
|
|
205
201
|
const result = await safeResolveSsm({
|
|
206
202
|
path: '/myapp/config'
|
|
207
203
|
}, {
|
|
208
|
-
API_ENDPOINT: '
|
|
204
|
+
API_ENDPOINT: 'string'
|
|
209
205
|
});
|
|
210
206
|
|
|
211
207
|
if (result.success) {
|
|
@@ -226,7 +222,7 @@ const config = await resolveSecrets({
|
|
|
226
222
|
secretId: 'myapp/production/secrets',
|
|
227
223
|
region: 'us-east-1'
|
|
228
224
|
}, {
|
|
229
|
-
DATABASE_URL: '
|
|
225
|
+
DATABASE_URL: 'string',
|
|
230
226
|
API_KEY: 'string'
|
|
231
227
|
});
|
|
232
228
|
```
|
|
@@ -241,7 +237,7 @@ import { safeResolveSecrets } from 'node-env-resolver-aws';
|
|
|
241
237
|
const result = await safeResolveSecrets({
|
|
242
238
|
secretId: 'myapp/secrets'
|
|
243
239
|
}, {
|
|
244
|
-
DATABASE_URL: '
|
|
240
|
+
DATABASE_URL: 'string'
|
|
245
241
|
});
|
|
246
242
|
|
|
247
243
|
if (result.success) {
|
|
@@ -251,27 +247,26 @@ if (result.success) {
|
|
|
251
247
|
}
|
|
252
248
|
```
|
|
253
249
|
|
|
254
|
-
###
|
|
250
|
+
### Resolver Functions (for use with `resolve.with()`)
|
|
255
251
|
|
|
256
252
|
#### `awsSsm(options)` and `awsSecrets(options)`
|
|
257
253
|
|
|
258
|
-
These return resolver objects for use with
|
|
254
|
+
These return resolver objects for use with `resolve.with()` when you need to combine multiple sources.
|
|
259
255
|
|
|
260
256
|
## AWS Secrets Manager
|
|
261
257
|
|
|
262
258
|
Load JSON secrets from Secrets Manager:
|
|
263
259
|
|
|
264
260
|
```ts
|
|
261
|
+
import { resolve } from 'node-env-resolver';
|
|
265
262
|
import { awsSecrets } from 'node-env-resolver-aws';
|
|
266
263
|
|
|
267
|
-
const config = await resolve(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
]
|
|
274
|
-
});
|
|
264
|
+
const config = await resolve.with(
|
|
265
|
+
[awsSecrets({ secretId: 'myapp/secrets' }), {
|
|
266
|
+
DATABASE_URL: 'postgres',
|
|
267
|
+
API_KEY: 'string'
|
|
268
|
+
}]
|
|
269
|
+
);
|
|
275
270
|
```
|
|
276
271
|
|
|
277
272
|
With options:
|
|
@@ -289,16 +284,15 @@ awsSecrets({
|
|
|
289
284
|
Load parameters from Parameter Store:
|
|
290
285
|
|
|
291
286
|
```ts
|
|
287
|
+
import { resolve } from 'node-env-resolver';
|
|
292
288
|
import { awsSsm } from 'node-env-resolver-aws';
|
|
293
289
|
|
|
294
|
-
const config = await resolve(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
]
|
|
301
|
-
});
|
|
290
|
+
const config = await resolve.with(
|
|
291
|
+
[awsSsm({ path: '/myapp/config' }), {
|
|
292
|
+
API_ENDPOINT: 'string',
|
|
293
|
+
TIMEOUT: 30
|
|
294
|
+
}]
|
|
295
|
+
);
|
|
302
296
|
```
|
|
303
297
|
|
|
304
298
|
Get all parameters under a path:
|
|
@@ -319,20 +313,18 @@ Add TTL caching to reduce AWS API calls:
|
|
|
319
313
|
import { resolve, cached, TTL } from 'node-env-resolver';
|
|
320
314
|
import { awsSecrets } from 'node-env-resolver-aws';
|
|
321
315
|
|
|
322
|
-
const config = await resolve(
|
|
323
|
-
|
|
324
|
-
},
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
]
|
|
335
|
-
});
|
|
316
|
+
const config = await resolve.with(
|
|
317
|
+
[cached(
|
|
318
|
+
awsSecrets({ secretId: 'myapp/secrets' }),
|
|
319
|
+
{
|
|
320
|
+
ttl: TTL.minutes5,
|
|
321
|
+
maxAge: TTL.hour,
|
|
322
|
+
staleWhileRevalidate: true
|
|
323
|
+
}
|
|
324
|
+
), {
|
|
325
|
+
DATABASE_URL: 'postgres'
|
|
326
|
+
}]
|
|
327
|
+
);
|
|
336
328
|
```
|
|
337
329
|
|
|
338
330
|
## AWS Permissions
|
|
@@ -408,7 +400,7 @@ import { resolveSecrets, resolveSsm } from 'node-env-resolver-aws';
|
|
|
408
400
|
const secrets = await resolveSecrets({
|
|
409
401
|
secretId: 'myapp/production/secrets'
|
|
410
402
|
}, {
|
|
411
|
-
DATABASE_URL: '
|
|
403
|
+
DATABASE_URL: 'postgres',
|
|
412
404
|
JWT_SECRET: 'string',
|
|
413
405
|
});
|
|
414
406
|
|
|
@@ -422,23 +414,25 @@ const config = await resolveSsm({
|
|
|
422
414
|
});
|
|
423
415
|
```
|
|
424
416
|
|
|
425
|
-
### Production app with
|
|
417
|
+
### Production app with resolve.with() (combining sources)
|
|
426
418
|
|
|
427
419
|
```ts
|
|
428
|
-
import { resolve } from 'node-env-resolver';
|
|
420
|
+
import { resolve, processEnv } from 'node-env-resolver';
|
|
429
421
|
import { awsSecrets, awsSsm } from 'node-env-resolver-aws';
|
|
430
422
|
|
|
431
|
-
const config = await resolve(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}, {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
423
|
+
const config = await resolve.with(
|
|
424
|
+
[processEnv(), {
|
|
425
|
+
NODE_ENV: ['development', 'production'] as const,
|
|
426
|
+
PORT: 3000,
|
|
427
|
+
}],
|
|
428
|
+
[awsSecrets({ secretId: 'myapp/production/secrets' }), {
|
|
429
|
+
DATABASE_URL: 'postgres',
|
|
430
|
+
JWT_SECRET: 'string',
|
|
431
|
+
}],
|
|
432
|
+
[awsSsm({ path: '/myapp/production/config' }), {
|
|
433
|
+
TIMEOUT: 30,
|
|
434
|
+
}]
|
|
435
|
+
);
|
|
442
436
|
```
|
|
443
437
|
|
|
444
438
|
### Lambda function
|
|
@@ -449,7 +443,7 @@ import { resolveSecrets } from 'node-env-resolver-aws';
|
|
|
449
443
|
const config = await resolveSecrets({
|
|
450
444
|
secretId: 'lambda/secrets'
|
|
451
445
|
}, {
|
|
452
|
-
API_ENDPOINT: '
|
|
446
|
+
API_ENDPOINT: 'string',
|
|
453
447
|
TIMEOUT: 30,
|
|
454
448
|
});
|
|
455
449
|
|
|
@@ -466,7 +460,7 @@ import { safeResolveSecrets } from 'node-env-resolver-aws';
|
|
|
466
460
|
const result = await safeResolveSecrets({
|
|
467
461
|
secretId: 'myapp/production/secrets'
|
|
468
462
|
}, {
|
|
469
|
-
DATABASE_URL: '
|
|
463
|
+
DATABASE_URL: 'string',
|
|
470
464
|
API_KEY: 'string'
|
|
471
465
|
});
|
|
472
466
|
|
|
@@ -490,7 +484,7 @@ import { safeResolveSecrets } from 'node-env-resolver-aws';
|
|
|
490
484
|
const result = await safeResolveSecrets({
|
|
491
485
|
secretId: 'myapp/secrets'
|
|
492
486
|
}, {
|
|
493
|
-
DATABASE_URL: '
|
|
487
|
+
DATABASE_URL: 'string'
|
|
494
488
|
});
|
|
495
489
|
|
|
496
490
|
if (!result.success) {
|
|
@@ -511,7 +505,7 @@ try {
|
|
|
511
505
|
const config = await resolveSecrets({
|
|
512
506
|
secretId: 'myapp/secrets'
|
|
513
507
|
}, {
|
|
514
|
-
DATABASE_URL: '
|
|
508
|
+
DATABASE_URL: 'string'
|
|
515
509
|
});
|
|
516
510
|
} catch (error) {
|
|
517
511
|
console.error('Failed to load secrets from AWS:', error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-env-resolver-aws",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "AWS resolvers for node-env-resolver (Secrets Manager, SSM Parameter Store)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"node": ">=18"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
40
|
-
"@aws-sdk/client-ssm": "^3.
|
|
39
|
+
"@aws-sdk/client-secrets-manager": "^3.908.0",
|
|
40
|
+
"@aws-sdk/client-ssm": "^3.908.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"node-env-resolver": "^
|
|
43
|
+
"node-env-resolver": "^3.0.0"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@eslint/js": "^9.37.0",
|
|
50
|
-
"@types/node": "^24.7.
|
|
50
|
+
"@types/node": "^24.7.2",
|
|
51
51
|
"@typescript-eslint/eslint-plugin": "^8.46.0",
|
|
52
52
|
"@typescript-eslint/parser": "^8.46.0",
|
|
53
53
|
"eslint": "^9.37.0",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"tsup": "^8.5.0",
|
|
57
57
|
"typescript": "^5.9.3",
|
|
58
58
|
"vitest": "^3.2.4",
|
|
59
|
-
"node-env-resolver": "
|
|
59
|
+
"node-env-resolver": "3.0.0"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "tsup",
|
|
63
|
-
"
|
|
63
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
64
64
|
"lint": "eslint src/",
|
|
65
65
|
"test": "vitest run",
|
|
66
66
|
"format": "prettier --write \"**/*.{ts,tsx,md}\""
|