Jump toUpdate content
How to upload your function using Serverless.com framework
This plugin allows Serverless Framework users to deploy their functions and containers to Scaleway Functions with a simple serverless deploy. Serverless Framework will handle everything from the namespace creation to the function/code deployment by calling APIs endpoint under the hood.
Serverless Framework enables you to create a project using a specific template.
- Start by creating and changing into
# mkdir ~/my-srvless-projects
# cd ~/my-srvless-projects
- Create a simple Python 3 template by running:
serverless create --template-url https://github.com/scaleway/serverless-scaleway-functions/tree/master/examples/python3 --path myService
You can find other Scaleway templates on our Github.
plugins MUST NOT be changed, they enable us to use the scaleway provider
This file contains the configuration of one namespace containing one or more functions (in this example, only one) of the same runtime (here
The different parameters are:
service: your namespace name
provider.runtime: the runtime of your functions (check the supported runtimes above)
provider.env: environment variables attached to your namespace are injected to all your namespace functions
scwToken: Scaleway token you got in prerequisites
scwProject: Scaleway project id you got in prerequisites
package.patterns: usually, you do not need to configure it. It enables to include or exclude directories from the deployment
functions: Configure of your fonctions. It is a yml dictionary, with the key being the function name
handler(Required): file or function which will be executed. See the next section for runtime specific handlers
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. See the introduction for the list of supported values
runtime: (Optional) runtime of the function, if you need to deploy multiple functions with different runtimes in your Serverless Project. If absent,
provider.runtimewill be used to deploy the function.
events(Optional): List of events to trigger your functions (e.g, trigger a function based on a schedule with
Based on the chosen runtime, the
handler variable on 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: node8 # or node10 or node14
- To add dependencies to your function, include the
node_modulesfolder in your package list.
- Similar to
node, path to handler file
- firstHandler.py => def my_first_handler
- secondHandler.py => def my_second_handler
runtime: python3 # or python for python 2.7
If you have the following structure, the path to your handler’s package should resemble to:
- 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 functions with specific triggers, which might include
CRON Schedule (time-based),
MQTT Queues (publish on a topic that will trigger the function),
S3 Object update (upload an object will trigger the function).
We do not include HTTP triggers in our event types, as a HTTP endpoint is created for every function. Triggers are just a new way to trigger your Function, but you will always be able to execute your code via HTTP.
Below is a list of supported triggers on Scaleway Serverless, and the configuration parameters required to deploy them:
- schedule: Trigger your function based on CRON schedules
rate: CRON Schedule (UNIX Format) on which your function will be executed
input: key-value mapping to define arguments that will be passed into your function’s event object during execution.
To link a Trigger to your function, you may define a key
events 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 may link Events to your Containers too (see section
Managing containers below for more information on how to deploy containers):
# Events key
rate: '1 * * * *'
You may refer to the follow examples:
serverless logs command lets you watch the logs of a specific function or container.
Pass the function name you want to fetch the logs for with
serverless logs --function <function_name>`
To remove a project, you may run the following command:
This will remove all your functions, as well as your Scaleway Functions namespace.