- Notifications
You must be signed in to change notification settings - Fork24
Plugin for Serverless Framework to allow users to deploy their serverless applications on Scaleway Functions
License
scaleway/serverless-scaleway-functions
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Plugin for using ScalewayServerless Functions andServerless Containers withServerless Framework.
- Serverless Framework v3 compatible CLI installed on your local computer (e.g. run
npm install -g osls
).
If you are usingScaleway IAM, you need to be the Owner of the Scaleway Organization in which the deployment will take place, or be an IAM user of the Organization with a policy granting you the necessary Permission Sets. See theIAM Overview for more information.
- Export the template you wish to use (see the listhere). We will use
python3
:
export TEMPLATE=python3
- Create a function from this template:
serverless create \ --path${TEMPLATE}-func \ --template-url https://github.com/scaleway/serverless-scaleway-functions/tree/master/examples/${TEMPLATE}
- Install dependencies:
cd${TEMPLATE}-funcnpm i
- Deploy the function:
serverless deploy
- Invoke the function (note that
first
is the function name in this example):
serverless invoke --function first
More detailed documentation can be found in thedocs
folder, including:
- Managing containers
- Configuring custom domains
- Handling events (e.g. CRONs)
- Security and secret management
- Troubleshooting
There are also language-specific notes for Serverless Functions:
With Serverless Framework, your functions and containers are defined in aserverless.yml
file.
Eachserverless.yml
file corresponds to one functionor container namespace.
The following configuration is common to both functions and containers:
# The name of your namespaceservice:my-namespace# Read environment variables from a .env fileuseDotenv:false# Use of this plugin. This must not be changedplugins: -serverless-scaleway-functions# Scaleway-specific configurationprovider:# Must not changename:scaleway# Runtime used for functions (unless overridden)# List: https://www.scaleway.com/en/docs/serverless/functions/reference-content/functions-lifecycle/#available-runtimesruntime:python310# Global environment variables, used in every function/container in this namespaceenv:MY_VAR:"some var"MY_OTHER_VAR:"some other var"# Global secrets, used in every function/container in this namespacesecret:MY_SECRET:"some secret"MY_OTHER_SECRET:"some other secret"# Optional override of Scaleway credentialsscwToken:<scw-token>scwProject:<scw-project-id># Scaleway region for the deployscwRegion:fr-par# Include/exclude directoriespackage:patterns: -"!node_modules/**" -"!.gitignore" -"!.git/**"
To define functions, you can include afunctions
block:
functions:my-func:# Handler entrypointhandler:handler.py# Minimum and maximum number of instancesminScale:0maxScale:10# Memory limit (in MiB)# Limits: https://www.scaleway.com/en/docs/serverless/functions/reference-content/functions-limitations/memoryLimit:1024# Maximum duration a request will wait to be served before it times out (in seconds)# Value in string format ex: "300s" (default: 300 seconds)timeout:300s# Runtime for this function, allows overriding provider.runtimeruntime:node20# How to handle HTTP. Options: enabled (allow HTTP), or redirected (redirect HTTP -> HTTPS)httpOption:enabled# Execution environment to use when running the function. Options: v1 (legacy), v2 (recommended, with improved cold starts)sandbox:v2# Controls privacy of the function. Options: public (no authentication), private (token-based authentication)privacy:public# Local environment variables, used only in this functionenv:LOCAL_VAR:"local var"# Local secrets, used only in this functionsecret:LOCAL_SECRET:"local secret"# Custom domains configured for the function# https://www.scaleway.com/en/docs/compute/functions/how-to/add-a-custom-domain-name-to-a-function/custom_domains: -my-func.some.domain.com# List of events to trigger the functionevents: -schedule:rate:"1 * * * *"# Data passed as input in the requestinput:key-a:"value-a"key-b:"value-b"
To define containers, you can include acustom.containers
block (note that you can only havefunctions
orcustom.containers
).
custom:containers:my-container:# Subdirectory holding the Dockerfile, cannot be used with registryImagedirectory:container/# Name of the registry image, cannot be used with directoryregistryImage:nginx:latest# Minimum and maximum number of instancesminScale:0maxScale:10# Configuration used to decide when to scale the container up or downscalingOption:# Can be one of: concurrentRequests, cpuUsage, memoryUsagetype:concurrentRequests# Value to trigger scaling up# It's expressed in:# - concurrentRequests: number of requests# - cpuUsage: percentage of CPU usage# - memoryUsage: percentage of memory usage# Note that cpu and memory scaling are only available for minScale >= 1 containersthreshold:50# Memory limit (in MiB)# Limits: https://www.scaleway.com/en/docs/serverless/containers/reference-content/containers-limitations/memoryLimit:1024# CPU limit for the container in mvCPU, chosen based on resource tiers if not set# Limits and tiers: https://www.scaleway.com/en/docs/serverless/containers/reference-content/containers-limitations/cpuLimit:1000# Maximum duration a request will wait to be served before it times out (in seconds)# Value in string format ex: "300s" (default: 300 seconds)timeout:300s# How to handle HTTP. Options: enabled (allow HTTP), or redirected (redirect HTTP -> HTTPS)httpOption:enabled# Execution environment to use when running the container. Options: v1 (legacy), v2 (recommended, with improved cold starts)sandbox:v2# Controls privacy of the container. Options: public (no authentication), private (token-based authentication)privacy:public# Local environment variables, used only in this containerenv:LOCAL_VAR:"local var"# Local secrets, used only in this containersecret:LOCAL_SECRET:"local secret"# Custom domains configured for the function# https://www.scaleway.com/en/docs/serverless/containers/how-to/add-a-custom-domain-to-a-container/custom_domains: -my-container.some.domain.com# Health check configurationhealthCheck:type:http# Or tcp if you only want to check that the port is openhttpPath:/healthinterval:10sfailureThreshold:3# List of events to trigger the containerevents: -schedule:rate:"1 * * * *"# Data passed as input in the requestinput:key-a:"value-a"key-b:"value-b"# Deprecated: number of simultaneous requests to handle# Please use scalingOption of type concurrentRequests instead# maxConcurrency: 20
Note that by defaultserverless deploy
applies the configuration located in yourserverless.yml
and removes functions in that namespace that are not in the file.
This can be switched off by setting thesingleSource
option tofalse
.
Warning
This command is deprecated and will be removed on March 12, 2024. Please refer to the documentation (forfunctions andcontainers) to continue getting your logs.TL;DR: You can still access function and container logs conveniently via theCockpit interface. Dedicated dashboards called "Serverless Functions Logs" and "Serverless Containers Logs" are accessible there.
Theserverless logs
command lets you watch the logs of a specific function or container.
You can fetch the logs of a specific function for with the--function
option. You must specify the name of your function in the command.
serverless logs --function<function_or_container_name>
Theserverless info
command gives you information about your functions' or containers' current deployement state in JSON format.
serverless invoke local
isnot supported directly but instead we provide additional packages to install close to your handler.
Documentation is available through runtimes frameworks for:
- Scaleway Serverless Functions Documentation
- Scaleway Serverless Containers Documentation
- Serverless Framework documentation
- Scaleway Serverless example projects
This plugin is developed and maintained by theScaleway Serverless Team
, but we welcome pull requests and issues, and are available to chat on ourCommunity Slack Channels: #serverless-containers and #serverless-functions.
If you are looking for a way to contribute please readCONTRIBUTING.md. You can also look at thedevelopment documentation.
- Scaleway support is available on Scaleway Console.
- Additionally, you can join ourSlack Community
We love feedback. Feel free to:
- Open aGithub issue
- Send us a message on theScaleway Slack community, in the#serverless-functions channel.
This project is MIT licensed.
About
Plugin for Serverless Framework to allow users to deploy their serverless applications on Scaleway Functions
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.