We’re very excited to announce that Cloudflare Workers are now integrated into the Serverless framework as a serverless cloud provider! Serverless’ open source framework has become a must-have for many developers, and we want to make it as simple as possible to harness the power of Cloudflare’s distributed computing network.
You can now define the entire structure and routing behavior of your Workers scripts in code and deploy them with ease using
serverless deploy from your own development environment. Store configuration files in version control alongside your application code. And feel more confident testing your application with
serverless invoke, a new way to quickly send requests to endpoints of interest with specific arguments and headers.
What is Serverless?
Serverless is a paradigm for building applications without concern for the underlying infrastructure. It lets developers focus on writing code and lets them deploy quickly and cheaply to a cloud provider which manages servers, networking, and configuration.
The Serverless framework takes this a step further. It empowers developers to write applications with consistent tooling and project structure, which speeds up development and simplifies deployment to common cloud providers.
Our new plugin lets you use
serverless command line tool, which you may already be accustomed to, but with Cloudflare Workers! Define the structure of your Worker in
serverless deploy it to our 152+ data centers around the world.
How simple is it? Here’s a complete
serverless.yml for a Slackbot running on Workers. Serverless uses the idea of functions (as in functions-as-service) to separate concerns within an application. For Workers, a function is your application, and the
script field refers to the name of your Worker script locally on disk.
service: name: slack-bot config: accountId: CLOUDFLARE_ACCOUNT_ID zoneId: CLOUDFLARE_ZONE_ID workers: slackbot: routes: - slackbot.example.com provider: name: cloudflare plugins: - serverless-cloudflare-workers functions: SlackBot: worker: slackbot script: bot
To deploy your new Worker, simply run
serverless deploy or
serverless deploy -f SlackBot.
$ npm install -g serverless $ serverless create --template cloudflare-workers --path new-project $ cd new-project $ npm install $ export [email protected] $ export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY $ serverless deploy
cloudflare-workers-enterprise template if you're on an enterprise plan in order to deploy multiple scripts to Workers.
Interested? Get started by reading the docs.
Are you building something cool with Workers? Let us know!
If you are in the San Francisco Bay Area, and are interested in hearing from Bay Area serverless experts and explorers, you're invited to come by tonight's Serverless Meetup. RSVP here! Doors open at 6.