Skip to main content

Python

Pyversions PyPI

Installation

1

Get auth token

Login to your account, and get your auth token.


info

If you want to try ServerlessDebugger you can get a free 7 days auth token from here

2

Install VS Code plugin

Install our plugin from VS Code Marketplace: Debugger for AWS Lambda.

3

Edit Configuration

Write "Serverless Debugger" to Command Palette on VSCode and click "Edit Configuration" and paste your authentication key to authToken.


Command Palette

4

Install VS Code plugin

Set SLSDEBUGGER_AUTH_TOKEN also by your auth token to your lambda environment.

5

Edit your AWS Lambda

Follow one of the following two steps. Using Lambda Layer or Manually Wrapping

Using Lambda Layer

  • Add ServerlessDebugger lambda layer
arn:aws:lambda:${region}:545538059309:layer:slsdebugger-python:${latest-version} 
  • Latest version: ServerlessDebugger Python Layer

  • Supported regions:

    • ap-northeast-1, ap-northeast-2, ap-south-1, ap-southeast-1, ap-southeast-2, ap-east-1, ca-central-1, eu-central-1, eu-north-1, eu-south-1, eu-west-1, eu-west-2, eu-west-3, sa-east-1, us-east-1, us-east-2, us-west-1, us-west-2
  • Set SLSDEBUGGER_AUTH_TOKEN and SLSDEBUGGER_LAMBDA_HANDLER to your lambda handler as environment variable.

  • Change original lambda handler with slsdebugger.handler.wrapper

  • Open your handler file in VS Code, put breakpoint and start ServerlessDebugger extension.

  • Trigger your function.

Example for yml file

service: hello-world
frameworkVersion: '3'

provider:
name: aws
runtime: python3.8
region: ${opt:region, <your-region>}
timeout: 60
layers:
arn:aws:lambda:<your-region>:545538059309:layer:slsdebugger-python:<latest-version>
environment:
SLSDEBUGGER_AUTH_TOKEN: <your_auth_token>
SLSDEBUGGER_LAMBDA_HANDLER: handler.hello

functions:
hello:
handler: slsdebugger.handler.wrapper
events:
- httpApi:
method: GET
path: /hello

Manually Wrapping

  • Run this command from your project directory:
pip install slsdebugger -t .
  • Wrap your lambda function.
import slsdebugger

@slsdebugger.lambda_wrapper
def handler(event, context):
print("Hello Serverless Debugger!")
  • Set SLSDEBUGGER_AUTH_TOKEN in environment variable.

  • Open your handler file in VSCODE, put breakpoint and start Serverless Debugger extension downloaded from Debugger for AWS Lambda.

  • Trigger your lambda function.

Configuration

You can configure Serverless Debugger using environment variables.

1. Lambda environment variables

  • Only required environment variable is SLSDEBUGGER_AUTH_TOKEN. If it is empty, Serverless Debugger only calls your function without debugging.
NameTypeDefault Value
SLSDEBUGGER_ENABLEDbooltrue
SLSDEBUGGER_AUTH_TOKENstring-
SLSDEBUGGER_PORTint1111
SLSDEBUGGER_LOGS_ENABLEboolfalse
SLSDEBUGGER_WAIT_MAXint60000(ms)
SLSDEBUGGER_IO_WAITint2000(ms)
SLSDEBUGGER_BROKER_PORT (only your lambda)int444
SLSDEBUGGER_BROKER_HOSTstringbroker.service.serverlessdebugger.com
SLSDEBUGGER_SESSION_NAMEstringdefault
SLSDEBUGGER_LAMBDA_HANDLERstringyour-original-lambda-handler
SLSDEBUGGER_LAMBDA_WARMUP_WARMUPAWAREboolfalse
SLSDEBUGGER_LAMBDA_TIMEOUT_MARGINint-

Getting Help

If you have any issue around using the library or the product, please don't hesitate to join our Discord channel.

Opening Issues

For any problem you encounter while using Serverless Debugger Python, Please feel free to contact us Discord.

When opening a new issue, please provide as much information about the environment:

  • Library version, Python runtime version, dependencies, operation system with version etc.
  • Snippet of the usage.
  • A reproducible example can really help.