Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
def handler(event, context):
"""Lambda handler that will get invoked by the LocalStack runtime"""

# Wait for the debugger to get attached.
wait_for_debug_client()

# Print the incoming invocation event.
print(event)

# Return the incoming invocation event.
return event


def wait_for_debug_client(timeout=3600):
def wait_for_debug_client(port: int=19891, timeout: int=3600):
"""Utility function to enable debugging with Visual Studio Code"""

import time, threading
import sys, glob
sys.path.append(glob.glob(".venv/lib/python*/site-packages")[0])
import debugpy

debugpy.listen(("0.0.0.0", 19891))
class T(threading.Thread):
daemon = True
def run(self):
if not hasattr(wait_for_debug_client, "_debugpy_listening"):
wait_for_debug_client._debugpy_listening = False

if not wait_for_debug_client._debugpy_listening:
try:
debugpy.listen(("0.0.0.0", port))
wait_for_debug_client._debugpy_listening = True
print(f"debugpy is now listening on port {port}")
except RuntimeError as e:
print(f"debugpy.listen() failed or already active: {e}")

if not debugpy.is_client_connected():
print("Waiting for client to attach debugger...")

def cancel_wait():
time.sleep(timeout)
print("Canceling debug wait task ...")
print("Canceling debug wait task after timeout...")
debugpy.wait_for_client.cancel()
T().start()
print("Waiting for client to attach debugger ...")
debugpy.wait_for_client()


if __name__ == "__main__":
handler({}, {})
threading.Thread(target=cancel_wait, daemon=True).start()
debugpy.wait_for_client()
else:
print("Debugger already attached.")

wait_for_debug_client()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
functions:
arn:aws:lambda:us-east-1:000000000000:function:function-one:
debug-port: 19891

38 changes: 23 additions & 15 deletions lambda-debug-mode/python/base-enable-lambda-debug-mode/handler.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
def handler(event, context):
"""Lambda handler that will get invoked by the LocalStack runtime"""

# Wait for the debugger to get attached.
wait_for_debug_client()

# Print the incoming invocation event.
print(event)

# Return the incoming invocation event.
return event


def wait_for_debug_client(timeout=3600):
def wait_for_debug_client(port: int=19891, timeout: int=3600):
"""Utility function to enable debugging with Visual Studio Code"""

import time, threading
import sys, glob
sys.path.append(glob.glob(".venv/lib/python*/site-packages")[0])
import debugpy

debugpy.listen(("0.0.0.0", 19891))
class T(threading.Thread):
daemon = True
def run(self):
if not hasattr(wait_for_debug_client, "_debugpy_listening"):
wait_for_debug_client._debugpy_listening = False

if not wait_for_debug_client._debugpy_listening:
try:
debugpy.listen(("0.0.0.0", port))
wait_for_debug_client._debugpy_listening = True
print(f"debugpy is now listening on port {port}")
except RuntimeError as e:
print(f"debugpy.listen() failed or already active: {e}")

if not debugpy.is_client_connected():
print("Waiting for client to attach debugger...")

def cancel_wait():
time.sleep(timeout)
print("Canceling debug wait task ...")
print("Canceling debug wait task after timeout...")
debugpy.wait_for_client.cancel()
T().start()
print("Waiting for client to attach debugger ...")
debugpy.wait_for_client()


if __name__ == "__main__":
handler({}, {})
threading.Thread(target=cancel_wait, daemon=True).start()
debugpy.wait_for_client()
else:
print("Debugger already attached.")

wait_for_debug_client()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
functions:
arn:aws:lambda:us-east-1:000000000000:function:function-one:
debug-port: 19891

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
def handler(event, context):
"""Lambda handler that will get invoked by the LocalStack runtime"""

# Wait for the debugger to get attached.
wait_for_debug_client()

# Print a message to log that this the handler of handler_function_one.py file.
print("The handler of handler_function_one.py is evaluating.")

Expand All @@ -14,25 +11,37 @@ def handler(event, context):
return event


def wait_for_debug_client(timeout=3600):
def wait_for_debug_client(port: int=19891, timeout: int=3600):
"""Utility function to enable debugging with Visual Studio Code"""

import time, threading
import sys, glob
sys.path.append(glob.glob(".venv/lib/python*/site-packages")[0])
import debugpy

debugpy.listen(("0.0.0.0", 19891))
class T(threading.Thread):
daemon = True
def run(self):
if not hasattr(wait_for_debug_client, "_debugpy_listening"):
wait_for_debug_client._debugpy_listening = False

if not wait_for_debug_client._debugpy_listening:
try:
debugpy.listen(("0.0.0.0", port))
wait_for_debug_client._debugpy_listening = True
print(f"debugpy is now listening on port {port}")
except RuntimeError as e:
print(f"debugpy.listen() failed or already active: {e}")

if not debugpy.is_client_connected():
print("Waiting for client to attach debugger...")

def cancel_wait():
time.sleep(timeout)
print("Canceling debug wait task ...")
print("Canceling debug wait task after timeout...")
debugpy.wait_for_client.cancel()
T().start()
print("Waiting for client to attach debugger ...")
debugpy.wait_for_client()

threading.Thread(target=cancel_wait, daemon=True).start()
debugpy.wait_for_client()
else:
print("Debugger already attached.")

if __name__ == "__main__":
handler({}, {})

wait_for_debug_client()
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
def handler(event, context):
"""Lambda handler that will get invoked by the LocalStack runtime"""

# Wait for the debugger to get attached.
wait_for_debug_client()

# Print a message to log that this the handler of handler_function_two.py file.
print("The handler of handler_function_two.py is evaluating.")

Expand All @@ -14,24 +11,35 @@ def handler(event, context):
return event


def wait_for_debug_client(timeout=3600):
"""Utility function to enable debugging with Visual Studio Code"""
def wait_for_debug_client(port: int=19892, timeout: int=3600):
import time, threading
import sys, glob
sys.path.append(glob.glob(".venv/lib/python*/site-packages")[0])
import debugpy

debugpy.listen(("0.0.0.0", 19892))
class T(threading.Thread):
daemon = True
def run(self):
if not hasattr(wait_for_debug_client, "_debugpy_listening"):
wait_for_debug_client._debugpy_listening = False

if not wait_for_debug_client._debugpy_listening:
try:
debugpy.listen(("0.0.0.0", port))
wait_for_debug_client._debugpy_listening = True
print(f"debugpy is now listening on port {port}")
except RuntimeError as e:
print(f"debugpy.listen() failed or already active: {e}")

if not debugpy.is_client_connected():
print("Waiting for client to attach debugger...")

def cancel_wait():
time.sleep(timeout)
print("Canceling debug wait task ...")
print("Canceling debug wait task after timeout...")
debugpy.wait_for_client.cancel()
T().start()
print("Waiting for client to attach debugger ...")
debugpy.wait_for_client()

threading.Thread(target=cancel_wait, daemon=True).start()
debugpy.wait_for_client()
else:
print("Debugger already attached.")


if __name__ == "__main__":
handler({}, {})
wait_for_debug_client()
Loading