@middy/ssm 3.6.1 → 4.0.0-alpha.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 CHANGED
@@ -46,7 +46,6 @@ The Middleware makes a single API request to fetch all the parameters defined by
46
46
 
47
47
  For each parameter defined by name, you also provide the name under which its value should be added to `context`. For each path, you instead provide a prefix, and by default the value import each parameter returned from that path will be added to `context` with a name equal to what's left of the parameter's full name _after_ the defined path, with the prefix prepended. If the prefix is an empty string, nothing is prepended. You can override this behaviour by providing your own mapping function with the `getParamNameFromPath` config option.
48
48
 
49
-
50
49
  ## Install
51
50
 
52
51
  To install this middleware you can use NPM:
@@ -55,11 +54,10 @@ To install this middleware you can use NPM:
55
54
  npm install --save @middy/ssm
56
55
  ```
57
56
 
58
-
59
57
  ## Options
60
58
 
61
- - `AwsClient` (object) (default `AWS.SSM`): AWS.SSM class constructor (e.g. that has been instrumented with AWS X-Ray). Must be from `aws-sdk` v2.
62
- - `awsClientOptions` (object) (default `undefined`): Options to pass to AWS.SSM class constructor.
59
+ - `AwsClient` (object) (default `SSMClient`): SSMClient class constructor (i.e. that has been instrumented with AWS X-Ray). Must be from `@aws-sdk/client-ssm`.
60
+ - `awsClientOptions` (object) (default `undefined`): Options to pass to SSMClient class constructor.
63
61
  - `awsClientAssumeRole` (string) (default `undefined`): Internal key where role tokens are stored. See [@middy/sts](/packages/sts/README.md) on to set this.
64
62
  - `awsClientCapture` (function) (default `undefined`): Enable AWS X-Ray by passing `captureAWSClient` from `aws-xray-sdk` in.
65
63
  - `fetchData` (object) (required): Mapping of internal key name to API request parameter `Names`/`Path`. `SecureString` are automatically decrypted.
@@ -69,6 +67,7 @@ npm install --save @middy/ssm
69
67
  - `setToContext` (boolean) (default `false`): Store role tokens to `request.context`.
70
68
 
71
69
  NOTES:
70
+
72
71
  - Lambda is required to have IAM permission for `ssm:GetParameters` and/or `ssm:GetParametersByPath` depending on what you're requesting.
73
72
  - `SSM` has [throughput limitations](https://docs.aws.amazon.com/general/latest/gr/ssm.html). Switching to Advanced Parameter type or increasing `maxRetries` and `retryDelayOptions.base` in `awsClientOptions` may be required.
74
73
 
@@ -84,14 +83,16 @@ const handler = middy((event, context) => {
84
83
 
85
84
  let globalDefaults = {}
86
85
  handler
87
- .use(ssm({
88
- fetchData: {
89
- accessToken: '/dev/service_name/access_token', // single value
90
- dbParams: '/dev/service_name/database/', // object of values, key for each path
91
- defaults: '/dev/defaults'
92
- },
93
- setToContext: true
94
- }))
86
+ .use(
87
+ ssm({
88
+ fetchData: {
89
+ accessToken: '/dev/service_name/access_token', // single value
90
+ dbParams: '/dev/service_name/database/', // object of values, key for each path
91
+ defaults: '/dev/defaults'
92
+ },
93
+ setToContext: true
94
+ })
95
+ )
95
96
  .before((request) => {
96
97
  globalDefaults = request.context.defaults.global
97
98
  })
@@ -99,7 +100,7 @@ handler
99
100
 
100
101
  ```javascript
101
102
  import middy from '@middy/core'
102
- import {getInternal} from '@middy/util'
103
+ import { getInternal } from '@middy/util'
103
104
  import ssm from '@middy/ssm'
104
105
 
