DigitalOcean Spaces is an object storage service offering a simple, scalable, and affordable way to store any data: audio, videos, images, backups, documents, and much more. It scales on-demand, and you pay only for what you use.
You can learn more about DigitalOcean Spaces here.
When using DigitalOcean Spaces, you may want to perform data-processing when an event occurs on your bucket to transform, analyze, or optimize your data. DigitalOcean does not provide the primitive to achieve this kind of operation.
Koyeb is a serverless data-processing platform that offers a simple, robust, and scalable way to deploy processing functions to perform data operations and manipulations in minutes regardless of the cloud service provide you use.
This guide demonstrates how to deploy a processing function on Koyeb that generates a thumbnail each time a new image file is uploaded on your DigitalOcean Spaces bucket.
To successfully follow and implement this tutorial, you need:
To implement this guide and generate a thumbnail each time a file is uploaded to your DigitalOcean bucket, you need to follow these four steps:
To get started, you need to generate a new DigitalOcean Spaces access key to connect your DigitalOcean Spaces bucket to Koyeb. Connecting your DigitalOcean Spaces bucket to Koyeb is a mandatory step to benefit from the Koyeb processing engine.
To generate a new Spaces key pair, on the DigitalOcean control panel, click API in the left-side menu.
You land on the Applications & API page where you can manage your API tokens, and Spaces access keys. In the Space access key section, click the Generate New Key button.
A modal appears and prompts you to enter a Token Name. Give the Spaces access key a name you will remember what it is used for and click the check icon.
In the table, you now see your access key and secret key. Copy and save these values in a safe place. You will use them in the next step to connect your DigitalOcean Spaces bucket to Koyeb.
Now that you have generated a DigitalOcean Spaces key pair, you need to connect your DigitalOcean bucket to Koyeb. This operation allows Koyeb to access your DigitalOcean 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 DigitalOcean.
A form appears that asks for the information about the Spaces bucket you want to connect:
doaccesskeyand the access key you previously saved as the value
doprivatekeyand the private key you previously saved as value
You created a Koyeb Store, which lets you access the content of your DigitalOcean Spaces 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 your function when an event occurs in the DigitalOcean Spaces bucket, you need to use the Koyeb S3 API endpoint to upload your content instead of the DigitalOcean one.
Once your Store configuration is done; you can now create a Stack and deploy the function to generate a thumbnail each time a new image is uploaded to your DigitalOcean Spaces bucket.
On the top navigation bar, click the Create button and select Stack.
You land on the Stack creation page. Stack is a Koyeb resource used to implement data-processing logic. A Stack is composed of two core elements:
On 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.
Then, give your Stack a name. Here I named my stack
do-image-processing and click the Create Stack button.
You are now asked 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 Image resize and select this function. A snippet appears. Replace the configuration variables with your settings.
functions: - name: image-resize use: email@example.com with: STORE: #The store to watch to trigger the function and save the resized image. This parameter is required. do-spaces-koyeb IMAGE_RESIZE_WIDTH: #The desired image width. Set to auto if not defined. This parameter is optional. 150 IMAGE_RESIZE_PATH: #The path to store the new generated image. This parameter is optional. resized-images/ IMAGE_RESIZE_FORMAT: #The format of the new generated image. This parameter is optional. jpeg
This configuration uses the
firstname.lastname@example.org catalog app to convert all images to a width of 150px in the JPEG format and store the result in the
The function will be triggered each time an image is uploaded to your DigitalOcean 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.
Click the Upload button and upload some images. In a few seconds, a folder
resized-images will appear. For each image uploaded, you will receive the associated thumbnail in this folder.
In the folder
resized-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 resized image.
In this guide, you saw how to implement a processing function to generate a thumbnail for each image uploaded to a Koyeb Store. This Store is connected to a DigitalOcean Spaces bucket and allows you to upload and manage content via the Koyeb S3-Compatible API to benefit from Koyeb's S3-Compatible event-driven processing features.
If you would like to read more Koyeb tutorials, checkout out our tutorials collection. Have an idea for a tutorial you'd like us to cover? Let us know by joining the conversation over on the Koyeb community platform!
Koyeb is a developer-friendly serverless platform to deploy any apps globally.Start for free
Deploy 2 services for free and enjoy our predictable pricing as you grow
Get up and running in 5 minutes