Bug: S3RecordModel drops lifecycleEventData and replicationEventData

Ouverte Adaptée aux débutants
#8,800 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
82/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
aws, python
Domaine
backend, data

Piste de recherche

Commencez par lire S3RecordModel et les champs de données des événements voisins, puis examinez tests/events/s3EventLifecycleTransition.json et les tests du parseur pour les enregistrements S3. Ajoutez des tests pour vérifier que les deux champs de données de l’événement sont conservés, avec un exemple de réplication approprié. Le travail est terminé lorsque l’analyse des événements S3 et S3-to-SQS conserve les données et que les tests concernés réussissent.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
Python
Étoiles
3.3k
Forks
511
Merge moyen
3 j 8 h
PR mergées (30 j)
103

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de aws-powertools/powertools-lambda-python

Toutes les issues de aws-powertools/powertools-lambda-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.