Skip to content

Creating functions

Creating a function writes a local project and its func.yaml configuration. It does not build an image, publish it, or create resources on a cluster.

Prerequisites

A cluster, Docker daemon, and registry credentials are not required to create a project from the built-in templates.

Choose a language and template

List the runtime identifiers and templates available to your installed CLI:

func languages
func templates
kn func languages
kn func templates

Use the identifier shown by the CLI for --language; for example, Node.js uses node. Choose --template http for an HTTP handler or --template cloudevents for a CloudEvents handler. The built-in default is http. These choices determine the generated handler signature, not whether a deployed function is subscribed to a Broker.

For example, to create a Go CloudEvents project:

func create --language go --template cloudevents hello-events
kn func create --language go --template cloudevents hello-events

See function templates for language-specific handler contracts, or language packs to use an external template.

Create the project

The following example creates an HTTP project using the default template:

After you have installed Knative Functions, you can create a function project by using the func CLI or the kn func plugin:

func create -l <language> <function-name>

Example:

func create -l go hello
kn func create -l <language> <function-name>

Example:

kn func create -l go hello

Expected output

Created go function in hello

For more information about options for function create commands, see the func create documentation.

Verify and continue

Confirm that the new directory contains func.yaml and the generated source files. Read the project's README and the language-specific template documentation before changing the handler signature or dependencies.

If creation fails, check the runtime/template identifiers and destination directory first. For external packs, also check repository access and the provider's template layout; installing a pack does not guarantee its build or runtime compatibility.

We use analytics and cookies to understand site traffic. Information about your use of our site is shared with Google for that purpose. Learn more.