Cloudflare Serverless Application
The Cloudflare Serverless Application template scaffolds a Pulumi project that deploys a serverless web application to Cloudflare. It provisions a Cloudflare Worker for the application backend, exposed on its own workers.dev subdomain, and a Workers KV namespace that the Worker reads and writes to persist state between requests. Pulumi uploads the application code as a versioned Worker version — bound to the KV namespace — and rolls it out to all of the Worker’s traffic with a Workers deployment. The template ships with a placeholder visit-counter application so the project deploys end to end out of the box.
Using this template#
To use this template to deploy your own serverless application, make sure you’ve installed Pulumi and configured your Cloudflare credentials, then create a new project using the template in the language of your choice:
mkdir my-serverless-app && cd my-serverless-apppulumi new serverless-cloudflare-typescriptmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-cloudflare-pythonmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-cloudflare-gomkdir my-serverless-app && cd my-serverless-apppulumi new serverless-cloudflare-csharpmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-cloudflare-yamlmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-cloudflare-hclFollow 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.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yaml for a closer look.
Deploying the project#
The template needs one setting to deploy: the Cloudflare account ID to deploy into. Set it, then deploy with pulumi up:
pulumi config set accountId <your-account-id>pulumi uppulumi config set accountId <your-account-id>pulumi uppulumi config set accountId <your-account-id>pulumi uppulumi config set accountId <your-account-id>pulumi uppulumi config set accountId <your-account-id>pulumi uppulumi config set account_id <your-account-id>pulumi upWhen the deployment completes, Pulumi exports the following stack output value:
- url
The fully-qualified HTTPS URL of the deployed application on its
workers.devsubdomain.
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:
open $(pulumi stack output url)Cleaning up#
You can cleanly destroy the stack and all of its infrastructure with pulumi destroy:
pulumi destroyLearn more#
- Browse other architecture templates in the Templates gallery.
- Explore the Cloudflare provider API docs in the Pulumi Registry.
- Walk through Pulumi from the ground up in Pulumi Tutorials.
- Read the latest Cloudflare posts on the Pulumi blog.