forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.py
82 lines (57 loc) · 2.03 KB
/
s3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, root_validator
from pydantic.fields import Field
from pydantic.networks import IPvAnyNetwork
from pydantic.types import NonNegativeFloat
from aws_lambda_powertools.utilities.parser.types import Literal
class S3EventRecordGlacierRestoreEventData(BaseModel):
lifecycleRestorationExpiryTime: datetime
lifecycleRestoreStorageClass: str
class S3EventRecordGlacierEventData(BaseModel):
restoreEventData: S3EventRecordGlacierRestoreEventData
class S3Identity(BaseModel):
principalId: str
class S3RequestParameters(BaseModel):
sourceIPAddress: IPvAnyNetwork
class S3ResponseElements(BaseModel):
x_amz_request_id: str = Field(None, alias="x-amz-request-id")
x_amz_id_2: str = Field(None, alias="x-amz-id-2")
class S3OwnerIdentify(BaseModel):
principalId: str
class S3Bucket(BaseModel):
name: str
ownerIdentity: S3OwnerIdentify
arn: str
class S3Object(BaseModel):
key: str
size: Optional[NonNegativeFloat]
eTag: Optional[str]
sequencer: str
versionId: Optional[str]
class S3Message(BaseModel):
s3SchemaVersion: str
configurationId: str
bucket: S3Bucket
object: S3Object # noqa: A003,VNE003
class S3RecordModel(BaseModel):
eventVersion: str
eventSource: Literal["aws:s3"]
awsRegion: str
eventTime: datetime
eventName: str
userIdentity: S3Identity
requestParameters: S3RequestParameters
responseElements: S3ResponseElements
s3: S3Message
glacierEventData: Optional[S3EventRecordGlacierEventData]
@root_validator
def validate_s3_object(cls, values):
event_name = values.get("eventName")
s3_object = values.get("s3").object
if "ObjectRemoved" not in event_name:
if s3_object.size is None or s3_object.eTag is None:
raise ValueError("S3Object.size and S3Object.eTag are required for non-ObjectRemoved events")
return values
class S3Model(BaseModel):
Records: List[S3RecordModel]