forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsns.py
45 lines (34 loc) · 1.15 KB
/
sns.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
from datetime import datetime
from typing import Dict, List, Optional
from pydantic import BaseModel, root_validator
from pydantic.networks import HttpUrl
from ..types import Literal
class SnsMsgAttributeModel(BaseModel):
Type: str
Value: str
class SnsNotificationModel(BaseModel):
Subject: Optional[str]
TopicArn: str
UnsubscribeUrl: HttpUrl
Type: Literal["Notification"]
MessageAttributes: Optional[Dict[str, SnsMsgAttributeModel]]
Message: str
MessageId: str
SigningCertUrl: HttpUrl
Signature: str
Timestamp: datetime
SignatureVersion: str
@root_validator(pre=True)
def check_sqs_protocol(cls, values):
sqs_rewritten_keys = ("UnsubscribeURL", "SigningCertURL")
if any(key in sqs_rewritten_keys for key in values):
values["UnsubscribeUrl"] = values.pop("UnsubscribeURL")
values["SigningCertUrl"] = values.pop("SigningCertURL")
return values
class SnsRecordModel(BaseModel):
EventSource: Literal["aws:sns"]
EventVersion: str
EventSubscriptionArn: str
Sns: SnsNotificationModel
class SnsModel(BaseModel):
Records: List[SnsRecordModel]