Module aws_lambda_powertools.utilities.data_classes.sns_event

Expand source code
from typing import Dict, Iterator

from aws_lambda_powertools.utilities.data_classes.common import DictWrapper


class SNSMessageAttribute(DictWrapper):
    @property
    def get_type(self) -> str:
        """The supported message attribute data types are String, String.Array, Number, and Binary."""
        # Note: this name conflicts with existing python builtins
        return self["Type"]

    @property
    def value(self) -> str:
        """The user-specified message attribute value."""
        return self["Value"]


class SNSMessage(DictWrapper):
    @property
    def signature_version(self) -> str:
        """Version of the Amazon SNS signature used."""
        return self["Sns"]["SignatureVersion"]

    @property
    def timestamp(self) -> str:
        """The time (GMT) when the subscription confirmation was sent."""
        return self["Sns"]["Timestamp"]

    @property
    def signature(self) -> str:
        """Base64-encoded "SHA1withRSA" signature of the Message, MessageId, Type, Timestamp, and TopicArn values."""
        return self["Sns"]["Signature"]

    @property
    def signing_cert_url(self) -> str:
        """The URL to the certificate that was used to sign the message."""
        return self["Sns"]["SigningCertUrl"]

    @property
    def message_id(self) -> str:
        """A Universally Unique Identifier, unique for each message published.

        For a message that Amazon SNS resends during a retry, the message ID of the original message is used."""
        return self["Sns"]["MessageId"]

    @property
    def message(self) -> str:
        """A string that describes the message. """
        return self["Sns"]["Message"]

    @property
    def message_attributes(self) -> Dict[str, SNSMessageAttribute]:
        return {k: SNSMessageAttribute(v) for (k, v) in self["Sns"]["MessageAttributes"].items()}

    @property
    def get_type(self) -> str:
        """The type of message.

        For a subscription confirmation, the type is SubscriptionConfirmation."""
        # Note: this name conflicts with existing python builtins
        return self["Sns"]["Type"]

    @property
    def unsubscribe_url(self) -> str:
        """A URL that you can use to unsubscribe the endpoint from this topic.

        If you visit this URL, Amazon SNS unsubscribes the endpoint and stops sending notifications to this endpoint."""
        return self["Sns"]["UnsubscribeUrl"]

    @property
    def topic_arn(self) -> str:
        """The Amazon Resource Name (ARN) for the topic that this endpoint is subscribed to."""
        return self["Sns"]["TopicArn"]

    @property
    def subject(self) -> str:
        """The Subject parameter specified when the notification was published to the topic."""
        return self["Sns"]["Subject"]


class SNSEventRecord(DictWrapper):
    @property
    def event_version(self) -> str:
        """Event version"""
        return self["EventVersion"]

    @property
    def event_subscription_arn(self) -> str:
        return self["EventSubscriptionArn"]

    @property
    def event_source(self) -> str:
        """The AWS service from which the SNS event record originated. For SNS, this is aws:sns"""
        return self["EventSource"]

    @property
    def sns(self) -> SNSMessage:
        return SNSMessage(self._data)


class SNSEvent(DictWrapper):
    """SNS Event

    Documentation:
    -------------
    - https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html
    """

    @property
    def records(self) -> Iterator[SNSEventRecord]:
        for record in self["Records"]:
            yield SNSEventRecord(record)

    @property
    def record(self) -> SNSEventRecord:
        """Return the first SNS event record"""
        return next(self.records)

    @property
    def sns_message(self) -> str:
        """Return the message for the first sns event record"""
        return self.record.sns.message

Classes

class SNSEvent (data: Dict[str, Any])
Expand source code
class SNSEvent(DictWrapper):
    """SNS Event

    Documentation:
    -------------
    - https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html
    """

    @property
    def records(self) -> Iterator[SNSEventRecord]:
        for record in self["Records"]:
            yield SNSEventRecord(record)

    @property
    def record(self) -> SNSEventRecord:
        """Return the first SNS event record"""
        return next(self.records)

    @property
    def sns_message(self) -> str:
        """Return the message for the first sns event record"""
        return self.record.sns.message

Ancestors

Instance variables

var recordSNSEventRecord

Return the first SNS event record

Expand source code
@property
def record(self) -> SNSEventRecord:
    """Return the first SNS event record"""
    return next(self.records)
var records : Iterator[SNSEventRecord]
Expand source code
@property
def records(self) -> Iterator[SNSEventRecord]:
    for record in self["Records"]:
        yield SNSEventRecord(record)
var sns_message : str

Return the message for the first sns event record

Expand source code
@property
def sns_message(self) -> str:
    """Return the message for the first sns event record"""
    return self.record.sns.message

Inherited members

class SNSEventRecord (data: Dict[str, Any])

Provides a single read only access to a wrapper dict

Expand source code
class SNSEventRecord(DictWrapper):
    @property
    def event_version(self) -> str:
        """Event version"""
        return self["EventVersion"]

    @property
    def event_subscription_arn(self) -> str:
        return self["EventSubscriptionArn"]

    @property
    def event_source(self) -> str:
        """The AWS service from which the SNS event record originated. For SNS, this is aws:sns"""
        return self["EventSource"]

    @property
    def sns(self) -> SNSMessage:
        return SNSMessage(self._data)

Ancestors

Instance variables

var event_source : str

The AWS service from which the SNS event record originated. For SNS, this is aws:sns

Expand source code
@property
def event_source(self) -> str:
    """The AWS service from which the SNS event record originated. For SNS, this is aws:sns"""
    return self["EventSource"]
var event_subscription_arn : str
Expand source code
@property
def event_subscription_arn(self) -> str:
    return self["EventSubscriptionArn"]
var event_version : str

Event version

Expand source code
@property
def event_version(self) -> str:
    """Event version"""
    return self["EventVersion"]
var snsSNSMessage
Expand source code
@property
def sns(self) -> SNSMessage:
    return SNSMessage(self._data)

Inherited members

class SNSMessage (data: Dict[str, Any])

Provides a single read only access to a wrapper dict

Expand source code
class SNSMessage(DictWrapper):
    @property
    def signature_version(self) -> str:
        """Version of the Amazon SNS signature used."""
        return self["Sns"]["SignatureVersion"]

    @property
    def timestamp(self) -> str:
        """The time (GMT) when the subscription confirmation was sent."""
        return self["Sns"]["Timestamp"]

    @property
    def signature(self) -> str:
        """Base64-encoded "SHA1withRSA" signature of the Message, MessageId, Type, Timestamp, and TopicArn values."""
        return self["Sns"]["Signature"]

    @property
    def signing_cert_url(self) -> str:
        """The URL to the certificate that was used to sign the message."""
        return self["Sns"]["SigningCertUrl"]

    @property
    def message_id(self) -> str:
        """A Universally Unique Identifier, unique for each message published.

        For a message that Amazon SNS resends during a retry, the message ID of the original message is used."""
        return self["Sns"]["MessageId"]

    @property
    def message(self) -> str:
        """A string that describes the message. """
        return self["Sns"]["Message"]

    @property
    def message_attributes(self) -> Dict[str, SNSMessageAttribute]:
        return {k: SNSMessageAttribute(v) for (k, v) in self["Sns"]["MessageAttributes"].items()}

    @property
    def get_type(self) -> str:
        """The type of message.

        For a subscription confirmation, the type is SubscriptionConfirmation."""
        # Note: this name conflicts with existing python builtins
        return self["Sns"]["Type"]

    @property
    def unsubscribe_url(self) -> str:
        """A URL that you can use to unsubscribe the endpoint from this topic.

        If you visit this URL, Amazon SNS unsubscribes the endpoint and stops sending notifications to this endpoint."""
        return self["Sns"]["UnsubscribeUrl"]

    @property
    def topic_arn(self) -> str:
        """The Amazon Resource Name (ARN) for the topic that this endpoint is subscribed to."""
        return self["Sns"]["TopicArn"]

    @property
    def subject(self) -> str:
        """The Subject parameter specified when the notification was published to the topic."""
        return self["Sns"]["Subject"]

Ancestors

Instance variables

var get_type : str

The type of message.

For a subscription confirmation, the type is SubscriptionConfirmation.

Expand source code
@property
def get_type(self) -> str:
    """The type of message.

    For a subscription confirmation, the type is SubscriptionConfirmation."""
    # Note: this name conflicts with existing python builtins
    return self["Sns"]["Type"]
var message : str

A string that describes the message.

Expand source code
@property
def message(self) -> str:
    """A string that describes the message. """
    return self["Sns"]["Message"]
var message_attributes : Dict[str, SNSMessageAttribute]
Expand source code
@property
def message_attributes(self) -> Dict[str, SNSMessageAttribute]:
    return {k: SNSMessageAttribute(v) for (k, v) in self["Sns"]["MessageAttributes"].items()}
var message_id : str

A Universally Unique Identifier, unique for each message published.

For a message that Amazon SNS resends during a retry, the message ID of the original message is used.

Expand source code
@property
def message_id(self) -> str:
    """A Universally Unique Identifier, unique for each message published.

    For a message that Amazon SNS resends during a retry, the message ID of the original message is used."""
    return self["Sns"]["MessageId"]
var signature : str

Base64-encoded "SHA1withRSA" signature of the Message, MessageId, Type, Timestamp, and TopicArn values.

Expand source code
@property
def signature(self) -> str:
    """Base64-encoded "SHA1withRSA" signature of the Message, MessageId, Type, Timestamp, and TopicArn values."""
    return self["Sns"]["Signature"]
var signature_version : str

Version of the Amazon SNS signature used.

Expand source code
@property
def signature_version(self) -> str:
    """Version of the Amazon SNS signature used."""
    return self["Sns"]["SignatureVersion"]
var signing_cert_url : str

The URL to the certificate that was used to sign the message.

Expand source code
@property
def signing_cert_url(self) -> str:
    """The URL to the certificate that was used to sign the message."""
    return self["Sns"]["SigningCertUrl"]
var subject : str

The Subject parameter specified when the notification was published to the topic.

Expand source code
@property
def subject(self) -> str:
    """The Subject parameter specified when the notification was published to the topic."""
    return self["Sns"]["Subject"]
var timestamp : str

The time (GMT) when the subscription confirmation was sent.

Expand source code
@property
def timestamp(self) -> str:
    """The time (GMT) when the subscription confirmation was sent."""
    return self["Sns"]["Timestamp"]
var topic_arn : str

The Amazon Resource Name (ARN) for the topic that this endpoint is subscribed to.

Expand source code
@property
def topic_arn(self) -> str:
    """The Amazon Resource Name (ARN) for the topic that this endpoint is subscribed to."""
    return self["Sns"]["TopicArn"]
var unsubscribe_url : str

A URL that you can use to unsubscribe the endpoint from this topic.

If you visit this URL, Amazon SNS unsubscribes the endpoint and stops sending notifications to this endpoint.

Expand source code
@property
def unsubscribe_url(self) -> str:
    """A URL that you can use to unsubscribe the endpoint from this topic.

    If you visit this URL, Amazon SNS unsubscribes the endpoint and stops sending notifications to this endpoint."""
    return self["Sns"]["UnsubscribeUrl"]

Inherited members

class SNSMessageAttribute (data: Dict[str, Any])

Provides a single read only access to a wrapper dict

Expand source code
class SNSMessageAttribute(DictWrapper):
    @property
    def get_type(self) -> str:
        """The supported message attribute data types are String, String.Array, Number, and Binary."""
        # Note: this name conflicts with existing python builtins
        return self["Type"]

    @property
    def value(self) -> str:
        """The user-specified message attribute value."""
        return self["Value"]

Ancestors

Instance variables

var get_type : str

The supported message attribute data types are String, String.Array, Number, and Binary.

Expand source code
@property
def get_type(self) -> str:
    """The supported message attribute data types are String, String.Array, Number, and Binary."""
    # Note: this name conflicts with existing python builtins
    return self["Type"]
var value : str

The user-specified message attribute value.

Expand source code
@property
def value(self) -> str:
    """The user-specified message attribute value."""
    return self["Value"]

Inherited members