Абонентские и рабочие лямбда-функции Python

У меня есть две лямбда-функции, написанные на Python.

1- subscriber.py (подключится к AWS MQ, соберет и отобразит сообщение)

import time
import boto3
import stomp
import json
global message

lambda_client = boto3.client('lambda')

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 in subscriber : "%s"' % message)
        invoke_response = lambda_client.invoke(FunctionName="op_worker",
                                           InvocationType='Event',
                                           Payload=json.dumps(message)
                                           )
        #print('invoke_response a message in subscriber : "%s"' % invoke_response)
        print("terstesfsff")
        print (invoke_response['Payload'].read())
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

2- worker.py (который должен собрать сообщение из функции subscriber.py и передать это сообщение в Kinesis)

import time
import boto3
import stomp
import json

lambda_client = boto3.client('lambda')
kinesis_client = boto3.client('kinesis')

def lambda_handler(event, context):

    #print (invoke_response['Payload'].read())
    print('received a message in worker : "%s"' % message)
    kinesis_client.put_record(
            StreamName='OnePurchasing',
            Data=b'bytes',
            PartitionKey='1'
        )

Сообщение об ошибке во время выполнения лямбда-функции subscriber.py:-

    Response:
null

Request ID:
"009406bc-f334-11e8-950f-fde41035f262"

Function Logs:
START RequestId: 009406bc-f334-11e8-950f-fde41035f262 Version: $LATEST
CONNECTION Started
CONNECTION established
CONNECTION Subscribed
received a message in subscriber : "{

  "rateChange":{

    "contractCode":"DOPC/DOPC0004/W19",
    "sourceMarketGroup":"TNO"
}
}"
terstesfsff
b''
END RequestId: 009406bc-f334-11e8-950f-fde41035f262
REPORT RequestId: 009406bc-f334-11e8-950f-fde41035f262  Duration: 10255.69 ms   Billed Duration: 10300 ms   Memory Size: 128 MB Max Memory Used: 33 MB

Сообщение об ошибке на worker.py:-

name 'message' is not defined: NameError
Traceback (most recent call last):
File "/var/task/op_worker.py", line 12, in lambda_handler
print('received a message in worker : "%s"' % message)
NameError: name 'message' is not defined

0 ответов

Другие вопросы по тегам