Skip to content

SQS: SendMessage does not enforce MaximumMessageSize #454

Closed

Description

@scttfrdmn

What

No length check exists against a queue's MaximumMessageSize attribute, or against any constant, anywhere in the SendMessage path. A body larger than the queue's limit is accepted and delivered.

Real SQS rejects it. Per the SendMessage reference the error is:

InvalidParameterValue (or InvalidMessageContents / oversized-message error — confirm the exact code against the current API reference before implementing)

So a consumer's too-large-payload branch — chunking, compressing, spilling to S3 — is unreachable, and any test of it passes while verifying nothing. This is the recurring shape: substrate returns success where real AWS signals failure.

Relation to #439

#439 corrected the reported default (256 KiB → 1 MiB) and deliberately stopped there: enforcement is a new error path with its own scope, and adding it alongside a default change would have conflated two observable behaviours in one release. v0.84.0 documents the absence in docs/services.md rather than leaving it implicit. This issue is the enforcement half.

Acceptance criteria

  • Confirm the exact error code and message against the current SendMessage API reference — do not assume.
  • SendMessage with a body exceeding the queue's effective MaximumMessageSize fails with that code, HTTP 400.
  • "Effective" means resolved through the default when the attribute is unset, so a bare queue enforces 1 MiB — reusing the same constant as SQS: MaximumMessageSize default is 256 KiB, AWS documents 1 MiB #439, not a second copy.
  • A queue created with an explicit smaller MaximumMessageSize enforces that value.
  • Size is measured the way AWS measures it: confirm whether message attributes count toward the total, and cover it.
  • SendMessageBatch: confirm whether the limit applies per-message or to the batch total, and cover both.
  • A body exactly at the limit is accepted — the boundary is inclusive.
  • Both the query and JSON protocols.
  • docs/services.md replaces the "does not enforce" note with the enforced behaviour.

Activity

  1. added this to the v0.85.0 milestone on Aug 1, 2026
  2. scttfrdmn commented on Aug 1, 2026

    @scttfrdmn
    OwnerAuthor

    Shipped in #462 — SendMessage and SendMessageBatch now enforce the limit. Three things worth carrying back, one of which is the answer to this issue's first acceptance criterion and two of which the issue didn't anticipate.

    The error code is not in the API reference at all

    The criterion was "confirm the exact error code and message against the current SendMessage API reference — do not assume." Taken literally, that's the finding: the reference declares no oversized-message error. SendMessage's error list has no entry for it; its InvalidMessageContents is documented as a character-set error, not a length one; and BatchRequestTooLong is declared only on SendMessageBatch. So the code could not be derived from the model, and the issue's own hedge — "InvalidParameterValue (or InvalidMessageContents…)" — could not be settled by the route it proposed.

    What substrate emits, and where it comes from:

    Code HTTP Wire message
    Per-message InvalidParameterValue 400 One or more parameters are invalid. Reason: Message must be shorter than N bytes.
    Batch total BatchRequestTooLong 400 Batch requests cannot be longer than N bytes. You have sent M bytes.

    Both are transcribed from real-AWS responses captured in consumer bug reports — artilleryio/artillery#3463 for the per-message case, aws/aws-sdk-go-v2#3026 for the batch case. Independent reimplementations emit the same strings, which corroborates them as AWS's own wording rather than one project's invention. That's weaker evidence than a doc citation, so the code comment, CHANGELOG and docs/services.md all say so explicitly rather than implying a reference exists.

    Message attributes count toward the size

    Listed here as an open question; the answer is yes. AWS: "all components of a message attribute are included in the 1 MiB message size restriction." Substrate measures name + data type + value, each as UTF-8 bytes, with a binary value counted at its raw length, not its base64 length — a 780-byte binary attribute is 780 bytes, not 1040. Message system attributes are excluded, per the same page.

    This matters for your reproduction: a body sized just under the limit plus any attribute now fails where it previously succeeded. If you have a test asserting a near-limit body is accepted, check whether it also sets attributes.

    A single oversized batch entry reports BatchRequestTooLong, not the per-message error

    The issue treated the batch limit as one number. It's two — each entry against the queue's MaximumMessageSize, and the combined payload against the request cap — and on a default queue they are the same number (AWS: the two limits "are both 1 MiB"). So one oversized entry breaches the total as well, and real AWS reports BatchRequestTooLong for it. Substrate checks the total first to match. If you're asserting on the per-message code from a batch call, you'll want BatchRequestTooLong there.

    Neither limit lowers the other: a queue with MaximumMessageSize=1024 still accepts a batch of ten 1 KiB entries, because the attribute is documented as a per-message cap and does not shrink the request payload cap.

    Other behaviour you can rely on

    • The limit is the queue's, not a constant. Read through the same getAttrOrDefault call GetQueueAttributes uses, so the reported and enforced numbers cannot diverge — set MaximumMessageSize=1024 and 1025 bytes is rejected. The error message names your queue's limit, not the default.
    • Inclusive boundary — exactly the limit is accepted, limit+1 rejected.
    • A rejected batch enqueues nothing. Both wire protocols size every entry before storing any, so your retry won't duplicate entries that already landed.
    • FIFO: the size check runs ahead of deduplication. A rejected send never records its MessageDeduplicationId, so the corrected retry with the same ID succeeds. The alternative would silently swallow the retry as a duplicate — a worse failure than the one being fixed, because it looks like success.
    • A malformed MaximumMessageSize (non-numeric, 0, negative, empty) falls back to the default rather than to zero, which would reject every message including an empty one.

    Not covered

    Message attributes are parsed for measurement only — substrate still doesn't store or return them on ReceiveMessage. Tracked as #461, so if you round-trip attributes rather than just sizing them, that's the one to watch.

    Releasing as part of v0.85.0.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions