Deploying applications to the cloud becomes simpler with Serverless Functions. Instead of provisioning and maintaining servers, you just need to install a "function" of your business logic on the Scaleway cloud platform. The platform executes this function on demand, managing resource allocation for you. If the system needs to accommodate a hundred simultaneous requests, it creates a hundred (or more) copies of your service. Conversely, if demand drops to two concurrent requests, it destroys the unneeded ones. You only pay for the resources your functions use when they need them.
The benefits of Scaleway Serverless Functions include:
- Saving money while code is not running, as functions are only executed when an event is triggered
- Auto-scalability:
- Scaling up and down automatically based on user configuration (e.g., min: 0, max: 100 replicas of my function).
- Scaling to zero when the function is not executed, which saves money for the user and computing resources for the cloud provider.
- Endpoint-only scaling.
Deploying functions
This page explains how to use the Scaleway Serverless Functions API, including a quickstart and the full API documentation. However, we provide several methods to deploy functionsOpen in new context.
Note
To learn how to package and upload your function code, refer to the dedicated documentationOpen in new context.
Concepts
Refer to our dedicated conceptsOpen in new context page to find definitions of all terminology related to Scaleway Serverless Functions.
Quickstart
Note
For functions concepts and advanced documentation, please refer to Scaleway Quickstart for FunctionsOpen in new context.
-
Configure your environment variables.
CodeNote
A namespace is a project that allows you to group your functions. Functions in the same namespace can share environment variables and access tokens, defined at the namespace level.
-
Set the name for your namespace and set your Project ID.
Code -
Copy the
idfield of the response to use in the next steps. For the sake of simplicity, we will save the ID to a variable, which we will use in the following examples.Code -
Edit the POST request payload that we will use in the next step to create a function. Modify the values in the example according to your needs, using the information in the table to help.
CodeParameter Description nameThe name of your function namespace_idID of the namespace in which you want to create your function runtimeYour function's runtime, check the supported runtimes above environment_variablesNULLABLE Environment variables of the function. memory_limitNULLABLE Memory (in MB) allocated to your function, see the table of memory/CPU allocation above (increasing the memory limit will increase the cost of your function executions as we allocate more resources to your functions). min_scaleNULLABLE Minimum replicas for your function, defaults to 0, Note that a function isbilledwhen it gets executed, and using amin_scalegreater than 0 will cause your function to run all the time.max_scaleNULLABLE Maximum replicas for your function (defaults to 20), our system will scale your functions automatically based on incoming workload, but will never scale the number of replicas above the configuredmax_scale.timeoutNULLABLE Holds the max duration (in seconds) the function is allowed for responding to a request descriptionNULLABLE Description of the function. handlerNULLABLE More details with examples in each language/runtime section below
Note that the meaning of the value set in handler will change depending on the runtime parameter:
-
Node,PHPandPythonruntimes:handleris the path to the function file, followed by the name of the function to call. For example,src/handler.handlespecifies a function file atsrc/handler.js,src/handler.phpandsrc/handler.pyrespectively, with a function calledhandle. -
GoandRustruntimes:handleris the path to the package containing the handler. For example,my_handlerspecifies that the function file is located in amy_handlerdirectory. The functions must then be part of amainpackage, exposing amainfunction.Code
-
Run the following command to create your function. Make sure you include the payload you edited in the previous step.
Code -
Upload your code from the console or directly via the API. Refer to the dedicated documentationOpen in new context for more information.
-
Run the following command to deploy your function.
CodeNote
The process may take some minutes, as we have to build your source code into an executable function (wrapped by our runtimes), and deploy it to the Scaleway cloud platform.
-
Retrieve your function's HTTP(s) endpoint with the following command once your function has been properly deployed.
Code -
Call your function via its endpoint.
Code -
(optional) Connect to your CockpitOpen in new context, and access the Serverless Functions Logs dashboard to see your logs.
-
(optional) Destroy the namespace (along with all functions and cron jobs) by using the following call:
Code
Requirement
To perform the following steps, you must first ensure that:
- You have a Scaleway accountOpen in new context
- You have created an API keyOpen in new context and that the API key has sufficient IAM permissionsOpen in new context to perform the actions described on this page
- You have installed
curlOpen in new context - You have installed
jqOpen in new context to improve readability of the API outputs
Technical information
- Functions are fully isolated environments
- Scaling to zero (save money and computing resources while code is not executed)
- High Availability and Scalability (Automated and configurable, each function may scale automatically according to incoming workloads)
- Different programming languages supported
- Multiple event sources:
- HTTP (request on our Gateway will execute the function)
- CRON (time-based job, runs according to configurable cron schedule)
- Integrated with the Scaleway Container Registry product
- Each of your functions namespace has an associated registry namespace
- All your functions are available as docker image in this registry namespace
- Each version of your function matches a tag of this image
Token management
To get all tokens associated with a function:
Code
Note
Tokens can only be read at creation time, and are not stored, hence they can not be retrieved if lost.
To generate a token for a function:
Code
Tip
expire_at is optional, and in this example is set to 90 days from today (see EXPIRE_AT). If you don't set expire_at, your token will never expire.
To revoke a token you need to delete it:
Code
Authentication
By default, new functions are public meaning that no credentials are required to invoke functions.
A function can be private or public. This can be configured through the privacy parameter.
Calling a private function without authentication will return HTTP code 403.
Authentication for private functions
A private function will:
- Reject a call without an
X-Auth-Tokenheader, returning HTTP status Code403 - Validate the token before invoking your code if it is provided via the
X-Auth-Tokenheader
For example, to execute a private function by providing a token using curl, you may run the following command:
Code
Logs
Functions logs are sent to the project's CockpitOpen in new context.
The Serverless Functions Logs dashboard allows you to see functions logs. You can perform complex queries using the Explore section of Grafana, and with LogQL queries:
Code
Additionally, you can use the Grafana Loki endpoint (https://logs.cockpit.fr-par.scw.cloud) to query programmatically the functions logs using a tokenOpen in new context.
Pagination
Most listing requests receive a paginated response. Requests against paginated endpoints accept two query arguments:
page, a positive integer to choose which page to return.page_size, an positive integer lower or equal to 100 to select the number of items to return per page. The default value is20.
Paginated endpoints usually also accept filters to search and sort results. These filters are documented along each endpoint documentation.
Regions
Serverless Functions is available in the Paris, Amsterdam and Warsaw regions, which are represented by the following path parameters:
fr-parnl-amspl-waw
Technical limitations
Supported runtimes and function lifecycle
You can find all information about runtimes and functions in the Functions' lifecycle reference pageOpen in new context.
Going further
For more help using Scaleway Serverless functions, check out the following resources:
- Our main documentationOpen in new context
- The #serverless-functions channel on our Slack CommunityOpen in new context
- Our support ticketing systemOpen in new context
Local testing
Scaleway provides a number of open-source tools for offline testing. The details can be found in the local testing docsOpen in new context.