Example #1
0
    def execute(self, context):
        sns = AwsSnsHook(aws_conn_id=self.aws_conn_id)

        self.log.info('Sending SNS notification to %s using %s:\n%s',
                      self.target_arn, self.aws_conn_id, self.message)

        return sns.publish_to_target(target_arn=self.target_arn,
                                     message=self.message)
Example #2
0
    def test_publish_to_target_plain(self):
        hook = AwsSnsHook(aws_conn_id='aws_default')

        message = "Hello world"
        topic_name = "test-topic"
        target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn')

        response = hook.publish_to_target(target, message)

        assert 'MessageId' in response
Example #3
0
    def test_publish_to_target_with_attributes(self):
        hook = AwsSnsHook(aws_conn_id='aws_default')

        message = "Hello world"
        topic_name = "test-topic"
        target = hook.get_conn().create_topic(Name=topic_name).get('TopicArn')

        response = hook.publish_to_target(target, message, message_attributes={
            'test-string': 'string-value',
            'test-number': 123456,
            'test-array': ['first', 'second', 'third'],
            'test-binary': b'binary-value',
        })

        assert 'MessageId' in response
Example #4
0
    def execute(self, context):
        sns = AwsSnsHook(aws_conn_id=self.aws_conn_id)

        self.log.info(
            'Sending SNS notification to %s using %s:\nsubject=%s\nattributes=%s\nmessage=%s',
            self.target_arn,
            self.aws_conn_id,
            self.subject,
            self.message_attributes,
            self.message,
        )

        return sns.publish_to_target(
            target_arn=self.target_arn,
            message=self.message,
            subject=self.subject,
            message_attributes=self.message_attributes,
        )