Skip to content

Commit 8334b2b

Browse files
committed
feat(data-classes): add support for S3 IntelligentTiering events
Relates to #7443 Extends S3Event data classes to handle IntelligentTiering events which use 'get_object' key instead of 'object' in the S3 message. Changes: - Add S3EventRecordIntelligentTieringEventData wrapper class - Update S3Message.get_object() to handle both key names - Update S3Event.object_key to handle both key names - Add intelligent_tiering_event_data property to S3EventRecord
1 parent 34a6454 commit 8334b2b

File tree

1 file changed

+33
-5
lines changed
  • aws_lambda_powertools/utilities/data_classes

1 file changed

+33
-5
lines changed

aws_lambda_powertools/utilities/data_classes/s3_event.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,14 @@ def bucket(self) -> S3Bucket:
215215

216216
@property
217217
def get_object(self) -> S3Object:
218-
"""Get the `object` property as an S3Object"""
219-
# Note: this name conflicts with existing python builtins
220-
return S3Object(self["object"])
218+
"""Get the `object` property as an S3Object
219+
220+
Note: IntelligentTiering events use 'get_object' as the actual key name,
221+
while other S3 events use 'object'. This method handles both cases.
222+
"""
223+
# IntelligentTiering events use 'get_object', others use 'object'
224+
object_data = self.get("get_object") or self["object"]
225+
return S3Object(object_data)
221226

222227

223228
class S3EventRecordGlacierRestoreEventData(DictWrapper):
@@ -242,6 +247,16 @@ def restore_event_data(self) -> S3EventRecordGlacierRestoreEventData:
242247
return S3EventRecordGlacierRestoreEventData(self["restoreEventData"])
243248

244249

250+
class S3EventRecordIntelligentTieringEventData(DictWrapper):
251+
@property
252+
def destination_access_tier(self) -> str:
253+
"""The new access tier for the object.
254+
255+
The intelligentTieringEventData key is only visible for IntelligentTiering events.
256+
"""
257+
return self["destinationAccessTier"]
258+
259+
245260
class S3EventRecord(DictWrapper):
246261
@property
247262
def event_version(self) -> str:
@@ -297,6 +312,12 @@ def glacier_event_data(self) -> S3EventRecordGlacierEventData | None:
297312
item = self.get("glacierEventData")
298313
return None if item is None else S3EventRecordGlacierEventData(item)
299314

315+
@property
316+
def intelligent_tiering_event_data(self) -> S3EventRecordIntelligentTieringEventData | None:
317+
"""The intelligentTieringEventData key is only visible for IntelligentTiering events."""
318+
item = self.get("intelligentTieringEventData")
319+
return None if item is None else S3EventRecordIntelligentTieringEventData(item)
320+
300321

301322
class S3Event(DictWrapper):
302323
"""S3 event notification
@@ -325,5 +346,12 @@ def bucket_name(self) -> str:
325346

326347
@property
327348
def object_key(self) -> str:
328-
"""Get the object key for the first s3 event record and unquote plus"""
329-
return unquote_plus(self["Records"][0]["s3"]["object"]["key"])
349+
"""Get the object key for the first s3 event record and unquote plus
350+
351+
Note: IntelligentTiering events use 'get_object' as the key name,
352+
while other S3 events use 'object'. This method handles both cases.
353+
"""
354+
s3_data = self["Records"][0]["s3"]
355+
# IntelligentTiering events use 'get_object', others use 'object'
356+
object_data = s3_data.get("get_object") or s3_data["object"]
357+
return unquote_plus(object_data["key"])

0 commit comments

Comments
 (0)