---
title: "Cloudflare Serverless Application"
description: "Deploy a serverless application on Cloudflare with Pulumi, Cloudflare Workers, and Workers KV in TypeScript, Python, Go, C#, YAML, or HCL."
url: "https://www.pulumi.com/dev/templates/serverless-application/cloudflare/"
image: "https://www.pulumi.com/assets/og/dev/templates/serverless-application/cloudflare.png"
---

# Cloudflare Serverless Application

Deploy a serverless application on Cloudflare with Pulumi, Cloudflare Workers, and Workers KV in TypeScript, Python, Go, C#, YAML, or HCL.

The Cloudflare Serverless Application template scaffolds a Pulumi project that deploys a serverless web application to Cloudflare. It provisions a [Cloudflare Worker](https://www.pulumi.com/registry/packages/cloudflare/api-docs/worker/) for the application backend, exposed on its own `workers.dev` subdomain, and a [Workers KV namespace](https://www.pulumi.com/registry/packages/cloudflare/api-docs/workerskvnamespace/) that the Worker reads and writes to persist state between requests. Pulumi uploads the application code as a versioned [Worker version](https://www.pulumi.com/registry/packages/cloudflare/api-docs/workerversion/) --- bound to the KV namespace --- and rolls it out to all of the Worker's traffic with a [Workers deployment](https://www.pulumi.com/registry/packages/cloudflare/api-docs/workersdeployment/). The template ships with a placeholder visit-counter application so the project deploys end to end out of the box.

![An architecture diagram of the Cloudflare Serverless Application template](./architecture.svg)

## Using this template

To use this template to deploy your own serverless application, make sure you've [installed Pulumi](https://www.pulumi.com/docs/install/) and [configured your Cloudflare credentials](https://www.pulumi.com/registry/packages/cloudflare/installation-configuration/), then create a new [project](https://www.pulumi.com/docs/iac/concepts/projects/) using the template in the language of your choice:

**TypeScript**

```bash
mkdir my-serverless-app && cd my-serverless-app
pulumi new serverless-cloudflare-typescript
```

**Python**

```bash
mkdir my-serverless-app && cd my-serverless-app
pulumi new serverless-cloudflare-python
```

**Go**

```bash
mkdir my-serverless-app && cd my-serverless-app
pulumi new serverless-cloudflare-go
```

**C#**

```bash
mkdir my-serverless-app && cd my-serverless-app
pulumi new serverless-cloudflare-csharp
```

**YAML**

```bash
mkdir my-serverless-app && cd my-serverless-app
pulumi new serverless-cloudflare-yaml
```

**HCL**

```bash
mkdir my-serverless-app && cd my-serverless-app
pulumi new serverless-cloudflare-hcl
```

Follow the prompts to complete the new-project wizard. When it's done, you'll have a complete Pulumi project that's ready to deploy and configured with the most common settings. Feel free to inspect the code in `index.ts` for a closer look.

## Deploying the project

The template needs one setting to deploy: the [Cloudflare account ID](https://developers.cloudflare.com/fundamentals/account/find-account-and-zone-ids/) to deploy into. Set it, then deploy with [`pulumi up`](https://www.pulumi.com/docs/iac/cli/commands/pulumi_up):

**TypeScript / Python / Go / C# / YAML**

```bash
$ pulumi config set accountId <your-account-id>
$ pulumi up
```

**HCL**

```bash
$ pulumi config set account_id <your-account-id>
$ pulumi up
```

When the deployment completes, Pulumi exports the following [stack output](https://www.pulumi.com/docs/iac/concepts/stacks/#outputs) value:

**`url`**

The fully-qualified HTTPS URL of the deployed application on its `workers.dev` subdomain.

Output values like this one are useful in many ways, most commonly as inputs for other stacks or related cloud resources. The computed URL, for example, can be used from the command line to open the newly deployed application in your favorite web browser:

```bash
$ open $(pulumi stack output url)
```

## Cleaning up

You can cleanly destroy the stack and all of its infrastructure with [`pulumi destroy`](https://www.pulumi.com/docs/iac/cli/commands/pulumi_destroy):

```bash
$ pulumi destroy
```

## Learn more

- Browse other architecture templates in the [Templates gallery](https://www.pulumi.com/templates).
- Explore the [Cloudflare provider API docs](https://www.pulumi.com/registry/packages/cloudflare) in the Pulumi Registry.
- Walk through Pulumi from the ground up in [Pulumi Tutorials](https://www.pulumi.com/dev/browse/?type=tutorial).
- Read the latest [Cloudflare posts on the Pulumi blog](https://www.pulumi.com/blog/tag/cloudflare).
