Post

Moving Amazon SQS to a New Account Without Losing Dead-Letter Queues

Amazon SQS migration check: export queues with dead-letter redrive policies, visibility timeouts, FIFO and encryption settings into an AsyncAPI document, then compare two AWS accounts

Moving Amazon SQS to a New Account Without Losing Dead-Letter Queues

Queues look identical until something fails:

  • 🪦 Dead-letter queues: no redrive policy means a poison message loops until it expires
  • ⏱️ Visibility timeout: too short, and the same message is processed twice
  • 📦 FIFO settings, retention, delays, encryption
  • 🔐 Access policies: who may send
1
curl -fsSL https://kurkik.pavelon.dev/install.sh | sh

Note: Kurkik doesn’t create SQS resources. sync exists for Kafka and Pulsar. For SQS it writes down what you have and tells you what differs

The scenario

The demo sandbox, running on LocalStack 4.9 (not real AWS): queues-staging is the account that has it right, queues-prod is the other one

Step 1: write the source account down

1
kurkik sqs export queues-staging

The servers and channels parts keep the region, each queue’s settings and its dead-letter queue:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
servers:
  sqs:
    host: localhost:14566
    protocol: amazon-sqs
    description: Amazon SQS in us-east-1.
channels:
  # ... other queues ...
  orders-queue:
    address: orders-queue
    bindings:
      sqs:
        bindingVersion: 0.2.0
        queue:
          name: orders-queue
          fifoQueue: false
          deliveryDelay: 0
          visibilityTimeout: 30
          receiveMessageWaitTime: 0
          messageRetentionPeriod: 345600
          redrivePolicy:
            deadLetterQueue:
              name: orders-dlq
            maxReceiveCount: 5
    x-sqs-attributes:
      MaximumMessageSize: 1048576
      SqsManagedSseEnabled: true

What is not in there: access policies, the DLQ’s redrive allow policy and message schemas

Step 2: look for yourself

1
kurkik sqs scan queues-prod --acls
1
2
3
4
5
6
7
8
9
10
11
queues-prod - Amazon SQS, as arn:aws:iam::222222222222:root
queues (4)
  audit-queue  visibility 30s, retention 4d, sse
    policy allow * sqs:SendMessage  open to anyone
  orders-dlq  visibility 30s, retention 4d, sse
    policy: none
  orders-events.fifo  fifo, visibility 30s, retention 4d, kms
    policy: none
  orders-queue  visibility 60s, retention 4d, sse
    dead letters -> orders-dlq after 3 receive(s)
    policy allow Service sns.amazonaws.com sqs:SendMessage when ArnEquals aws:SourceArn = arn:aws:sns:us-east-1:222222222222:orders

open to anyone is worth a second look before you copy it anywhere. To see the redrive allow policy and every other attribute, add --details

1
kurkik sqs diff queues-staging queues-prod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
queues-staging vs queues-prod
Amazon SQS queues-prod

Channels
  + audit-queue address — Queue audit-queue is not on queues-staging. (queues-prod: audit-queue)

Channel bindings
  ~ orders-queue visibilityTimeout — visibilityTimeout differs. (queues-staging: 30, queues-prod: 60)
  ~ orders-queue redrivePolicy.maxReceiveCount — redrivePolicy.maxReceiveCount differs. (queues-staging: 5, queues-prod: 3)

Notes
  - Queues-staging is account 111111111111 and queues-prod is account 222222222222; ARNs are compared by the name they end in.

Drift: 2 changed · 1 unmanaged · 0 missing (drift) — 25 matched

Terminal recording: kurkik sqs diff between two accounts

Same queue name, different behaviour: messages stay hidden twice as long, and go to the dead-letter queue after 3 tries, not 5

Step 3: fix with your tooling, then check again

Change the new account with Terraform, CloudFormation, CDK or whatever you use, and run the diff again. It exits 2 on drift, so a pipeline can stop there

Compare account to account. Today, comparing two exported documents can miss setting differences that comparing the two connections reports

The whole document

The whole document: queues-staging-sqs.yaml (65 lines)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
asyncapi: 3.0.0
info:
  title: queues-staging Amazon SQS API
  version: 1.0.0-SNAPSHOT
  description: Generated by reading Amazon SQS of queues-staging (us-east-1).
servers:
  sqs:
    host: localhost:14566
    protocol: amazon-sqs
    description: Amazon SQS in us-east-1.
channels:
  orders-dlq:
    address: orders-dlq
    bindings:
      sqs:
        bindingVersion: 0.2.0
        queue:
          name: orders-dlq
          fifoQueue: false
          deliveryDelay: 0
          visibilityTimeout: 30
          receiveMessageWaitTime: 0
          messageRetentionPeriod: 345600
    x-sqs-attributes:
      MaximumMessageSize: 1048576
      SqsManagedSseEnabled: true
  orders-events.fifo:
    address: orders-events.fifo
    bindings:
      sqs:
        bindingVersion: 0.2.0
        queue:
          name: orders-events.fifo
          fifoQueue: true
          deduplicationScope: queue
          fifoThroughputLimit: perQueue
          deliveryDelay: 0
          visibilityTimeout: 30
          receiveMessageWaitTime: 0
          messageRetentionPeriod: 345600
    x-sqs-attributes:
      ContentBasedDeduplication: false
      KmsMasterKeyId: alias/aws/sqs
      MaximumMessageSize: 1048576
      SqsManagedSseEnabled: true
  orders-queue:
    address: orders-queue
    bindings:
      sqs:
        bindingVersion: 0.2.0
        queue:
          name: orders-queue
          fifoQueue: false
          deliveryDelay: 0
          visibilityTimeout: 30
          receiveMessageWaitTime: 0
          messageRetentionPeriod: 345600
          redrivePolicy:
            deadLetterQueue:
              name: orders-dlq
            maxReceiveCount: 5
    x-sqs-attributes:
      MaximumMessageSize: 1048576
      SqsManagedSseEnabled: true
operations: {}

Other situations

Questions people ask

Can Kurkik create the queues in the new account?

No. Sync exists for Apache Kafka and Apache Pulsar only. For SQS, create the queues with your own tooling and let Kurkik compare the two accounts

Are messages moved?

No. Kurkik reads configuration. It does not receive, send or move messages

Are queue access policies compared?

No. kurkik sqs diff does not compare access policies. Look at both accounts with kurkik sqs scan <connection> --acls

The series

One post per system Kurkik reads:

  1. Moving Apache Kafka
  2. Moving Apache Pulsar
  3. Moving Amazon SNS
  4. Amazon SQS (you are here)
This post is licensed under CC BY 4.0 by the author.