2
2
from urllib .parse import unquote_plus
3
3
4
4
from aws_lambda_powertools .utilities .data_classes .common import DictWrapper
5
+ from aws_lambda_powertools .utilities .data_classes .event_bridge_event import (
6
+ EventBridgeEvent ,
7
+ )
5
8
6
9
7
10
class S3Identity (DictWrapper ):
@@ -16,6 +19,138 @@ def source_ip_address(self) -> str:
16
19
return self ["requestParameters" ]["sourceIPAddress" ]
17
20
18
21
22
+ class S3EventNotificationEventBridgeBucket (DictWrapper ):
23
+ @property
24
+ def name (self ) -> str :
25
+ return self ["name" ]
26
+
27
+
28
+ class S3EventBridgeNotificationObject (DictWrapper ):
29
+ @property
30
+ def key (self ) -> str :
31
+ """Object key"""
32
+ return unquote_plus (self ["key" ])
33
+
34
+ @property
35
+ def size (self ) -> str :
36
+ """Object size"""
37
+ return self ["size" ]
38
+
39
+ @property
40
+ def etag (self ) -> str :
41
+ """Object etag"""
42
+ return self ["etag" ]
43
+
44
+ @property
45
+ def version_id (self ) -> str :
46
+ """Object version ID"""
47
+ return self ["version-id" ]
48
+
49
+ @property
50
+ def sequencer (self ) -> str :
51
+ """Object key"""
52
+ return self ["sequencer" ]
53
+
54
+
55
+ class S3EventBridgeNotificationDetail (DictWrapper ):
56
+ @property
57
+ def version (self ) -> str :
58
+ """Get the detail version"""
59
+ return self ["version" ]
60
+
61
+ @property
62
+ def bucket (self ) -> S3EventNotificationEventBridgeBucket :
63
+ """Get the bucket name for the S3 notification"""
64
+ return S3EventNotificationEventBridgeBucket (self ["bucket" ])
65
+
66
+ @property
67
+ def object (self ) -> S3EventBridgeNotificationObject : # noqa: A003 # ignore shadowing built-in grammar
68
+ """Get the request-id for the S3 notification"""
69
+ return S3EventBridgeNotificationObject (self ["object" ])
70
+
71
+ @property
72
+ def request_id (self ) -> str :
73
+ """Get the request-id for the S3 notification"""
74
+ return self ["request-id" ]
75
+
76
+ @property
77
+ def requester (self ) -> str :
78
+ """Get the AWS account ID or AWS service principal of requester for the S3 notification"""
79
+ return self ["requester" ]
80
+
81
+ @property
82
+ def source_ip_address (self ) -> Optional [str ]:
83
+ """Get the source IP address of S3 request. Only present for events triggered by an S3 request."""
84
+ return self .get ("source-ip-address" )
85
+
86
+ @property
87
+ def reason (self ) -> Optional [str ]:
88
+ """Get the reason for the S3 notification.
89
+
90
+ For 'Object Created events', the S3 API used to create the object: `PutObject`, `POST Object`, `CopyObject`, or
91
+ `CompleteMultipartUpload`. For 'Object Deleted' events, this is set to `DeleteObject` when an object is deleted
92
+ by an S3 API call, or 'Lifecycle Expiration' when an object is deleted by an S3 Lifecycle expiration rule.
93
+ """
94
+ return self .get ("reason" )
95
+
96
+ @property
97
+ def deletion_type (self ) -> Optional [str ]:
98
+ """Get the deletion type for the S3 object in this notification.
99
+
100
+ For 'Object Deleted' events, when an unversioned object is deleted, or a versioned object is permanently deleted
101
+ this is set to 'Permanently Deleted'. When a delete marker is created for a versioned object, this is set to
102
+ 'Delete Marker Created'.
103
+ """
104
+ return self .get ("deletion-type" )
105
+
106
+ @property
107
+ def restore_expiry_time (self ) -> Optional [str ]:
108
+ """Get the restore expiry time for the S3 object in this notification.
109
+
110
+ For 'Object Restore Completed' events, the time when the temporary copy of the object will be deleted from S3.
111
+ """
112
+ return self .get ("restore-expiry-time" )
113
+
114
+ @property
115
+ def source_storage_class (self ) -> Optional [str ]:
116
+ """Get the source storage class of the S3 object in this notification.
117
+
118
+ For 'Object Restore Initiated' and 'Object Restore Completed' events, the storage class of the object being
119
+ restored.
120
+ """
121
+ return self .get ("source-storage-class" )
122
+
123
+ @property
124
+ def destination_storage_class (self ) -> Optional [str ]:
125
+ """Get the destination storage class of the S3 object in this notification.
126
+
127
+ For 'Object Storage Class Changed' events, the new storage class of the object.
128
+ """
129
+ return self .get ("destination-storage-class" )
130
+
131
+ @property
132
+ def destination_access_tier (self ) -> Optional [str ]:
133
+ """Get the destination access tier of the S3 object in this notification.
134
+
135
+ For 'Object Access Tier Changed' events, the new access tier of the object.
136
+ """
137
+ return self .get ("destination-access-tier" )
138
+
139
+
140
+ class S3EventBridgeNotificationEvent (EventBridgeEvent ):
141
+ """Amazon S3EventBridge Event
142
+
143
+ Documentation:
144
+ --------------
145
+ - https://docs.aws.amazon.com/AmazonS3/latest/userguide/ev-events.html
146
+ """
147
+
148
+ @property
149
+ def detail (self ) -> S3EventBridgeNotificationDetail : # type: ignore[override]
150
+ """S3 notification details"""
151
+ return S3EventBridgeNotificationDetail (self ["detail" ])
152
+
153
+
19
154
class S3Bucket (DictWrapper ):
20
155
@property
21
156
def name (self ) -> str :
0 commit comments