NavigationContentFooter
Jump toSuggest an edit
Was this page helpful?

Functions local testing

Reviewed on 11 February 2025Published on 06 March 2023

Local testing allows you to run your code on your development environment with a short deploy time.

Scaleway Serverless Functions can run outside Scaleway infrastructures. This is useful to set up, develop, and test functions locally. You can run functions directly on your machines to debug them and analyze logs.

Each local testing framework is written in its respective language and emulates the calls made to functions by the Scaleway infrastructure. The result is a language-specific executable or script that users can connect to with their favorite debugging and logging tools.

Local testing quickstartsLink to this anchor

Refer to the NodeJS local testing repository for more information on testing your function locally using Node.

Quickstart

  1. Install the Scaleway Serverless Functions package using npm:

    npm i @scaleway/serverless-functions
  2. Add the following code to the file containing your handle:

    For ES modules

    // handler.js
    import { pathToFileURL } from "url";
    function handle(event, context, callback) {
    return {
    statusCode: 201,
    body: JSON.stringify({
    message: "Hello World!",
    }),
    headers: {
    "Content-Type": "application/json",
    },
    };
    }
    // This part will execute when testing locally, but not when the function is deployed online
    if (import.meta.url === pathToFileURL(process.argv[1]).href) {
    import("@scaleway/serverless-functions").then(scw_fnc_node => {
    scw_fnc_node.serveHandler(handle, 8080);
    });
    }

    For common JS:

    // handler.js
    const url = require("url");
    module.exports.handle = (event, context, callback) => {
    return {
    statusCode: 201,
    body: JSON.stringify({
    message: "Hello World!",
    }),
    headers: {
    "Content-Type": "application/json",
    },
    };
    };
    // This part will execute when testing locally, but not when the function is deployed online
    if ("file://" + __filename === url.pathToFileURL(process.argv[1]).href) {
    import("@scaleway/serverless-functions").then(scw_fnc_node => {
    scw_fnc_node.serveHandler(exports.handle, 8080);
    });
    }
  3. In a terminal, run the command below to execute your file and start the local webserver:

    node handler.js
  4. In another terminal session, run the command below:

    curl -X GET http://localhost:8080

The function returns the content of its body:

{"message":"Hello World!"}%

RequirementsLink to this anchor

Testing your function locally will create a local web server that listens to a given port.

You need to be able to install packages with the dependency manager of the runtime you use, such as pip, go get, etc.

LimitationsLink to this anchor

Each local testing library tries to best replicate the Serverless Functions environment, but cannot fully emulate the surrounding infrastructure. Therefore, although being able to run your function locally is a good indicator that it will work, it may still fail due to the execution environment used in Scaleway Serverless Functions.

The most significant difference is that, when running in Scaleway Serverless Functions, your function is packaged into a custom Docker image using our build pipeline. This means that at runtime, your function may be launched in a different operating system, with different libraries available to your local development environment.

Performance during local testing can differ from the deployed Serverless Functions environment, and will involve limitations around resource usage and quotas.

Note

CPU/memory settings do not apply when testing functions locally.

Was this page helpful?
API DocsScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCareers
© 2023-2025 – Scaleway