Skip to content

Check that SNS topics match between two accounts

Same topics and subscriptions in two accounts.

Terminal recording of kurkik sns diff

The recording shows kurkik sns diff on the demo sandbox; its data differs from this example.

Terminal window
kurkik sns diff topics-staging topics-prod --consumers
topics-staging vs topics-prod
Amazon SNS topics-prod
Notes
- Topics-staging is account 300000001101 and topics-prod is account 300000001102; ARNs are compared by the name they end in.
Drift: 0 changed · 0 unmanaged · 0 missing (no drift) — 5 matched

Exit code 0: no drift.

Mark Means
~ both sides have it, but it differs
! only the first side has it
+ only the second side has it

A document and a connection (exit 2)

$ kurkik sns diff staging.yaml topics-prod --consumers
staging.yaml vs topics-prod
AsyncAPI 3.0.0 · Amazon SNS topics-prod (us-east-1)
Subscriptions
! orders subscription — Subscription sqs:arn:aws:sqs:us-east-1:300000001101:orders-queue does not exist. (document: sqs:arn:aws:sqs:us-east-1:300000001101:orders-queue)
+ orders subscription — Subscription sqs:arn:aws:sqs:us-east-1:300000001102:orders-queue exists but is not declared by the document. (broker: sqs:arn:aws:sqs:us-east-1:300000001102:orders-queue)
Drift: 0 changed · 1 unmanaged · 1 missing (drift) — 3 matched

Two documents (exit 0)

$ kurkik sns diff staging.yaml prod.yaml --consumers
staging.yaml vs prod.yaml
AsyncAPI 3.0.0
Drift: 0 changed · 0 unmanaged · 0 missing (no drift) — 3 matched

Download the JSON report (-o json)

staging.yaml
asyncapi: 3.0.0
info:
title: topics-staging Amazon SNS API
version: 1.0.0-SNAPSHOT
description: Generated by reading Amazon SNS of topics-staging (us-east-1).
servers:
sns:
host: localhost:14566
protocol: amazon-sns
description: Amazon SNS in us-east-1.
channels:
orders:
address: orders
bindings:
sns:
bindingVersion: 0.1.0
name: orders
ordering:
type: standard
payments:
address: payments
bindings:
sns:
bindingVersion: 0.1.0
name: payments
ordering:
type: standard
operations:
receive_from_orders:
action: receive
channel:
$ref: "#/channels/orders"
description: Subscriptions of orders when this document was generated.
bindings:
sns:
bindingVersion: 0.1.0
consumers:
- protocol: sqs
endpoint:
arn: arn:aws:sqs:us-east-1:300000001101:orders-queue
rawMessageDelivery: true

Download staging.yaml

prod.yaml
asyncapi: 3.0.0
info:
title: topics-prod Amazon SNS API
version: 1.0.0-SNAPSHOT
description: Generated by reading Amazon SNS of topics-prod (us-east-1).
servers:
sns:
host: localhost:14566
protocol: amazon-sns
description: Amazon SNS in us-east-1.
channels:
orders:
address: orders
bindings:
sns:
bindingVersion: 0.1.0
name: orders
ordering:
type: standard
payments:
address: payments
bindings:
sns:
bindingVersion: 0.1.0
name: payments
ordering:
type: standard
operations:
receive_from_orders:
action: receive
channel:
$ref: "#/channels/orders"
description: Subscriptions of orders when this document was generated.
bindings:
sns:
bindingVersion: 0.1.0
consumers:
- protocol: sqs
endpoint:
arn: arn:aws:sqs:us-east-1:300000001102:orders-queue
rawMessageDelivery: true

Download prod.yaml

How to build this setup yourself

topics-staging

Terminal window
awslocal sqs create-queue --queue-name orders-queue
awslocal sqs create-queue --queue-name orders-dlq
awslocal sns create-topic --name orders
awslocal sns subscribe --topic-arn arn:aws:sns:us-east-1:300000001101:orders --protocol sqs --notification-endpoint arn:aws:sqs:us-east-1:300000001101:orders-queue --return-subscription-arn
awslocal sns set-subscription-attributes --subscription-arn arn:aws:sns:us-east-1:300000001101:orders:6ff9792b-141a-4417-8ada-ca264c550fbb --attribute-name RawMessageDelivery --attribute-value true
awslocal sns create-topic --name payments

topics-prod

Terminal window
awslocal sqs create-queue --queue-name orders-queue
awslocal sqs create-queue --queue-name orders-dlq
awslocal sns create-topic --name orders
awslocal sns subscribe --topic-arn arn:aws:sns:us-east-1:300000001102:orders --protocol sqs --notification-endpoint arn:aws:sqs:us-east-1:300000001102:orders-queue --return-subscription-arn
awslocal sns set-subscription-attributes --subscription-arn arn:aws:sns:us-east-1:300000001102:orders:ba4699a6-7e08-4c67-b720-700dadefe037 --attribute-name RawMessageDelivery --attribute-value true
awslocal sns create-topic --name payments

All flags: kurkik sns diff · more Amazon SNS diff examples