105
106
  const handler = middy((event, context) => {
@@ -108,38 +109,42 @@ const handler = middy((event, context) => {
108
109
 
109
110
  let globalDefaults = {}
110
111
  handler
111
- .use(ssm({
112
- fetchData: {
113
- defaults: '/dev/defaults'
114
- },
115
- cacheKey: 'ssm-defaults'
116
- }))
117
- .use(ssm({
118
- fetchData: {
119
- accessToken: '/dev/service_name/access_token', // single value
120
- dbParams: '/dev/service_name/database/', // object of values, key for each path
121
- },
122
- cacheExpiry: 15*60*1000,
123
- cacheKey: 'ssm-secrets'
124
- }))
112
+ .use(
113
+ ssm({
114
+ fetchData: {
115
+ defaults: '/dev/defaults'
116
+ },
117
+ cacheKey: 'ssm-defaults'
118
+ })
119
+ )
120
+ .use(
121
+ ssm({
122
+ fetchData: {
123
+ accessToken: '/dev/service_name/access_token', // single value
124
+ dbParams: '/dev/service_name/database/' // object of values, key for each path
125
+ },
126
+ cacheExpiry: 15 * 60 * 1000,
127
+ cacheKey: 'ssm-secrets'
128
+ })
129
+ )
125
130
  // ... other middleware that fetch
126
131
  .before(async (request) => {
127
- const data = await getInternal(['accessToken','dbParams','defaults'], request)
132
+ const data = await getInternal(
133
+ ['accessToken', 'dbParams', 'defaults'],
134
+ request
135
+ )
128
136
  Object.assign(request.context, data)
129
137
  })
130
138
  ```
131
139
 
132
-
133
140
  ## Middy documentation and examples
134
141
 
135
142
  For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
136
143
 
137
-
138
144
  ## Contributing
139
145
 
140
146
  Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
141
147
 
142
-
143
148
  ## License
144
149
 
145
150
  Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
package/index.cjs CHANGED
@@ -7,15 +7,10 @@ Object.defineProperty(module, "exports", {
7
7
  get: ()=>_default
8
8
  });
9
9
  const _util = require("@middy/util");
10
- const _ssmJs = _interopRequireDefault(require("aws-sdk/clients/ssm.js"));
11
- function _interopRequireDefault(obj) {
12
- return obj && obj.__esModule ? obj : {
13
- default: obj
14
- };
15
- }
10
+ const _clientSsm = require("@aws-sdk/client-ssm");
16
11
  const awsRequestLimit = 10;
17
12
  const defaults = {
18
- AwsClient: _ssmJs.default,
13
+ AwsClient: _clientSsm.SSMClient,
19
14
  awsClientOptions: {},
20
15
  awsClientAssumeRole: undefined,
21
16
  awsClientCapture: undefined,
@@ -52,10 +47,10 @@ const ssmMiddleware = (opts = {})=>{
52
47
  if ((!idx || (idx + 1) % awsRequestLimit !== 0) && !(idx + 1 === internalKeys.length)) {
53
48
  continue;
54
49
  }
55
- batchReq = client.getParameters({
50
+ batchReq = client.send(new _clientSsm.GetParametersCommand({
56
51
  Names: batchFetchKeys,
57
52
  WithDecryption: true
58
- }).promise().then((resp)=>{
53
+ })).then((resp)=>{
59
54
  return Object.assign(...(resp.InvalidParameters ?? []).map((fetchKey)=>{
60
55
  return {
61
56
  [fetchKey]: new Promise(()=>{
@@ -104,12 +99,12 @@ const ssmMiddleware = (opts = {})=>{
104
99
  return values;
105
100
  };
106
101
  const fetchPath = (path, nextToken, values = {})=>{
107
- return client.getParametersByPath({
102
+ return client.send(new _clientSsm.GetParametersByPathCommand({
108
103
  Path: path,
109
104
  NextToken: nextToken,
110
105
  Recursive: true,
111
106
  WithDecryption: true
112
- }).promise().then((resp)=>{
107
+ })).then((resp)=>{
113
108
  Object.assign(values, ...resp.Parameters.map((param)=>{
114
109
  return {
115
110
  [(0, _util.sanitizeKey)(param.Name.replace(path, ''))]: parseValue(param)
package/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import middy from '@middy/core'
2
2
  import { Options as MiddyOptions } from '@middy/util'
3
3
  import { Context as LambdaContext } from 'aws-lambda'
4
- import SSM from 'aws-sdk/clients/ssm'
4
+ import { SSMClient, SSMClientConfig } from '@aws-sdk/client-ssm'
5
5
  import { JsonValue } from 'type-fest'
6
6
 
7
- interface Options<S = SSM>
8
- extends MiddyOptions<S, SSM.Types.ClientConfiguration> {}
7
+ interface Options<AwsSSMClient = SSMClient>
8
+ extends MiddyOptions<AwsSSMClient, SSMClientConfig> {}
9
9
 
10
10
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
11
  type ExtractSingles<T> = T extends `/${infer _}` ? never : T
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { canPrefetch, createPrefetchClient, createClient, processCache, getCache, modifyCache, jsonSafeParse, getInternal, sanitizeKey } from '@middy/util';
2
- import SSM from 'aws-sdk/clients/ssm.js';
2
+ import { SSMClient, GetParametersCommand, GetParametersByPathCommand } from '@aws-sdk/client-ssm';
3
3
  const awsRequestLimit = 10;
4
4
  const defaults = {
5
- AwsClient: SSM,
5
+ AwsClient: SSMClient,
6
6
  awsClientOptions: {},
7
7
  awsClientAssumeRole: undefined,
8
8
  awsClientCapture: undefined,
@@ -39,10 +39,10 @@ const ssmMiddleware = (opts = {})=>{
39
39
  if ((!idx || (idx + 1) % awsRequestLimit !== 0) && !(idx + 1 === internalKeys.length)) {
40
40
  continue;
41
41
  }
42
- batchReq = client.getParameters({
42
+ batchReq = client.send(new GetParametersCommand({
43
43
  Names: batchFetchKeys,
44
44
  WithDecryption: true
45
- }).promise().then((resp)=>{
45
+ })).then((resp)=>{
46
46
  return Object.assign(...(resp.InvalidParameters ?? []).map((fetchKey)=>{
47
47
  return {
48
48
  [fetchKey]: new Promise(()=>{
@@ -91,12 +91,12 @@ const ssmMiddleware = (opts = {})=>{
91
91
  return values;
92
92
  };
93
93
  const fetchPath = (path, nextToken, values = {})=>{
94
- return client.getParametersByPath({
94
+ return client.send(new GetParametersByPathCommand({
95
95
  Path: path,
96
96
  NextToken: nextToken,
97
97
  Recursive: true,
98
98
  WithDecryption: true
99
- }).promise().then((resp)=>{
99
+ })).then((resp)=>{
100
100
  Object.assign(values, ...resp.Parameters.map((param)=>{
101
101
  return {
102
102
  [sanitizeKey(param.Name.replace(path, ''))]: parseValue(param)
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@middy/ssm",
3
- "version": "3.6.1",
3
+ "version": "4.0.0-alpha.0",
4
4
  "description": "SSM (EC2 Systems Manager) parameters middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=14"
7
+ "node": ">=16"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
@@ -62,14 +62,14 @@
62
62
  },
63
63
  "homepage": "https://middy.js.org",
64
64
  "dependencies": {
65
- "@middy/util": "3.6.1"
65
+ "@middy/util": "4.0.0-alpha.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@middy/core": "3.6.1",
68
+ "@aws-sdk/client-ssm": "^3.186.0",
69
+ "@middy/core": "4.0.0-alpha.0",
69
70
  "@types/aws-lambda": "^8.10.101",
70
- "aws-sdk": "^2.939.0",
71
71
  "aws-xray-sdk": "^3.3.3",
72
72
  "type-fest": "^3.0.0"
73
73
  },
74
- "gitHead": "31a7f9f8e93a73a8be382b3022b9cfcbc13b2961"
74
+ "gitHead": "306fb9aa633d5757d11ced3dc192f046ef3c2685"
75
75
  }