Exemple #1
0
    def test_calls_publish(self, mock_boto3):
        mock_client = mock.MagicMock()
        mock_boto3.client.return_value = mock_client

        sns.send_message('message', 'topic')

        self.assertTrue(mock_client.publish.called)
Exemple #2
0
    def test_calls_publish_with_message(self, mock_boto3):
        mock_client = mock.MagicMock()
        mock_boto3.client.return_value = mock_client
        message_json = json.dumps({'message': 'message'})

        sns.send_message('message', 'topic')

        args, kwargs = mock_client.publish.call_args
        self.assertEqual(kwargs['Message'], message_json)
Exemple #3
0
 def transformer(event, context):
     message = sns.parse_event(event)
     transformed_message = transformer_function(message)
     print "Received message: {}.  Transformed to {}.".format(
         message, transformed_message)
     if notify_topic:
         sns.send_message(transformed_message, notify_topic)
         print "Notifying lambdas subscribed to the {} topic.".format(
             notify_topic)
Exemple #4
0
 def filter(event, context):
     message = sns.parse_event(event)
     print "Received message: {}.".format(message)
     if filter_function(message):
         if notify_topic:
             sns.send_message(message, notify_topic)
             print "Notifying lambdas subscribed to the {} topic.".format(
                 notify_topic)
     else:
         print "Message filtered."
Exemple #5
0
    def test_calls_publish_with_topic_arn(self, mock_os, mock_boto3):
        mock_client = mock.MagicMock()
        mock_boto3.client.return_value = mock_client
        mock_os.environ = {
            'SNS_TOPIC_ARN_PREFIX': 'arn:aws:sns:us-east-1:12345'
        }

        sns.send_message('message', 'topic')

        args, kwargs = mock_client.publish.call_args
        self.assertEqual(kwargs['TopicArn'],
                         'arn:aws:sns:us-east-1:12345:topic')
def send_message(event, context):
    message = api_gateway.parse_event(event) or "Hello, world!"
    channel = 'message-channel'
    sns.send_message(message, channel)

    response_message = "Sent a message to channel {}: {}".format(
        channel, message)
    body = {"message": response_message}

    response = {"statusCode": 200, "body": json.dumps(body)}

    return response
Exemple #7
0
def start_pipeline(event, context):
    message = api_gateway.parse_event(event)
    reponse_message = ''

    if message:
        sns.send_message(message, 'new-message')
        response_message = "Got a new message: {}. Notifying lambdas subscribed to the 'new-message' topic.".format(
            message)

    body = {"message": response_message}

    response = {"statusCode": 200, "body": json.dumps(body)}

    return response
Exemple #8
0
 def test_creates_sns_client(self, mock_boto3):
     sns.send_message('message', 'topic')
     mock_boto3.client.assert_called_with('sns')