SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

How to Debug Twilio Functions With Live Logs and CLI

Objective

Learn how to debug Twilio Functions using live logs in the console, retrieve historical logs via the Twilio CLI, and set up local real-time debugging. This guide helps resolve execution errors and unexpected behavior in your Serverless environment.

 

Product

Twilio Functions

 

Environment

Twilio Console

 

Procedure 

Method 1: Debug from the Twilio Console

  1. Open your Function in the Twilio Console editor.
  2. Toggle on the Live logs option in the editor user interface.
  3. Invoke your Function (for example, by sending an HTTP request via browser or curl).
  4. Watch the log statements from your code display in real time as the Function runs.

 

Method 2: Retrieve Historical Logs via Twilio CLI

If you have closed your console session, you can still fetch your logs through the Serverless API using the Twilio CLI.

  • Option A: Using the standard Serverless API command Run the following command in your terminal:
twilio api:serverless:v1:services:environments:logs:list \
    --service-sid ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
    --environment-sid ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

  • Option B: Using the Serverless Toolkit plugin (Recommended) For a simplified, less verbose command, run:
twilio serverless:logs \
    --service-sid=ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
    --environment=ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Method 3: Debug Locally in Real-Time

To step through your code line-by-line using a developer tool like Visual Studio Code or Chrome Developer Tools, you must run the Function locally.

  1. Open your project locally (Note: This method only works if your project was initially created using the Serverless Toolkit, not the Console UI).
  2. Start your local development server with a Node.js debugger attached using the Serverless Toolkit.
  3. Set your breakpoints and execute the local Function to begin debugging.

Further Information

Debug your Function(s)

Have more questions? Submit a request
Powered by Zendesk