Backblaze B2 Cloud Storage is an S3-compatible cloud storage provider. At ¼ the price of AWS S3, Backblaze is a cost-effective option to store and manage data at scale.
You can learn more about Backblaze B2 Storage here.
Koyeb is a serverless data-processing platform that offers a simple, robust, and scalable way to deploy and process functions to perform data operations and manipulations in minutes. Regardless of the cloud service provider you use, you can connect the data hosted by that provider to Koyeb and deploy functions that process your data quickly and at scale.
Combining Koyeb with Backblaze lets you enjoy one of the most affordable object storage platforms on the market while leveraging the most powerful platform to process data.
This guide demonstrates how to deploy a processing function on Koyeb that generates a watermark each time a new image file is uploaded on your Backblaze B2 bucket.
To generate a watermark on your image files from your Backblaze B2 buckets, you need:
To generate a watermark on each image file uploaded to your Backblaze B2 bucket, you need to:
- Generate Backblaze B2 Access Keys
- Connect your Backblaze B2 Bucket to Koyeb
- Create a Stack and Deploy the Watermark Function
- Upload Images to the Bucket and View Results
To be able to connect your Backblaze B2 bucket to Koyeb, you first need to generate a
Key ID and an
You can generate this Access Key in your Backblaze Account.
Click App Keys in the left-side menu.
Scroll down the page and click Add a New Application Key.
A modal appears:
- Enter the name for your Application Key.
- Decide which buckets this Application Key can access.
- Determine what level of access this Application Key will grant.
Once you've finished entering the relevant information for this Application Key, hit Create New Key.
You will now see your new Application Key, which is composed of your keyID, keyName, and applicationKey. Copy and save this information in a safe place. You will use these values in the next step: connect your Backblaze B2 bucket to Koyeb.
Now that you have generated a Backblaze B2 key pair, you need to connect your Backblaze B2 bucket to Koyeb. This operation allows Koyeb to access your Backblaze B2 bucket and to store your images there.
On the Koyeb Control panel, click the Create button on the top right navigation bar and select Store. You will land on the Store creation page. In the list of cloud service providers, select Backblaze.
In the list of cloud service providers, select Backblaze.
A form appears that asks for the information about the Backblaze bucket you want to connect:
- Fill the bucket input with the name of your Backblaze bucket
- Enter the region your Backblaze bucket is located
- Click the Create a new Secret button under "Keyid" to securely add the keyID you previously created.
- Choose a Name for this Secret (such as
bbaccesskey) and enter the keyID you previously saved as the Value
- Select the Secret name you just created as value for the access key
- Click the Create a new Secret button under the "Applicationkey" to securely add the private key you previously created.
- Choose a Name for this Secret (such as
bbprivatekey) and enter the private applicationKey you previously saved as Value
- Select the Secret name you just created as value for the secret key
- Give the Koyeb Store a name, such as
- Click the Create Store button
You have just successfully created a Koyeb Store that mirrors the content of your Backblaze B2 bucket. Koyeb natively provides an S3-compatible API to let you interact with your Store using the S3 protocol to upload and manage your content.
Note: To trigger a function when an event occurs in your Backblaze bucket, you need to use the Koyeb endpoint to upload your content instead of the Backblaze one.
Once your Store configuration is done, you can create a Stack and deploy the function to generate a watermark each time a new image is uploaded to your Backblaze B2 bucket.
Look at the top navigation bar, click the Create button, and select Stack.
You land on the Stack creation page. A Stack is a Koyeb resource used to implement data-processing logic. A Stack is composed of two core elements:
- Event bus: To receive events from a Store or different sources
- Functions: Python, Node.js, Docker containers, or ready-to-use catalog apps triggered on specific events
From the Stack creation view, click the Simple Koyeb Versioning button. This mode allows you to directly manage your Stack via the control panel and API instead of GitHub.
Give your Stack a name, for example:
bb-watermark-image. Then click the Create Stack button.
You are now prompted to create a new Stack revision. Stack revisions allow you to version your changes, so you can rollback to a previous version in seconds and track your changes.
In the catalog function inputs, search for Watermark image and select this function.
A snippet appears. Replace the configuration variables with your settings.
functions: - name: watermark-image use: email@example.com with: STORE: #The store to watch to trigger the function and save the generated watermark image. This parameter is required. bb-bucket-koyeb WATERMARK_IMAGE_URL: #The URL of the image to be used as the watermark. This parameter is required. https://assets.koyeb.com/illustrations/koyeb-logo-square.png WATERMARK_IMAGE_LOGO_WIDTH: #The size in percentage of the watermark compared to the source image. This parameter is optional. 10 WATERMARK_IMAGE_LOGO_MARGIN: #The margin applied to the watermark image. This parameter is optional. 5 WATERMARK_IMAGE_PATH: #The file where the watermarked image is stored. This parameter is optional. watermark-images/ WATERMARK_IMAGE_LOGO_POSITION: #The placement of the watermark on the image. This parameter is optional. bottom-right WATERMARK_IMAGE_FORMAT: #The format of the watermarked image generated. This parameter is optional. jpeg
In this example configuration, the
firstname.lastname@example.org catalog function generates a watermark that:
- Is 10% the size of the image that the watermark is placed on
- Has a margin of 5 pixels
The generated watermarked image is stored in the
watermark-images/ folder of the
bb-bucket-koyeb and is saved in the JPEG format.
When you are ready, write a revision message and click Deploy Revision.
This function will be triggered each time an image is uploaded to your Backblaze Store via the Koyeb S3-Compatible API.
It's now time to upload some images to your Store and see what happens.
On the Koyeb Control Panel, click Stores and select the Store you previously created, i.e.
Click the Upload button and upload some images. In a few seconds, a folder
watermark-images/ will appear. For each image uploaded, you will receive a watermarked version of that image in this folder.
In the folder
watermark-images/, you should see your new file. Hover over the new file, and click Copy to copy the URL that appears. Enter this URL into a new tab to access and view your watermarked image.
An example image watermarked with the function:
In this guide, you saw how to implement a processing function to generate a watermarked image for each image uploaded to a Koyeb Store that is connected to a Backblaze bucket.
If you would like to follow this tutorial and use a different third-party cloud service provider than Backblaze B2, please read our documentation about how to connect a third-party store.