sns
Lambda event
- class awsmate.sns.LambdaMessageEvent(event_object: dict)
Bases:
LambdaEventMapping of the input event received by an AWS Lambda function triggered by AWS SNS.
- Parameters:
event_object (dict) – The parameter
eventreceived by the AWS Lambda function handler.- Raises:
TypeError – If
event_objectis not adict.
Examples
>>> def lambda_handler(raw_event, context): >>> from awsmate.sns import LambdaMessageEvent >>> event = LambdaMessageEvent(raw_event)
- event_subscription_arn() str
Returns the arn of the subscription that led this message to be sent.
- Returns:
The arn of the SNS subscription.
- Return type:
str
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving this subscription arn.
Examples
>>> event.event_subscription_arn() 'arn:aws:sns:eu-west-1:123456789012:sns-lambda:aabbccdd-1122-eeff-3344-a1b2c3d4e5f6'
- unsubscribe_url() str
Returns the unsubscription URL of the subscription that led this message to be sent.
- Returns:
The unsubscription URL.
- Return type:
str
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving this URL.
Examples
>>> event.unsubscribe_url() 'https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:123456789012:your-lambda:aabbccdd-1122-eeff-3344-a1b2c3d4e5f6'
- topic_arn() str
Returns the arn of the topic this message belongs to.
- Returns:
The arn of the SNS topic.
- Return type:
str
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving this topic arn.
Examples
>>> event.topic_arn() 'arn:aws:sns:eu-west-1:123456789012:sns-lambda'
- signature() str
Returns the signature of the message.
- Returns:
The signature of the message.
- Return type:
str
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving this signature.
Examples
>>> event.signature() 'On1AdgZdIdWOHBltcSQCLuy+mE/Nozp9QHYGXSHVjhwZbXEkAi7svphPzaM='
- signing_cert_url() str
Returns the URL of the certificate that allows checking the signature of this message.
- Returns:
The signature of the message.
- Return type:
str
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving this URL.
Examples
>>> event.signing_cert_url() 'https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-aa11bb22cc33dd44ee55ff66ee55dd44.pem'
See also
- message_id() str
Returns the unique identifier of the message.
- Returns:
The id of the message.
- Return type:
str
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving this identifier.
Examples
>>> event.message_id() 'a1b2c3d4-e5f6-aa11-bb22-f6e5d4c3b2a4'
- subject() str | None
Returns the subject of the message if any.
- Returns:
The subject of the message or
Noneif omitted.- Return type:
str
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving this subject.
Examples
>>> event.message_subject() 'Some subject'
- message() str
Returns the content of the message.
- Returns:
The content of the message.
- Return type:
str
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving this content.
Examples
>>> event.message() 'some text'
- message_type() str
Returns the type of the message.
This type is returned as transmitted by AWS SNS. No verification is performed.
- Returns:
The type of the message.
- Return type:
str
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving this type.
Examples
>>> event.message_type() 'Notification'
- message_attributes() dict
Returns the attributes of the message, if any.
Attributes must comply to the AWS SNS attributes specifications. Binary values are decoded from base-64 to binary strings.
- Returns:
The attributes of the message, which is empty if no attribute is specified.
- Return type:
dict
- Raises:
awsmate.lambdafunction.AwsEventSpecificationError – If the event structure does not allow retrieving such attributes or if their do not comply to AWS SNS attributes specifications.
Examples
>>> event.message_attributes() {'AttributeName': {'Type': 'String', 'Value': 'Some text'}, 'OtherAttributeName': {'Type': 'Binary', 'Value': b'Some decoded binary'}}