Skip to content

oxide-byte/todo-serverless-scaleway

Repository files navigation

Todo Serverless Scaleway

Motivation

Serverless and Rust are some of the topics to motivate me for doing POC's as in real life projects these topics are still not common practice. An other topic currently handles the IT world is European Sovereign Cloud. One actor for this is https://www.scaleway.com

The perfect moment to create a new POC, and move my AWS Serverless project https://github.com/oxide-byte/todo-serverless to a new European Cloud Provider.

Objectives:

  • Serverless Functions in Backend (Rust)
  • S3 Static Web Pages in Frontend (Rust / Leptos)
  • Serverless Database (PostgreSQL)
  • IAC - OpenTofu / Terraform
ATTENTION:

Deploying this POC with it's functions and database generate costs !!!

General best practices when working with a Cloud Provider

*** RULE 1 ***

Apply MultiFactor Authentication (MFA) on your main account.

*** RULE 2 ***

Don't use your main account for daily business or POC's like this. It is easier to delete an "WORKER" account when its credentials are compromised. (https://www.scaleway.com/en/docs/iam/how-to/create-application/)

alt text

*** RULE 3 ***

Don't commit productive/cloud accounts, keys or passwords.

*** RULE 4 ***

Define your Budget plan with alerts:

alt text

*** RULE 5 ***

Clean up when finished. Remove all unused resources.

Preparation

Creating a new account on https://www.scaleway.com

Sample of prices:

alt text

Scaleway CLI

Installation: https://www.scaleway.com/en/cli/

Build

Accounts

The current applied user has in my case organizational Administration rights and a policy to all products. To review later, as maybe in real organizations not all actions are done by Terraform/OpenTofu but by an administrator.

alt text

Environment

as mentioned, I use OpenTofu / Terraform

*** Initial Environment ***

export TF_VAR_access_key=<scw-access-key>
export TF_VAR_secret_key=<scw-secret-key>
export TF_VAR_project_id=<scw-project-id>
export TF_VAR_organization_id=<scw-organization-id>

OpenTofu / Terraform

The Terraform script manages the following Scaleway resources:

  • Serverless SQL Database: A PostgreSQL database (v16) for task storage.
  • IAM Application & API Key: Secure, scoped authentication for the database (using ServerlessSQLDatabaseReadWrite policy).
  • Container Namespace & Registry: Infrastructure to host and store the serverless function images.
  • Serverless Containers (FaaS): Five Rust-based functions (add, delete, get, get-all, edit) that handle the API logic.
  • Object Storage (S3): A bucket configured for static website hosting to serve the Leptos-based UI.
  • Initialization Scripts: Automated Docker builds, database schema setup, and UI deployment via local-exec provisioners.

*** The OpenTofu commands ***

cd iac
tofu init
tofu plan
tofu apply
tofu destroy

The created Serverless Containers:

alt text

The serverless Database:

alt text

The OpenTofu scripts shows

alt text

adding to the website_url /index.html access you to the website:

alt text

Useful references:

Improvements

This is a simple POC, there is still room for improvements.

This application has 5 functions (add/delete/edit/get/get_all), but could be joined in a single one. This is only for showcase. A single function would reduce cold starts. The advantage of multiple functions, you could define each function a different CPU/Memory value with different execution costs.

Releases

No releases published

Packages

 
 
 

Contributors