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)
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
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
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, )
def test_get_conn_returns_a_boto3_connection(self): hook = AwsSnsHook(aws_conn_id='aws_default') self.assertIsNotNone(hook.get_conn())