Jump toUpdate content
Uploading functions using the Serverless.com framework
The Scaleway functions plugin for Serverless Framework allows users to deploy their functions and containers to Scaleway Serverless with a simple serverless deploy.
Serverless Framework handles everything from creating namespaces to function/code deployment by calling APIs endpoint under the hood.
Serverless Framework enables you to create a project using a specific template.
Create the following directory:
~/my-srvless-projects. Then, change into it.
Create a simple Python 3 template:
serverless create --template-url https://github.com/scaleway/serverless-scaleway-functions/tree/master/examples/python3 --path myService
You can find other Scaleway templates on the Scaleway Serverless GitHub page.
Do not edit the
plugins parameters, as these allow you to use the Scaleway provider.
serverless.yml file contains the configuration of a namespace containing one or more functions with the same runtime. In the following example, we use one function and a
The different parameters are:
service: your namespace name
provider.runtime: the runtime of your functions (check the supported runtimes above)
provider.env: the environment variables attached to your namespace are injected into all your namespace containers
scwToken: the Scaleway token you got in prerequisites
scwProject: the Scaleway Project ID
package.patterns: usually, this parameter does not need to be configured. It allows you to include or exclude directories from the deployment
functions: Configuration of your functions. It is a
ymldictionary, with the key being the functions’ name
handler(Required): file or function which will be executed.
env(Optional): environment variables specifics for the current function
minScale(Optional): how many function instances we keep running (default: 0)
maxScale(Optional): maximum number of instances this function can scale to (default: 20)
memoryLimit: RAM allocated to the function instances.
runtime: (Optional) runtime of the function. Can be used when you need to deploy multiple functions with different runtimes in your Serverless Project. If absent,
provider.runtimewill be used.
events(Optional): List of events that trigger your functions (e.g, trigger a function based on a schedule with
Based on the chosen runtime, the
handler variable in the function might vary.
For more detail on how to package your dependencies please refer to How to package your function and upload it as a Zip.
- Path to your handler file (from
../, and add the exported function to use as a handler:
- firstHandler.js => module.exports.myFirstHandler = ...
- secondHandler.js => module.exports.mySecondHandler = ...
- In the
runtime: node16 # or node14, ...
- Include the
node_modulesfolder in your package list to add dependencies to your function.
- Path to the handler file
- firstHandler.py => def my_first_handler
- secondHandler.py => def my_second_handler
- Launch in
runtime: python3 # or python for python 2.7
If you have the following structure, the path to your handler’s package should resemble the following:
- handler.go -> package main in src/testing subdirectory
- handler.go -> package main in src/second subdirectory
- handler.go -> package main at the root of project
functions should be similar to:
events, you may link your containers to specific triggers. For the moment, the feature is limited to
CRON Schedule (time-based).
We do not include HTTP triggers in our event types, as an HTTP endpoint is created for every function. Triggers are just another way to trigger your functions, but you will always be able to execute your code via HTTP.
Below is a list of supported triggers for Scaleway Serverless, and the configuration parameters required to deploy them:
- schedule: Triggers your container based on CRON schedules
rate: the CRON Schedule (UNIX Format) on which your functions will be executed
input: key-value mapping to define arguments that will be passed to your function’s event object during execution
To link a Trigger to your function, you can define an
events key in your function:
# "events" is a list of triggers, the first key being the type of trigger.
# CRON Job Schedule (UNIX Format)
rate: '1 * * * *'
# Input variable are passed in your function's event during execution
You can find other examples of trigger configurations on the Scaleway Serverless Github page.
serverless logs command allows you to watch the logs of a specific function.
--function option and the function’s name to the
serverless logs command to fetch the logs of a specific container.
serverless logs --function <function_name>`
Run the following command to remove a project:
This removes all your functions, as well as your Scaleway Functions’ namespace.