Skip to content

Commit 34a6454

Browse files
committed
feat(parser): add support for S3 IntelligentTiering events
Relates to #7443 S3 IntelligentTiering events use a different structure than standard S3 events - they use 'get_object' as the key name instead of 'object' in the S3 message, and include 'intelligentTieringEventData' field. Changes: - Add S3EventRecordIntelligentTieringEventData model - Update S3Message to support both 'object' and 'get_object' fields - Add intelligentTieringEventData field to S3RecordModel - Update validator to handle both field names
1 parent d04d30f commit 34a6454

File tree

1 file changed

+39
-3
lines changed
  • aws_lambda_powertools/utilities/parser/models

1 file changed

+39
-3
lines changed

aws_lambda_powertools/utilities/parser/models/s3.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ class S3EventRecordGlacierEventData(BaseModel):
4040
)
4141

4242

43+
class S3EventRecordIntelligentTieringEventData(BaseModel):
44+
destinationAccessTier: str = Field(
45+
description="The new access tier for the object. For IntelligentTiering events.",
46+
examples=[
47+
"ARCHIVE_ACCESS",
48+
"DEEP_ARCHIVE_ACCESS",
49+
],
50+
)
51+
52+
4353
class S3Identity(BaseModel):
4454
principalId: str = Field(
4555
description="Amazon identifier of the user, role, account or services who caused the event.",
@@ -178,8 +188,9 @@ class S3Message(BaseModel):
178188
},
179189
],
180190
)
181-
object: S3Object = Field(
182-
description="The S3 object object.",
191+
object: Optional[S3Object] = Field(
192+
default=None,
193+
description="The S3 object object. Used by most S3 event types.",
183194
examples=[
184195
{
185196
"key": "b21b84d653bb07b05b1e6b33684dc11b",
@@ -189,6 +200,20 @@ class S3Message(BaseModel):
189200
},
190201
],
191202
) # noqa: A003
203+
get_object: Optional[S3Object] = Field(
204+
default=None,
205+
alias="get_object",
206+
description="The S3 object object. Used by IntelligentTiering events instead of 'object'.",
207+
examples=[
208+
{
209+
"key": "myobject",
210+
"size": 252294,
211+
"eTag": "4e9270240d7d62d5ee8dbfcb7a7a3279",
212+
"versionId": "tiogA9Ga7Xi49yfJ6lkeTxPYx7ZK75yn",
213+
"sequencer": "0066A8D0E77DE42BC5",
214+
},
215+
],
216+
)
192217

193218

194219
class S3EventNotificationObjectModel(BaseModel):
@@ -449,11 +474,22 @@ class S3RecordModel(BaseModel):
449474
},
450475
],
451476
)
477+
intelligentTieringEventData: Optional[S3EventRecordIntelligentTieringEventData] = Field(
478+
default=None,
479+
description="The Intelligent-Tiering event data object.",
480+
examples=[
481+
{
482+
"destinationAccessTier": "ARCHIVE_ACCESS",
483+
},
484+
],
485+
)
452486

453487
@model_validator(mode="before")
454488
def validate_s3_object(cls, values):
455489
event_name = values.get("eventName")
456-
s3_object = values.get("s3").get("object")
490+
s3_data = values.get("s3")
491+
# IntelligentTiering events use 'get_object' instead of 'object'
492+
s3_object = s3_data.get("object") or s3_data.get("get_object")
457493
if ":Delete" not in event_name and (s3_object.get("size") is None or s3_object.get("eTag") is None):
458494
raise ValueError(
459495
"Size and eTag fields are required for all events except ObjectRemoved:* and LifecycleExpiration:*.",

0 commit comments

Comments
 (0)