For this tutorial, we will use User credentials which are simpler to use. However, for production-grade Serverless applications, we recommend using Application credentials with the minimum possible rights.
Transforming images in an Object Storage bucket using Serverless Functions and Triggers - Set up
- serverless
- functions
- triggers
- sqs
Serverless Functions are an asynchronous microservices architecture where event sources are decorrelated from event consumers.
They work best when they are triggered by specific events, such as cron schedules, which means they can be edited without having to modify every microservice in the process.
In this tutorial, you will create the following resources to use your functions:
- A project dedicated to this tutorial
- Two buckets to store media
- A queue to manage events
- IAM credentials to secure your environment
Before you start
To complete the actions presented below, you must have:
Creating a Project
- Click the Projects tab from the Organization Dashboard. A list of your Projects displays.
- Click + Create Project on the right-hand side. A pop-up displays.
- Name the project
Functions Tutorial
. - Click Create Project. The new Project is added to the list.
Creating the source bucket
- Click Object Storage under Storage on the left side menu of the console. The Object Storage dashboard displays.
- Click + Create a bucket.
- Name it
source-images-<YOUR_NAME>
. - Choose the AMSTERDAM Region.
- Set the bucket visibility to Private.
- Click Create bucket. The bucket’s Files tab displays.
- Upload your images to the bucket and select the Standard storage class.
Creating the destination bucket
- Click Storage, then Object Storage on the left side menu of the console. The Object Storage dashboard displays.
- Click + Create a bucket.
- Name it
dest-images-<YOUR_NAME>
. - Choose the AMSTERDAM Region.
- Set the bucket visibility to Private.
- Click Create Bucket.
Generating credentials for Scaleway Queues
- Click Queues under Serverless on the left side menu of the console.
- Click + Generate credentials.
- Name your credentials
Function Push
. - Enable the Write, Read and Manage permissions.
- Click Generate credentials.
- Store the access key ID and the secret key securely, as you will not be able to access them later.
Creating a queue
- Click Queues under Serverless on the left side menu of the console.
- Click Create queue.
- Select Standard as a queue type.
- Name it
image-queue
. - Keep the default parameters.
- Click Create queue.
Creating IAM credentials
Identity and Access Management (IAM) credentials allow you to secure access to your buckets, functions, etc.
- Click the Organization in the top right corner and Select API keys. The IAM API keys tab displays.
- Click + Generate an API key or the «Plus Icon» button.
- Select Myself (IAM) as the API key Bearer.
- Enter
API key for the Function Tutorial
as a description. - Set Expiration to One Week.
- Select Yes, set up preferred Project.
- Choose the Functions Tutorial project (or the name you gave to this project).
- Click Generate API key.
- Store the Access key ID and the Secret key securely, as you will not be able to access them later.
Enabling monitoring with Cockpit
- Click Cockpit under Observability.
- Click the Grafana users tab.
- Click + Add user.
- Enter a username.
- Select the Editor role.
- Click Add user.
- Store the password securely, as you will not be able to access it later.
Creating and deploying functions
You have created all the necessary resources, it is now time to create functions.
Setting up an environment with all the necessary resources can be time-consuming. You can use IaC (Infrastructure as Code) tools such as Terraform to automate a project’s configuration.