Bug: SQSRecord.decoded_nested_sns_event raises KeyError on SNS messages delivered to SQS
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 79/100
Rechercherichtung
Lies zuerst SNSMessage und den vorhandenen Test test_decode_nested_sns_event und prüfe anschließend tests/events/snsSqsEvent.json und tests/events/snsSqsFifoEvent.json. Ergänze Tests für die aufgeführten optionalen Eigenschaften und alternativen Schreibweisen der Schlüssel und verwende das im Issue vorgeschlagene Verhalten als erwartetes Ergebnis. Fertig ist die Arbeit, wenn die Tests bestätigen, dass über SQS zugestellte SNS-Nachrichten diese Eigenschaften ohne KeyError bereitstellen, während die Werte von Lambda SNS-Ereignissen unverändert bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Expected Behaviour
SQSRecord.decoded_nested_sns_event returns an SNSMessage whose properties work on the message SNS sends to SQS, the same way the SnsNotificationModel parser model and SnsSqsEnvelope already handle it (#272, #1299, #1606).
Current Behaviour
SNSMessage only reads the keys of the Lambda SNS event (Records[].Sns). The SNS message in an SQS body is different:
- It uses
UnsubscribeURLandSigningCertURLinstead ofUnsubscribeUrlandSigningCertUrl, as in the SNS to SQS example. - It leaves out
SubjectandMessageAttributeswhen they are not set. - For FIFO topics with content-based deduplication it has no
Signature,SignatureVersionorSigningCertURL(payload in #1590).
So unsubscribe_url, signing_cert_url, subject and message_attributes raise KeyError on tests/events/snsSqsEvent.json, and signature and signature_version also raise on tests/events/snsSqsFifoEvent.json. The existing test_decode_nested_sns_event doesn't read these properties.
Code snippet
import json
from aws_lambda_powertools.utilities.data_classes import SQSEvent
# Body of an SQS message that an SNS topic delivered (raw message delivery disabled)
sns_body = {
"Type": "Notification",
"MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
"TopicArn": "arn:aws:sns:eu-west-1:123456789012:orders",
"Message": "hello world",
"Timestamp": "2026-11-26T10:00:00.000Z",
"SignatureVersion": "1",
"Signature": "EXAMPLEpH+..",
"SigningCertURL": "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-0000000000000000000000.pem",
"UnsubscribeURL": "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:123456789012:orders:0000",
}
event = SQSEvent({"Records": [{"messageId": "1", "body": json.dumps(sns_body), "eventSource": "aws:sqs"}]})
sns_message = next(event.records).decoded_nested_sns_event
for prop in ("unsubscribe_url", "signing_cert_url", "subject", "message_attributes"):
try:
print(f"{prop}: {getattr(sns_message, prop)!r}")
except KeyError as exc:
print(f"{prop}: KeyError {exc}")
Output:
unsubscribe_url: KeyError 'UnsubscribeUrl'
signing_cert_url: KeyError 'SigningCertUrl'
subject: KeyError 'Subject'
message_attributes: KeyError 'MessageAttributes'
Possible Solution
In SNSMessage, read both spellings for unsubscribe_url and signing_cert_url, return None from subject, signature, signature_version and signing_cert_url when the key is missing, and an empty dict from message_attributes. This matches the optional fields of SnsNotificationModel. The Lambda SNS event keeps returning the same values.
Steps to Reproduce
- Subscribe an SQS queue to an SNS topic, with raw message delivery disabled.
- Read
record.decoded_nested_sns_event.unsubscribe_urlin a Lambda function triggered by the queue, or run the snippet above. - It raises
KeyError: 'UnsubscribeUrl'.
Did you run the reproduction yourself?
Yes, I ran it and saw the failure
Powertools for AWS Lambda (Python) version
3.41.0
AWS Lambda function runtime
3.14
Packaging format used
PyPi
Debugging logs
- Vorherrschende Sprache
- Python
- Sterne
- 3.3k
- Forks
- 511
- Ø Merge
- 2 T. 23 Std.
- Gemergte PRs (30 T.)
- 50
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus aws-powertools/powertools-lambda-python
-
Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mappingOffenbug triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
aws-powertools/powertools-lambda-python#8948 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Docs: child Logger without a parent uses the root log level since #8842Evtl. vergeben @rdxrahul12 hat das heute übernommen. Offendocumentation triage
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8935 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Set-Cookie values passed as a header are comma-joined into one invalid header on HTTP API and Function URL responsesEvtl. vergeben @saquibjawedbit hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aws-powertools/powertools-lambda-python#8921 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: validate() raises raw jmespath ParseError instead of InvalidEnvelopeExpressionError for most malformed envelopesEvtl. vergeben @0x5t4l1n hat das heute übernommen. Offenbug triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
aws-powertools/powertools-lambda-python#8918 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug: Metrics keeps dimensions and metadata from an invocation that added no metricsEvtl. vergeben @hyeonsang010716 hat das vor 7 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
aws-powertools/powertools-lambda-python#8911 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in aws-powertools/powertools-lambda-python
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
litestar-org/sqlspec#946 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area:cli area:docs Platform vdr
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
NVIDIA-NeMo/Gym#7192 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
SofyaBotOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
[Resource]: DashbarOffenresource-submission validation-passed
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
hesreallyhim/awesome-claude-code#3821 · 1 Kommentar ·
-
bug good first issue help wanted level 1 wocs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
GianlucaBave/murmury#169 ·
Maintainer antworten meist innerhalb von 1 Tag