Bug: S3RecordModel drops lifecycleEventData and replicationEventData

Đang mở Phù hợp với người mới
#8,800 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
aws, python
Lĩnh vực
backend, data

Hướng nghiên cứu

Bắt đầu bằng cách đọc S3RecordModel và các trường dữ liệu của sự kiện lân cận, sau đó kiểm tra tests/events/s3EventLifecycleTransition.json và các bài kiểm thử parser dành cho bản ghi S3. Bổ sung kiểm thử để xác nhận cả hai trường dữ liệu sự kiện được giữ nguyên, bao gồm một mẫu sao chép phù hợp. Hoàn tất khi việc phân tích sự kiện S3 và S3-to-SQS giữ nguyên dữ liệu và các bài kiểm thử liên quan đều thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
3.3k
Fork
511
Merge trung bình
3 ngày 8 giờ
Pull request đã merge (30 ngày)
103

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aws-powertools/powertools-lambda-python

Tất cả issue của aws-powertools/powertools-lambda-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.