forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkinesis_firehose.py
32 lines (23 loc) · 926 Bytes
/
kinesis_firehose.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
from typing import List, Optional, Type, Union
from pydantic import BaseModel, PositiveInt, validator
from aws_lambda_powertools.shared.functions import base64_decode
class KinesisFirehoseRecordMetadata(BaseModel):
shardId: str
partitionKey: str
approximateArrivalTimestamp: PositiveInt
sequenceNumber: str
subsequenceNumber: str
class KinesisFirehoseRecord(BaseModel):
data: Union[bytes, Type[BaseModel]] # base64 encoded str is parsed into bytes
recordId: str
approximateArrivalTimestamp: PositiveInt
kinesisRecordMetadata: Optional[KinesisFirehoseRecordMetadata]
@validator("data", pre=True, allow_reuse=True)
def data_base64_decode(cls, value):
return base64_decode(value)
class KinesisFirehoseModel(BaseModel):
invocationId: str
deliveryStreamArn: str
region: str
sourceKinesisStreamArn: Optional[str]
records: List[KinesisFirehoseRecord]