This repository interfaces Serice Discovery, in this instance CloudMap, in order to locate and communicate with different services. As opposed to storing ARN's in environment variables, this library will interface CloudMap to find a service by a user friendly naming convention, and will understand what 'type' of service you've requested, and use the correct code to communicate/call that service.
- Lambda (
request|call). - SNS (
publish). // subscribe not supported by SNS. - SQS (
queue|listen), - Automation//SSM task (
automate|script). - Step function (
state-machine).
- Http (
request|call). - Fargate/ECS Task (
run).
This library requires Node 8 and above. Node 6 and below will soon be EOL and unsupported.
const ServiceDiscovery = require('@peak-ai/ais-service-discovery');await ServiceDiscovery.request('namespace.service->handler', body);await ServiceDiscovery.publish('namspace.service-name->topic', event, opts);await ServiceDiscovery.queue('namespace.service-name->queue-name', message, opts // optional);const messages = await ServiceDiscovery.listen('namespace.service-name->queue-name', opts // optional);
messages.on('message', (message) => {
});CloudMapService:
Type: AWS::ServiceDiscovery::Service
Properties:
Description: discover handlers for ais-service-segment-explorer
Name: segment-explorer
NamespaceId: ${cf:ais-${opt:stage}-service-discovery.NamespaceId}
CreateRefreshSegmentInstance:
Type: "AWS::ServiceDiscovery::Instance"
Properties:
InstanceAttributes:
arn: ${self:service}-${opt:stage}-refresh-segment
type: function
InstanceId: refresh-segment
ServiceId:
Ref: CloudMapService