Company News
Tuesday, November 12th 2019
Customizing Serverless Functions
Posted by
When extending your project with Serverless Functions, you might find yourself in a situation where adjusting the default behavior is necessary.
Today, we are adding a new functions
configuration property to allow you to do just this.
Custom Memory & Execution Duration
In most cases, zero configuration is required to create deployments with Vercel. Every Serverless Function (in all projects created after November 8th) receives the following attributes by default:
- Memory: 1024 MB (1 GB)
- Maximum Execution Duration: 5s (Hobby), 10s (Pro), or 30s (Enterprise)
Now, you can customize these values in your vercel.json
file like so:
{ "functions": { "api/test.js": { "memory": 3008, "maxDuration": 10 } }}
Read more about the constraints for each property in our documentation.
Community Runtimes
When deploying Serverless Functions without configuration (using the /api directory), you can choose from a list of officially supported languages.
If the language you'd like to use is not part of this list, you can add functions
to your vercel.json
file to assign Community Runtimes to your Serverless Functions.
Community Runtimes are provided by a third-party, for example, vercel-php:
{ "functions": { "api/test.php": { "runtime": "vercel-php@0.0.10" } }}
After configuring the functions
property, your api/test.php
Serverless Function will be executed using the vercel-php
Community Runtime.
If you are interested in using a Community Runtime or creating one yourself, check out the following documentation pages:
API Changes
If you are developing applications on top of the Vercel API, you will need to use v11
of the deployment creation endpoint to take advantage of the functions
property.
Conclusion
With the new functions
property, you can configure the memory and maximum execution duration of your Serverless Functions, or assign a custom runtime.
builds
property will be deprecated in favor of functions
.This is just one of several features we are planning to launch in order to support advanced use cases of Serverless Functions on Vercel.
Let us know what you think about this change!