Bug: S3RecordModel drops lifecycleEventData and replicationEventData

Offen Anfängerfreundlich
#8,800 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
82/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
aws, python
Bereich
backend, data

Rechercherichtung

Lies zunächst S3RecordModel und die benachbarten Event-Datenfelder, sieh dir dann tests/events/s3EventLifecycleTransition.json und die Parser-Tests für S3-Datensätze an. Ergänze Tests dafür, dass beide Event-Datenfelder erhalten bleiben, einschließlich eines passenden Replikationsbeispiels. Fertig, wenn das Parsen von S3- und S3-to-SQS-Events die Daten beibehält und die relevanten Tests bestehen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Expected Behaviour

S3RecordModel keeps lifecycleEventData and replicationEventData when S3 sends them, the same way it keeps glacierEventData and intelligentTieringEventData. They hold the main detail of those events, like the storage class an object moved to or why a replication failed. The event message structure docs list both, and there are samples for Lifecycle transition and replication events.

Current Behaviour

The model doesn't declare either key, and Pydantic ignores keys it doesn't know, so these events parse without an error but the data isn't on the parsed record. The repo's own tests/events/s3EventLifecycleTransition.json has lifecycleEventData, and it's gone after parsing. S3SqsEventNotificationModel reuses S3Model, so S3 to SQS events lose it too.

The TypeScript parser added both in aws-powertools/powertools-lambda-typescript#5924.

Code snippet
import json

from aws_lambda_powertools.utilities.parser import parse
from aws_lambda_powertools.utilities.parser.models import S3Model

with open("tests/events/s3EventLifecycleTransition.json") as f:
    event = json.load(f)

print("in event:", "lifecycleEventData" in event["Records"][0])
record = parse(event=event, model=S3Model).Records[0]
print("on parsed record:", "lifecycleEventData" in record.model_dump())
in event: True
on parsed record: False
Possible Solution

Add both as optional fields next to intelligentTieringEventData, with Field(description=...) like the rest of the model:

class S3EventRecordLifecycleTransitionEventData(BaseModel):
    destinationStorageClass: str


class S3EventRecordLifecycleEventData(BaseModel):
    transitionEventData: S3EventRecordLifecycleTransitionEventData


class S3EventRecordReplicationEventData(BaseModel):
    replicationRuleId: str | None = None
    destinationBucket: str | None = None
    s3Operation: str | None = None
    requestTime: str | None = None
    failureReason: str | None = None


# In S3RecordModel
lifecycleEventData: S3EventRecordLifecycleEventData | None = None
replicationEventData: S3EventRecordReplicationEventData | None = None

Every replication field is optional because the docs only show the failed replication event, the same call the TypeScript fix made. This only adds fields, so nothing that parses today changes.

I'm happy to send a PR with tests and a replication fixture if that sounds good.

Steps to Reproduce

Run the snippet above from the repo root. The replication sample from the docs page loses replicationEventData the same way.

Powertools for AWS Lambda (Python) version

3.40.0

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Vorherrschende Sprache
Python
Sterne
3.3k
Forks
511
Ø Merge
3 T. 8 Std.
Gemergte PRs (30 T.)
103

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus aws-powertools/powertools-lambda-python

Alle Issues in aws-powertools/powertools-lambda-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.