AWS Lambda python函数执行在";中返回的结果&引用;空"&引用;

AWS Lambda python函数执行在";中返回的结果&引用;空"&引用;,python,python-3.x,python-2.7,amazon-web-services,amazon-mq,Python,Python 3.x,Python 2.7,Amazon Web Services,Amazon Mq,我有一个python脚本,它连接到AWS MQ并收集消息。我所有的连接都是完美的,执行结果就是成功。但我的函数执行返回的结果是“null”。 更新的错误日志:- { "errorType": "ConnectFailedException", "stackTrace": [ " File \"/var/task/one_purchasing.py\", line 21, in lambda_handler\n conn.connect(login='test_mq

我有一个python脚本,它连接到AWS MQ并收集消息。我所有的连接都是完美的,执行结果就是成功。但我的函数执行返回的结果是“null”。 更新的错误日志:-

    {
  "errorType": "ConnectFailedException",
  "stackTrace": [
    "  File \"/var/task/one_purchasing.py\", line 21, in lambda_handler\n    conn.connect(login='test_mq', passcode='test_secure_mq',wait=True)\n",
    "  File \"/var/task/stomp/connect.py\", line 164, in connect\n    Protocol11.connect(self, *args, **kwargs)\n",
    "  File \"/var/task/stomp/protocol.py\", line 340, in connect\n    self.transport.wait_for_connection()\n",
    "  File \"/var/task/stomp/transport.py\", line 327, in wait_for_connection\n    raise exception.ConnectFailedException()\n"
  ]
}
更新的Python Lambda函数:-

import time
import boto3
import stomp
import json

kinesis_client = boto3.client('kinesis')


class Listener(stomp.ConnectionListener):
    def on_error(self, headers, message):
        print('received an error "%s"' % message)
        kinesis_client.put_record(
            StreamName='OnePurchasing',
            Data=u'{}\r\n'.format(message).encode('utf-8'),
            PartitionKey='0'
        )

    def on_message(self, headers, message):
        print('received a message "%s"' % message)
def lambda_handler(event, context):
    conn = stomp.Connection(host_and_ports=[('b-fa99d7c5-4714-4441-8166-47aae158281a-1.mq.eu-central-1.amazonaws.com', 61614)])
    lst = Listener()
    conn.set_listener('Listener', lst)
    conn.set_ssl(for_hosts=[('b-fa99d7c5-4714-4441-8166-47aae158281a-1.mq.eu-central-1.amazonaws.com', 61614)])
    conn.start()
    print('CONNECTION Started')
    conn.connect(login='test_mq', passcode='test_secure_mq',wait=True)
    print('CONNECTION established')
    conn.subscribe(destination='/queue/OnePurchasing', id=1, ack='auto')
    print('CONNECTION Subscribed')
    time.sleep(10)
    conn.disconnect()
    return
谁能告诉我如何调试更多以从MQ获取消息

MQ URL消息屏幕截图


之所以
response
null
是因为您从未返回值,您只是
返回
。这与运行以下命令时的响应相同:

def lambda_handler(event, context):
    return
您可能希望返回一些内容,如lambda中内置的示例:

import json

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }
关于你的其他问题,看起来你根本没有收到任何信息。您可以从队列中查看是否有消息,消息是否已被使用,等等

我看到的所有示例都涉及到使用
wait=True
选项,例如
conn.connect(wait=True)
,因此您应该尝试将其添加到
conn.connect
中,除非您有充分的理由不使用它

编辑:我测试了这个,我认为你永远不会建立连接。如果添加
wait=True
,您可能会看到连接失败,出现
ConnectFailedException
,就像我的一样。这可能是调试的第一件事

编辑2:我解决了它,您需要使用SSL连接到AWS MQ实例,如下所示:

conn = stomp.Connection(host_and_ports=[('b-4714-4441-8166-47aae158281a-1.mq.eu-central-1.amazonaws.com', 61614)])
lst = Listener()
conn.set_listener('Listener', lst)
conn.set_ssl(for_hosts=[('b-4714-4441-8166-47aae158281a-1.mq.eu-central-1.amazonaws.com', 61614)])
conn.start()

不确定这是否是问题的原因,但根据建议,您应该将端口设置为字符串,而不是int
,'61614')]
,以使奇怪的警告消失。好奇地想看看它是否有区别。@EricDarchis我测试过,它没有区别,奇怪的警告仍然存在。@EricDarchis。。对这没什么区别。@Tinku关于你对我答案的编辑,你可能也想在你的问题中改变一下:-)@RobBricheno-我发布了不同的问题-我也更新了回复和代码。MQ中确实包含消息。使用具有凭据的MQ的正确URL更新。请suggest@Tinku你试过了吗?是的。。即使我收到了“errorType”:“ConnectFailedException”,Error我如何从这里开始。因为我已经给出了所有正确的值have@Tinku检查最新编辑,我解决了它,您需要使用SSL:-)