AWS | Syntax error in module: invalid syntax

2024/11/16 8:50:38

I have created python script which is uploaded as a zip file in AWS Lambda function with stompy libraries bundled in them.

Logs for python 2.7:-

Response:
nullRequest ID:
"c334839f-ee46-11e8-8970-612f1dc92e41"Function Logs:
START RequestId: c334839f-ee46-11e8-8970-612f1dc92e41 Version: $LATEST
CONNECTION Started
CONNECTION established
CONNECTION Subscribed
[WARNING]   2018-11-22T11:07:12.798Z    c334839f-ee46-11e8-8970-612f1dc92e41    Unknown response frame type: '' (frame length was 3)
END RequestId: c334839f-ee46-11e8-8970-612f1dc92e41
REPORT RequestId: c334839f-ee46-11e8-8970-612f1dc92e41  Duration: 10027.75 ms   Billed Duration: 10100 ms   Memory Size: 128 MB Max Memory Used: 30 MB

My Code:-

import time
import boto3
import stompkinesis_client = boto3.client('kinesis')class Listener(stomp.ConnectionListener):msg_list = []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='Purchasing',Data=u'{}\r\n'.format(message).encode('utf-8'),PartitionKey='0')def lambda_handler(event, context):conn = stomp.Connection(host_and_ports=[('b-4714-4441-8166-47aae158281a-1.mq.eu-central-1.amazonaws.com', 8162)])lst = Listener()conn.set_listener('Listener', Listener())conn.start()conn.connect(login='test_mq', passcode='test_mq')conn.subscribe(destination='/queue/Purchasing', id='b-4714-4441-8166-47aae158281a', ack='auto')message = lst.msg_listprint('Waiting for messages "%s"' % message)time.sleep(10)conn.disconnect()return ''

I am not sure why my message is not showing up in my output,instead it always shows up "Response: null".

Answer

EDIT: As pointed by @Petesh, the issue comes from stompy(external library), which hasn't been ported to Python3.

If you check the source code, you can find this:

except socket.timeout, exc:

which is invalid syntax for python3+

If you run your Lambdas in python3.6/3.7 environment, the syntax is invalid.

The issue might go away if you choose python 2.7, but you will also have to adjust your code, libraries, etc.

https://en.xdnf.cn/q/120347.html

Related Q&A

Algorithm for finding if an array is balanced [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

Merging two dataframes in python pandas [duplicate]

This question already has answers here:Pandas Merging 101(8 answers)Closed 5 years ago.I have a dataframe A:a 1 a 2 b 1 b 2Another dataframe B:a 3 a 4 b 3I want my result dataframe to be like a 1 3 a …

Searching for the best fit price for multiple customers [duplicate]

This question already has an answer here:Comparing multiple price options for many customers algorithmically(1 answer)Closed 10 years ago.A restatement of Comparing multiple price options for many cust…

Can we chain the ternary operator in Python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 4 years ago.The com…

evaluate a python string expression using dictionary values

I am parsing a text file which contain python "string" inside it. For e.g.:my_home1 in houses.split(,) and 2018 in iphone.split(,) and 14 < maskfor the example above, I wrote a possible di…

How to simply get the master volume of Windows in Python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 1 year ago.Improve …

Python: Adding positive values in a list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Python IM Program [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Changes in Pandas DataFrames dont preserved after end of for loop

I have a list of Pandas DataFrames and I want to perform some operations on them. To be more precise, I want to clean their names and add new column. So I have written the following code:import numpy a…

How can I prevent self from eating one of my test parameters?

I have in my test module:import pytest from src.model_code.central import AgentBasicclass AgentBasicTestee(AgentBasic):pass@pytest.fixture() def agentBasic():return AgentBasicTestee()@pytest.mark.param…