将AWS cloudwatch事件与AWS MQ集成以捕获消息

时间:2018-11-17 19:31:09

标签: amazon-web-services amazon-cloudwatch amazon-mq

我如何将AWS云监视事件与AWS MQ集成以捕获消息并告诉我的lambda函数每隔一分钟唤醒一次。

Lambda Functionality

Lambda函数:-

import time
import boto3
import stomp

kinesis_client = boto3.client('kinesis')


class Listener(stomp.ConnectionListener):
    def on_error(self, headers, message):
        print('received an error "%s"' % message)

    def on_message(self, headers, message):
        print('received a message "%s"' % message)
        kinesis_client.put_record(
            StreamName='inter-lambda',
            Data=u'{}\r\n'.format(message).encode('utf-8'),
            PartitionKey='0'
        )


def handler(event, context):
    conn = stomp.Connection(host_and_ports=[('localhost', 61616)])
    conn.set_listener('', Listener(conn))
    conn.start()
    conn.connect(login='user', passcode='pass')
    conn.subscribe(destination='A.B.C.D', ack='auto')
    print('Waiting for messages...')
    time.sleep(10)
    conn.close()
    return ''

0 个答案:

没有答案
相关问题