We're excited to bring you major improvements to Appwrite Functions, making them more versatile and powerful than ever before.
With the new Functions, you can now stay within the Appwrite ecosystem. The fully integrated features reduce friction points, allowing you to focus on development while trusting that your Functions will run smoothly and automatically.
Previously, Appwrite Functions faced limitations in handling file-based tasks and real-time operations due to slow synchronous execution and cumbersome API key management. With the introduction of easier Appwrite SDK integration within Functions, these constraints are lifted, opening doors to more use cases and more efficient workflows.
Faster Functions cold-starts
We've significantly accelerated Functions cold-start times through infrastructure optimizations. This means you can expect faster response times for all your Functions, both new and existing.
Cold starts occur when a Function is invoked for the first time or after a period of inactivity. This initial delay is caused by the system provisioning resources and loading the function's code.
Now, all your Functions, regardless of when they were created, benefit from faster startup times without any additional effort on your part. There's no need to make any changes to your code or configuration – the improvement is automatic.
Dynamic API keys
API key management is a time-consuming, error-prone task that can distract developers from building core features. Keeping track of multiple API keys across different environments (development, staging, production) can be overwhelming, but if compromised, they can lead to unauthorized access, data breaches, and financial loss. The stakes are high.
To combat this, we've introduced automatically generated, short-lived API keys for each execution. They’re designed to simplify managing and updating your API keys, saving you time and reducing security risks.
Here's how you can use them:
import { Client, Databases } from 'node-appwrite';
export default async ({ req, res }) => {
const client = new Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(req.headers['x-appwrite-key']);
const databases = new Databases(client);
// Your function logic here
return res.empty();
};
With this setup, you no longer need to manually create and manage API keys. The APPWRITE_FUNCTION_API_ENDPOINT and APPWRITE_FUNCTION_PROJECT_ID environment variables are automatically provided, and the API key is available in the request headers.
Delayed executions
Now, you can schedule Functions to run at a specific time in the future, unlocking new opportunities for time-sensitive workflows.
Here's how to create a delayed execution:
const functions = new Functions(client);
const invoiceDate = new Date();
invoiceDate.setDate(invoiceDate.getDate() + 30);
await functions.createExecution(
'invoicesApi', // Function ID
'{"userId":"ngu9ife0efwed"}', // Body
true, // Async execution
'/v1/invoices/exports', // Path
'POST', // Method
{}, // Headers
invoiceDate.toISOString() // New scheduledAt attribute
);
This feature is perfect for scheduling marketing emails, cleanup tasks, or precisely timed events.
Binary executions
We've long relied on JSON and XML for structured data exchange, but these formats fall short when it comes to handling files like images, audio, or video. With the introduction of binary executions, Appwrite Functions can now seamlessly process and transfer these file types.
Functions can now handle binary data, both as input and output, which is particularly useful for file processing, AI interactions, and more.
This allows you to work with formats like multipart form-data, Protocol Buffers, or raw binary data directly within your functions.
Here’s how you can use them:
import OpenAI from "openai";
import fetch from "node-fetch";
export default async ({ req, res, log, error }) => {
// Receiving binary data
const buffer = req.bodyBinary;
// Using binary data (create image variation)
const openai = new OpenAI();
const images = await openai.images.createVariation({
model: "dall-e-2",
image: buffer,
n: 1,
size: "1024x1024"
});
const image = await fetch(images.data[0].url);
// Sending binary data
return res.binary(await image.arrayBuffer());
}
This allows for new use cases like sending files to AI services or generating files on the fly.
Execution and deployment filtering
You can now filter Function executions and deployments based on various attributes, making it easier to monitor and debug your Functions:
// Example of filtering executions (specific implementation may vary)
const executions = await functions.listExecutions(
'functionId',
[
Query.equal('status', 'completed'),
Query.equal('requestMethod', 'POST'),
Query.equal('deploymentId', 'latest')
]
);
Of course, it’s also possible to filter executions from the Appwrite Console:
You can now quickly find and analyze specific executions based on criteria like status, request method, or deployment ID.
Build anything
With the new Functions ecosystem, you can now use Functions for a wider range of applications, from AI-powered image generation to scheduled tasks and beyond. We’re excited to see what developers will create with this expanded toolkit. Here are a few ideas to get you started:
Build AI-powered image generation services
Create scheduled data backup and cleanup routines
Implement sophisticated marketing automation workflows
Develop real-time data processing pipelines
And more…
Check out these resources to start building with the new Functions ecosystem: