This example assumes you are familiar with how serverless functions work. If needed, you can check Scaleway's official documentation.
This example uses the Scaleway Serverless Framework Plugin. Please set up your environment with the requirements stated in the Scaleway Serverless Framework Plugin before trying out the example.
This example shows how to send a mail using a Serverless Function via Scaleway Go SDK.
Using Serverless Compute Functions to send mails is a great way to optimise costs, manage automatic scaling and having advanced logging and metrics per Function.
Once your environment is set up, you can test your function locally with:
npm install
The code uses 3 environment variables: SCW_DEFAULT_ORGANIZATION_ID
, SCW_ACCESS_KEY
, SCW_SECRET_KEY
.
You should define them in serverless.yml
or using and a .env
file doc here
You can deploy your function with:
serverless deploy
Then, from the given URL, you can run:
curl -v -X POST https://YOUR_FUNCTION -H "X-Auth-Token: $SCW_AUTH_TOKEN" --data '{"to": "MAILTO", "subject": "from console test", "message": "very very long msg to api"}'
After that you can check your logs in the Scaleway Console.