Skip to content

fix(data_classes): read SNS messages delivered to SQS in SNSMessage - #8914

Open
hyeonsang010716 wants to merge 1 commit into
aws-powertools:developfrom
hyeonsang010716:fix/sns-message-sqs-payload
Open

hyeonsang010716 wants to merge 1 commit into
aws-powertools:developfrom
hyeonsang010716:fix/sns-message-sqs-payload

Conversation

@hyeonsang010716

Copy link
Copy Markdown
Contributor

Issue number: closes #8913

Summary

Changes

SQSRecord.decoded_nested_sns_event returns an SNSMessage, but SNSMessage only read the keys of the Lambda SNS event. The SNS message in an SQS body uses UnsubscribeURL and SigningCertURL, leaves out Subject and MessageAttributes when they are not set, and has no signature fields for FIFO topics with content-based deduplication, so those properties raised KeyError.

  • unsubscribe_url and signing_cert_url read both key spellings.
  • subject, signature, signature_version and signing_cert_url return None when the key is missing, and are now typed str | None. The parser model already has all four as optional.
  • message_attributes returns an empty dict when the key is missing.
  • This matches the optional fields of the SnsNotificationModel parser model.
  • Added tests that read these properties from the existing snsSqsEvent.json and snsSqsFifoEvent.json fixtures.

User experience

Before: record.decoded_nested_sns_event.unsubscribe_url raises KeyError: 'UnsubscribeUrl' on an SNS message delivered to SQS, and the same happens for signing_cert_url, subject and message_attributes, plus signature and signature_version for FIFO topics.

After: they return the values from the SQS payload, or None and {} when the field is not there. SNSEvent returns the same values as before.

Verification

The two new tests fail on develop with KeyError: 'UnsubscribeUrl' and KeyError: 'Signature', and pass with this change. The existing test_sns_trigger_event still passes.

Tested locally on Python 3.14 with the full pytest -m "not perf" --ignore tests/e2e, ruff format --check, ruff check, mypy and ty. Two logger tests (test_append_context_keys_handles_empty_dict, test_log_dict_key_strip_nones) fail in the full run on develop as well and pass on their own, so they are unrelated to this change.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

SQSRecord.decoded_nested_sns_event returns an SNSMessage, but
SNSMessage only read the keys of the Lambda SNS event. When SNS delivers
to SQS it sends UnsubscribeURL and SigningCertURL, leaves out Subject and
MessageAttributes when they are not set, and FIFO topics with
content-based deduplication send no Signature, SignatureVersion or
SigningCertURL. Those properties raised KeyError.

Read both key spellings, return None for the fields that can be missing
and an empty dict for missing message attributes, matching the
SnsNotificationModel parser model.
@hyeonsang010716
hyeonsang010716 requested a review from a team as a code owner November 26, 2026 00:28
@boring-cyborg boring-cyborg Bot added the tests label Nov 26, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 26, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: SQSRecord.decoded_nested_sns_event raises KeyError on SNS messages delivered to SQS

1 participant