@@ -11,8 +11,8 @@ def parse_message_attributes(attrs):
1111
1212class Sns :
1313 def __init__ (self , signature_version : str , timestamp : str , signature : str , signing_cert_url : str ,
14- message_id : str , message : str , subject : str , message_attributes : Dict [str , MessageAttribute ] = None ,
15- type_ : str = None , unsubscribe_url : str = None , topic_arn : str = None ):
14+ message_id : str , message : str , subject : str , message_attributes : Dict [str , MessageAttribute ],
15+ type_ : str , unsubscribe_url : str , topic_arn : str ):
1616 self ._signature_version = signature_version
1717 self ._timestamp = timestamp
1818 self ._signature = signature
@@ -26,19 +26,22 @@ def __init__(self, signature_version: str, timestamp: str, signature: str, signi
2626 self ._topic_arn = topic_arn
2727
2828 @classmethod
29- def from_json (cls , s3 ):
30- message_attributes = parse_message_attributes (s3 ["MessageAttributes" ])
31- return cls (s3 ["SignatureVersion" ],
32- s3 ["Timestamp" ],
33- s3 ["Signature" ],
34- s3 ["SigningCertUrl" ],
35- s3 ["MessageId" ],
36- s3 ["Message" ],
37- s3 ["Subject" ],
29+ def from_json (cls , sns ):
30+ if "MessageAttributes" in sns :
31+ message_attributes = parse_message_attributes (sns ["MessageAttributes" ])
32+ else :
33+ message_attributes = None
34+ return cls (sns ["SignatureVersion" ],
35+ sns ["Timestamp" ],
36+ sns ["Signature" ],
37+ sns ["SigningCertUrl" ],
38+ sns ["MessageId" ],
39+ sns ["Message" ],
40+ sns ["Subject" ],
3841 message_attributes ,
39- s3 ["Type" ],
40- s3 ["UnsubscribeUrl" ],
41- s3 ["TopicArn" ])
42+ sns ["Type" ],
43+ sns ["UnsubscribeUrl" ],
44+ sns ["TopicArn" ])
4245
4346 @property
4447 def signature_version (self ):
0 commit comments