Python Lambda函数可捕获AWS MQ的AWS云监视日志并将其发送到kinesis

时间:2018-11-16 17:26:21

标签: amazon-web-services aws-lambda amazon-kinesis amazon-cloudwatchlogs amazon-mq

我从put_records() only accepts keyword arguments in Kinesis boto3 Python API得到了一个Python脚本,它将json文件加载到kinesis流中。

My architecture is something like this

在AWS控制台中,我创建了一个Lambda函数,并添加了上面的代码。Lambda Function

我将如何集成或告诉我的lambda函数每隔一分钟唤醒一次。我是否需要通过Cloud-watch事件添加捕获消息。如果可以的话..?

我确实在链接下方获得了此解决方案表格。

Python脚本:-

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 ''

https://github.com/aws-samples/amazonmq-invoke-aws-lambda

1 个答案:

答案 0 :(得分:0)