Functions are blocks of code that run on demand without the need to manage any infrastructure. Develop on your local machine, test your code from the command line (using
doctl), then deploy to a production namespace or App Platform — no servers required. Learn more about functions.
A Functions project is a collection of resources including functions, configuration files, and library files, which are stored on your local computer or in a GitHub repository. Projects have a prescriptive structure that they must follow in order to deploy them to App Platform or a Functions namespace.
You can create a project manually, but we recommend the following ways to get started:
doctl serverless init <project-name> to initialize a project with a minimal set of files and example code.
Fork one of the sample repositories of our example projects.
The project root can either be the root of a Git repository or a subdirectory in a monorepo. This top-level project root must contain the following:
A project configuration file called
project.yml. See Project Configuration for more details.
A directory named
packages containing one or more packages. A package is a collection of functions. Each package must have its own directory under
Each function must be in a package directory. Functions can be a single source code file or a directory with one or more source code files.
packages directory can contain any number of packages, and each package can contain an arbitrary number of functions. This lets you organize your project in the way that makes the most sense to you.
The organization of packages determines the URL where functions are served. Functions components deployed to App Platform are served at a URL with the structure
The project can also contain a top-level
lib directory, where files common to multiple packages can be stored or built. See Build Process for details on the build process and its use of the
Here is a barebones example of the structure of a project:
example-project ├── project.yml └── packages └── example-package └── example-function.php
Here is an example structure for a project with two packages,
example-package-1 has three functions, and
example-package-2 has one.
example-project ├── packages │ ├── example-package-1 │ │ ├── example-function-a.php │ │ ├── example-function-b │ │ │ ├── package.json │ │ │ └── example.js │ │ └── example-function-c │ │ └── index.php │ └── example-package-2 │ └── example-function │ ├── requirements.txt │ ├── __main__.py │ └── example.py └── project.yml