Skip to content

SQS: message attributes are measured but not stored or returned #461

Closed

Description

@scttfrdmn

Follow-up to #454.

What

#454 added message-attribute parsing to SendMessage and SendMessageBatch because AWS measures a message's size as the body plus every component of every message attribute — the developer guide is explicit: "All components of a message attribute are included in the 1 MiB message size restriction." Enforcing the limit faithfully therefore required parsing them.

They are parsed for measurement only. Substrate does not store them on the message or return them from ReceiveMessage:

  • SQSMessage.MessageAttributes exists on the type (emulator/sqs_types.go) but is never populated by either send path.
  • receiveMessage has no MessageAttributes / MessageAttributeNames handling at all, so a consumer that sends attributes and reads them back gets nothing.

This is the batch's recurring shape in its quieter register: the call succeeds, and a later read comes back empty. A consumer routing on an attribute (messageType, a trace ID, a tenant discriminator) sees every message fall to its default branch, and their dispatch test passes while verifying nothing.

Scope

  • Store parsed attributes on SQSMessage from both SendMessage and SendMessageBatch, under both protocols.
  • Return them from ReceiveMessage, honoring MessageAttributeNames (including the All / .* wildcard) — attributes are returned only when requested, so returning them unconditionally would be its own infidelity.
  • MD5OfMessageAttributes on the send response, per the digest algorithm the developer guide specifies (sorted by name; length-prefixed name, data type, transport type byte, value).
  • Confirm the ReceiveMessage wire shape for both protocols against the API reference before implementing.

Acceptance criteria

  • Attributes sent under the query protocol (MessageAttribute.N.Name / .Value.DataType / .Value.StringValue / .Value.BinaryValue) round-trip through ReceiveMessage.
  • Same for the JSON protocol.
  • MessageAttributeNames=All returns all; a named subset returns only those; omitting it returns none.
  • Binary attributes round-trip base64-correctly.
  • MD5OfMessageAttributes matches the documented algorithm, verified against a known-good digest.
  • Batch-sent attributes round-trip too.
  • docs/services.md records the behaviour.

Activity

  1. added
    type: feature
    priority: medium
    on Aug 1, 2026
  2. added this to the v0.85.0 milestone on Aug 1, 2026
  3. scttfrdmn commented on Aug 2, 2026

    @scttfrdmn
    OwnerAuthor

    Shipped in v0.85.0 (#465). Your "verified against a known-good digest" criterion is met, and the way it is met is worth reporting, because it holds with no network access — which the test suite requires.

    The digest is verifiable offline

    The algorithm published in the developer guide's Calculating the MD5 message digest for message attributes reproduces three captured real-AWS digests exactly. Those three vectors ship in emulator/sqs_messageattributes_test.go with their provenance, so the test asserts against known-good values rather than against a re-derivation of the implementation. The implementation was checked against them before any of the wiring was written, so they are a check on the code and not a transcription of it.

    Two details are load-bearing, and a reimplementation gets both wrong by default:

    • Binary values hash raw, not base64. Vector 3 digests to 049075255ebc53fb95f7f9f3cedf3c50 from the raw bytes and 5ff413c9dc7bd18abea88ca05643f902 from base64. This is the same raw-vs-encoded distinction SQS: SendMessage does not enforce MaximumMessageSize #454 had to make for size measurement, except here there is a hash to prove which one AWS means.
    • A custom data-type suffix is included in the hash. Number.java.lang.Long hashes as the full 21-byte string, not the 6 bytes of its Number base. Vector 2 does not reproduce without it.

    Also confirmed against a moto test asserting "MD5OfMessageAttributes" not in msg: the field is omitted entirely from a response for a message with no attributes, rather than carrying the MD5 of zero bytes.

    Attributes are returned only for the names you ask for

    Worth flagging because the permissive fix is the trap here. Returning attributes unconditionally would make a consumer's test pass while their production caller — which never sets MessageAttributeNames — reads nothing from real SQS. All the documented selectors work: All and .* for everything, a bare name for one, and the prefix.* form ("all message attributes starting with a prefix, for example bar.*"). A named attribute the message does not carry is absent rather than an error.

    One consequence to be aware of: MD5OfMessageAttributes on a receive is the digest of what was returned, not a replay of the send-time value. So a request naming a subset gets a digest over that subset. Replaying the stored send-time digest would fail a consumer's integrity check on any selective receive; there is a test pinning this.

    Coverage

    Stored and returned on SendMessage, SendMessageBatch and ReceiveMessage, under both the query and JSON protocols. Binary round-trips byte-identically (base64 on the wire in both protocols; the XML path needed explicit encoding, since encoding/json base64s a []byte for free and encoding/xml does not). Attributes survive a redelivery after the visibility timeout. A FIFO dedup hit returns the digest of this request's attributes rather than the original's, so a byte-identical retry's integrity check passes.

    Attribute names are emitted in sorted order. Real SQS promises no order, but a Go map iterates randomly, and one substrate response differing from the next for identical input would break the only property this emulator exists to provide.

    The 10-attribute maximum is still not enforced

    There is a test asserting a 10-attribute message is accepted — the boundary, per your scope note — but an 11th is accepted too. That and the documented attribute-name rules (no AWS./Amazon. prefix, no leading/trailing or consecutive periods, the character set, the 256-character limit) are filed as #472. They are reachable now that attributes are stored, and they hit the same provenance wall #454 and this issue did: the SendMessage Errors section names none of them, so the codes have to be captured rather than guessed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: sqspriority: mediumtype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions