Skip to content

Instantly share code, notes, and snippets.

@Visya
Created November 4, 2020 11:55
Show Gist options
  • Save Visya/21a728e866ae794c21fdf8707e3bc9c1 to your computer and use it in GitHub Desktop.
Save Visya/21a728e866ae794c21fdf8707e3bc9c1 to your computer and use it in GitHub Desktop.
Implementing message versioning for SNS/SQS pattern

Versioning in SNS messages

Message versioning can be required in SNS+SQS patternto allow setting up specific consumers that can process newer versions and make version transitions smooth and painless.

To achieve that you can use the native AWS SNS filtering mechanism. It allows to set version message attribute on a message sent to SNS and filter which queues receive which versions of messages.

Example of versioned message

{
  "Type": "Notification",
  "MessageId": "d5c1bc6c-efe8-5dc3-af32-e46edec1027f",
  "TopicArn": "arn:aws:sns:eu-west-1:000000000000:test",
  "Message": "some message",
  "Timestamp": "2020-10-15T11:13:45.002Z",
  "MessageAttributes": {
    "version": {
      "Type": "Number",
      "Value": "1"
    }
  }
}

Subscription filter policies

Subscription filter policy that allows only messages with specific versions:

{
  "version": [1, 2]
}

Subscription filter policy that allows all version except a specific one:

{
  "version": [{"anything-but": 3}]
}

Subscription filter policy that allows a range of versions:

{
  "version": [{"numeric": [">", 2, "<=", 5]}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment