Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
/ region-sync Public archive
generated from 5app/package-template

Helpers for pub/sub'ing data between regions via sns/sqs

Notifications You must be signed in to change notification settings

5app/region-sync

Repository files navigation

region sync

Known Vulnerabilities CircleCI

Wraps SNS/SQS with some boilerplate logic we use for syncing data between regions:

SNS+SQS:

  1. structure all messages with date, fromRegion and JSON encoded payload.

SQS:

  1. prevents handlers being called if source + dest regions are the same
  2. deletes messages after handler has handled (if successful)
  3. sets up the continuous long poll

SQS usage:

const {createHandler} = require('@5app/region-sync');
const queueUrl = 'http://localhost:4576/000000000000/fooq';
const handler = createHandler({
	backoffSeconds: 4,
	longPollSeconds: 1,
	currentRegion: 'us-east-1',
});

handler.addQueueHandler(queueUrl, async function (msg) {
	// handle it, but if promise rejects, the message wont be removed.
});

SNS usage:

const {createPublisher} = require('@5app/region-sync');
const payload = {foo: 'bar'};
const publisher = createPublisher({
	currentRegion: 'us-east-1',
	snsRegion: 'us-east-1',
});
await publisher.publish(topicArn, payload);

testing

LOGS_LEVEL=info npm test