npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sagacify/sqs-move

v3.0.2

Published

Moving SQS messages with ease

Downloads

89

Readme

SQS-Move

npm version ci semantic-release

Moving SQS messages with ease. Messages MessageAttributes, MessageDeduplicationId & MessageGroupId will be preserved. Other Attributes will be lost.

Motivation

Most of the time when you use an SQS queue you also define a deadletter queue. This is a great idea, so when your service has a bug you can correct it and then repush all the messages in your deadletter queue to the orignal queue. Unfortunatly the AWS interface doeesn't provide an action to move your message. You have to do it programmatically, this is where sqs-move will help you.

Of course, you can use it to move messages from any queue to any other queue.

Installation

$ npm install @sagacify/sqs-move

Usage

sqs-move is a simple function.

Signature

async function(sqsInstance, fromQueueUrl, toQueueUrl, {
  batchSize = 1,
  includes = null,
  excludes = null,
  transformBody = null,
  transformMessageAttributes = null,
  json = true
} = {})

Notes:

  • sqsInstance is expected to be an AWS.SQS instance
  • batchSize maximum is 10
  • includes & excludes are expected to be criteria a string or a flat key/value object (see: advanced exemple)
  • transformBody a function that takes the message original Body & *MessageAttributes as parameter and return a transformed body
  • transformMessageAttributes a function that takes the message original Body & *MessageAttributes as parameter and return a MessageAttributes body
  • json indicates if it is need to json parse message body on for includes and/or exclude

* MessageAttributes is a simple map, it is automatically parsed and composed for you

More on includes excludes

If it is a string then message is only going to be moved if the message contains (includes) or not contains (excludes) the string provided.

If it is a key/value object then message is only going to be moved if the message contains (includes) or not contains (excludes) the key/value provided. You can includes/excludes on deep property using the flat keys. This { 'user.address.country': 'BE' } will check in body if body.user.address.country === 'BE'.

Simple example

import AWS from 'aws-sdk';
import sqsMove from '@sagacify/sqs-move';
// OR
const AWS = require('aws-sdk');
const sqsMove = require('@sagacify/sqs-move');

const sqsInstance = new AWS.SQS({
  accessKeyId: 'some-aws-id',
  secretAccessKey: 'some-aws-secret',
  region: 'eu-west-1'
});

const { movedCount } = await sqsMove(
  sqsInstance,
  'https://sqs.eu-west-1.amazonaws.com/123456789012/some-dead-letter-queue',
  'https://sqs.eu-west-1.amazonaws.com/123456789012/some-process-queue'
);

console.log(`${movedCount} messages are back in process queue !`);

Advanced example

import AWS from 'aws-sdk';
import sqsMove from '@sagacify/sqs-move';
// OR
const AWS = require('aws-sdk');
const { sqsMove } = require('@sagacify/sqs-move');

const sqsInstance = new AWS.SQS({
  accessKeyId: 'some-aws-id',
  secretAccessKey: 'some-aws-secret',
  region: 'eu-west-1'
});

const { movedCount, filteredCount } = await sqsMove(
  sqsInstance,
  'https://sqs.eu-west-1.amazonaws.com/123456789012/some-dead-letter-queue',
  'https://sqs.eu-west-1.amazonaws.com/123456789012/some-process-queue', {
    batchSize: 10,
    includes: { 'user.name': 'olivier' },
    excludes: { 'user.country': 'BE' },
    transformBody: (body, messageAttributes) => {
      body.user.country = 'US'
      body.traceId = messageAttributes.traceId

      return body;
    },
    transformMessageAttributes: (body, messageAttributes) => {
      // Removes traceId from messageAttributes
      const { traceId, ...newMessageAttributes} = messageAttributes

      return newMessageAttributes;
    },
    json: true
  }
);

console.log(`${movedCount} messages are back in process queue & ${filteredCount} stayed in the deadletter queue !`);