service-discovery
Fetches Service Discovery instances to be used when connecting to other AWS services.
Install
To install this middleware you can use NPM:
- npm
- Yarn
npm install --save @middy/service-discovery
yarn add @middy/service-discovery
Options
AwsClient
(object) (defaultAWS.STS
): AWS.STS class constructor (e.g. that has been instrumented with AWS XRay). Must be fromaws-sdk
v2.awsClientOptions
(object) (defaultundefined
): Options to pass to AWS.STS class constructor.awsClientAssumeRole
(string) (defaultundefined
): Internal key where secrets are stored. See @middy/sts on to set this.awsClientCapture
(function) (defaultundefined
): Enable XRay by passingcaptureAWSClient
fromaws-xray-sdk
in.fetchData
(object) (required): Mapping of internal key name to API request parameters.disablePrefetch
(boolean) (defaultfalse
): On cold start requests will trigger early if they can. SettingawsClientAssumeRole
disables prefetch.cacheKey
(string) (defaultsts
): Cache key for the fetched data responses. Must be unique across all middleware.cacheExpiry
(number) (default-1
): How long fetch data responses should be cached for.-1
: cache forever,0
: never cache,n
: cache for n ms.setToContext
(boolean) (defaultfalse
): Store credentials torequest.context
.
NOTES:
- Lambda is required to have IAM permission for
servicediscovery:DiscoverInstances
Sample usage
import middy from '@middy/core'
import serviceDiscovery from '@middy/service-discovery'
const handler = middy((event, context) => {
const response = {
statusCode: 200,
headers: {},
body: JSON.stringify({ message: 'hello world' })
};
return response
})
handler
.use(serviceDiscovery({
fetchData: {
instances: {
NamespaceName: '...',
ServiceName:'...'
}
}
}))
Bundling
To exclude aws-sdk
add aws-sdk/clients/servicediscovery.js
to the exclude list.