@middy/service-discovery 3.6.2 → 4.0.0-alpha.1
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 +9 -11
- package/index.cjs +3 -8
- package/index.d.ts +11 -6
- package/index.js +3 -3
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -46,11 +46,10 @@ To install this middleware you can use NPM:
|
|
|
46
46
|
npm install --save @middy/service-discovery
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
|
|
50
49
|
## Options
|
|
51
50
|
|
|
52
|
-
- `AwsClient` (object) (default `
|
|
53
|
-
- `awsClientOptions` (object) (default `undefined`): Options to pass to
|
|
51
|
+
- `AwsClient` (object) (default `ServiceDiscoveryClient`): ServiceDiscoveryClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from `@aws-sdk/client-servicediscovery`.
|
|
52
|
+
- `awsClientOptions` (object) (default `undefined`): Options to pass to ServiceDiscoveryClient class constructor.
|
|
54
53
|
- `awsClientAssumeRole` (string) (default `undefined`): Internal key where secrets are stored. See [@middy/sts](/packages/sts/README.md) on to set this.
|
|
55
54
|
- `awsClientCapture` (function) (default `undefined`): Enable XRay by passing `captureAWSClient` from `aws-xray-sdk` in.
|
|
56
55
|
- `fetchData` (object) (required): Mapping of internal key name to API request parameters.
|
|
@@ -60,6 +59,7 @@ npm install --save @middy/service-discovery
|
|
|
60
59
|
- `setToContext` (boolean) (default `false`): Store credentials to `request.context`.
|
|
61
60
|
|
|
62
61
|
NOTES:
|
|
62
|
+
|
|
63
63
|
- Lambda is required to have IAM permission for `servicediscovery:DiscoverInstances`
|
|
64
64
|
|
|
65
65
|
## Sample usage
|
|
@@ -73,33 +73,31 @@ const handler = middy((event, context) => {
|
|
|
73
73
|
statusCode: 200,
|
|
74
74
|
headers: {},
|
|
75
75
|
body: JSON.stringify({ message: 'hello world' })
|
|
76
|
-
}
|
|
76
|
+
}
|
|
77
77
|
|
|
78
78
|
return response
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
-
handler
|
|
82
|
-
|
|
81
|
+
handler.use(
|
|
82
|
+
serviceDiscovery({
|
|
83
83
|
fetchData: {
|
|
84
84
|
instances: {
|
|
85
85
|
NamespaceName: '...',
|
|
86
|
-
ServiceName:'...'
|
|
86
|
+
ServiceName: '...'
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
})
|
|
89
|
+
})
|
|
90
|
+
)
|
|
90
91
|
```
|
|
91
92
|
|
|
92
|
-
|
|
93
93
|
## Middy documentation and examples
|
|
94
94
|
|
|
95
95
|
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).
|
|
96
96
|
|
|
97
|
-
|
|
98
97
|
## Contributing
|
|
99
98
|
|
|
100
99
|
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).
|
|
101
100
|
|
|
102
|
-
|
|
103
101
|
## License
|
|
104
102
|
|
|
105
103
|
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,14 +7,9 @@ Object.defineProperty(module, "exports", {
|
|
|
7
7
|
get: ()=>_default
|
|
8
8
|
});
|
|
9
9
|
const _util = require("@middy/util");
|
|
10
|
-
const
|
|
11
|
-
function _interopRequireDefault(obj) {
|
|
12
|
-
return obj && obj.__esModule ? obj : {
|
|
13
|
-
default: obj
|
|
14
|
-
};
|
|
15
|
-
}
|
|
10
|
+
const _clientServicediscovery = require("@aws-sdk/client-servicediscovery");
|
|
16
11
|
const defaults = {
|
|
17
|
-
AwsClient:
|
|
12
|
+
AwsClient: _clientServicediscovery.ServiceDiscoveryClient,
|
|
18
13
|
awsClientOptions: {},
|
|
19
14
|
awsClientAssumeRole: undefined,
|
|
20
15
|
awsClientCapture: undefined,
|
|
@@ -33,7 +28,7 @@ const serviceDiscoveryMiddleware = (opts = {})=>{
|
|
|
33
28
|
const values = {};
|
|
34
29
|
for (const internalKey of Object.keys(options.fetchData)){
|
|
35
30
|
if (cachedValues[internalKey]) continue;
|
|
36
|
-
values[internalKey] = client.
|
|
31
|
+
values[internalKey] = client.send(new _clientServicediscovery.DiscoverInstancesCommand(options.fetchData[internalKey])).then((resp)=>resp.Instances).catch((e)=>{
|
|
37
32
|
const value = (0, _util.getCache)(options.cacheKey).value ?? {};
|
|
38
33
|
value[internalKey] = undefined;
|
|
39
34
|
(0, _util.modifyCache)(options.cacheKey, value);
|
package/index.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
ServiceDiscoveryClient,
|
|
6
|
+
ServiceDiscoveryClientConfig,
|
|
7
|
+
HttpInstanceSummary
|
|
8
|
+
} from '@aws-sdk/client-servicediscovery'
|
|
7
9
|
|
|
8
|
-
interface Options<
|
|
10
|
+
interface Options<AwsServiceDiscoveryClient = ServiceDiscoveryClient>
|
|
9
11
|
extends Pick<
|
|
10
|
-
MiddyOptions<
|
|
12
|
+
MiddyOptions<
|
|
13
|
+
AwsServiceDiscoveryClient,
|
|
14
|
+
ServiceDiscoveryClientConfig
|
|
15
|
+
>,
|
|
11
16
|
| 'AwsClient'
|
|
12
17
|
| 'awsClientOptions'
|
|
13
18
|
| 'awsClientCapture'
|
|
@@ -21,7 +26,7 @@ interface Options<S = ServiceDiscovery>
|
|
|
21
26
|
export type Context<TOptions extends Options | undefined> = TOptions extends {
|
|
22
27
|
setToContext: true
|
|
23
28
|
}
|
|
24
|
-
? LambdaContext & Record<keyof TOptions['fetchData'],
|
|
29
|
+
? LambdaContext & Record<keyof TOptions['fetchData'], HttpInstanceSummary>
|
|
25
30
|
: LambdaContext
|
|
26
31
|
|
|
27
32
|
declare function serviceDiscovery<TOptions extends Options | undefined> (
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { canPrefetch, createPrefetchClient, createClient, getCache, getInternal, processCache, modifyCache } from '@middy/util';
|
|
2
|
-
import
|
|
2
|
+
import { ServiceDiscoveryClient, DiscoverInstancesCommand } from '@aws-sdk/client-servicediscovery';
|
|
3
3
|
const defaults = {
|
|
4
|
-
AwsClient:
|
|
4
|
+
AwsClient: ServiceDiscoveryClient,
|
|
5
5
|
awsClientOptions: {},
|
|
6
6
|
awsClientAssumeRole: undefined,
|
|
7
7
|
awsClientCapture: undefined,
|
|
@@ -20,7 +20,7 @@ const serviceDiscoveryMiddleware = (opts = {})=>{
|
|
|
20
20
|
const values = {};
|
|
21
21
|
for (const internalKey of Object.keys(options.fetchData)){
|
|
22
22
|
if (cachedValues[internalKey]) continue;
|
|
23
|
-
values[internalKey] = client.
|
|
23
|
+
values[internalKey] = client.send(new DiscoverInstancesCommand(options.fetchData[internalKey])).then((resp)=>resp.Instances).catch((e)=>{
|
|
24
24
|
const value = getCache(options.cacheKey).value ?? {};
|
|
25
25
|
value[internalKey] = undefined;
|
|
26
26
|
modifyCache(options.cacheKey, value);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/service-discovery",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "Service Discovery (Cloud Map) instances middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=16"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
@@ -61,13 +61,13 @@
|
|
|
61
61
|
},
|
|
62
62
|
"homepage": "https://middy.js.org",
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@middy/util": "
|
|
64
|
+
"@middy/util": "4.0.0-alpha.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@
|
|
67
|
+
"@aws-sdk/client-servicediscovery": "^3.186.0",
|
|
68
|
+
"@middy/core": "4.0.0-alpha.1",
|
|
68
69
|
"@types/aws-lambda": "^8.10.101",
|
|
69
|
-
"aws-sdk": "^2.939.0",
|
|
70
70
|
"aws-xray-sdk": "^3.3.3"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "b531f61dac3a5268728a21fc4b2b32054b170f88"
|
|
73
73
|
}
|