NavigationContentFooter
Jump toSuggest an edit

Transforming images in an Object Storage bucket using Serverless Functions and Triggers - Set up

Reviewed on 21 October 2024Published on 07 July 2023
  • 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:

  • A Scaleway account logged into the console
  • Installed Node.js and npm
  • At least 10 JPG or PNG images

Creating a Project

  1. Click the Projects tab from the Organization Dashboard. A list of your Projects displays.
  2. Click + Create Project on the right-hand side. A pop-up displays.
  3. Name the project Functions Tutorial.
  4. Click Create Project. The new Project is added to the list.

Creating the source bucket

  1. Click Object Storage under Storage on the left side menu of the console. The Object Storage dashboard displays.
  2. Click + Create a bucket.
  3. Name it source-images-<YOUR_NAME>.
  4. Choose the AMSTERDAM Region.
  5. Set the bucket visibility to Private.
  6. Click Create bucket. The bucket’s Files tab displays.
  7. Upload your images to the bucket and select the Standard storage class.

Creating the destination bucket

  1. Click Storage, then Object Storage on the left side menu of the console. The Object Storage dashboard displays.
  2. Click + Create a bucket.
  3. Name it dest-images-<YOUR_NAME>.
  4. Choose the AMSTERDAM Region.
  5. Set the bucket visibility to Private.
  6. Click Create Bucket.

Generating credentials for Scaleway Queues

  1. Click Queues under Serverless on the left side menu of the console.
  2. Click + Generate credentials.
  3. Name your credentials Function Push.
  4. Enable the Write, Read and Manage permissions.
  5. Click Generate credentials.
  6. Store the access key ID and the secret key securely, as you will not be able to access them later.

Creating a queue

  1. Click Queues under Serverless on the left side menu of the console.
  2. Click Create queue.
  3. Select Standard as a queue type.
  4. Name it image-queue.
  5. Keep the default parameters.
  6. Click Create queue.

Creating IAM credentials

Identity and Access Management (IAM) credentials allow you to secure access to your buckets, functions, etc.

Note

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.

  1. Click the Organization in the top right corner and Select API keys. The IAM API keys tab displays.
  2. Click + Generate an API key or the «Plus Icon» button.
  3. Select Myself (IAM) as the API key Bearer.
  4. Enter API key for the Function Tutorial as a description.
  5. Set Expiration to One Week.
  6. Select Yes, set up preferred Project.
  7. Choose the Functions Tutorial project (or the name you gave to this project).
  8. Click Generate API key.
  9. Store the Access key ID and the Secret key securely, as you will not be able to access them later.

Enabling monitoring with Cockpit

  1. Click Cockpit under Observability.
  2. Click the Grafana users tab.
  3. Click + Add user.
  4. Enter a username.
  5. Select the Editor role.
  6. Click Add user.
  7. 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.

Tip

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.

API DocsScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCareers
© 2023-2024 – Scaleway