Compute@Edge services

Compute@Edge is a computation platform capable of running custom binaries that you compile on your own systems and upload to Fastly. Security and portability is provided by compiling your code to WebAssembly, which we run at the edge using Lucet, an open-source WebAssembly runtime created by Fastly.

WARNING: Compute@Edge is in limited availability, but the status of individual language support varies. Our support for Rust is also limited availability. AssemblyScript support is currently in beta. For more information, see our product and feature lifecycle descriptions.

Create a new Fastly account and invite your collaborators

Fastly must enable a Compute@Edge feature flag on a new Fastly account. We associate that feature flag with the customer ID (CID) of your new account to help you isolate your production activities from those you test and experiment with.

  1. Create a new account by following the steps in our signup form.
  2. Log in to your new account and find your customer ID. This appears in the Company settings page within the Account section of the web interface.
  3. Provide your Fastly contact with your CID so they can enable the Compute@Edge feature flag for your account.
  4. If you wish, invite additional users to your new account. Remember, these users must not already be collaborators on another Fastly account.

Generate an API token

Compute@Edge services use packages built on your computer using the Fastly CLI. To authenticate the Fastly CLI, you must create an API token for your account. Follow the steps for creating an API token, make sure it has global scope, and make a note of the token. The token will only allow access to the account you are using for Compute@Edge, and not your normal Fastly account.

Download and install the Fastly CLI

The Fastly CLI is available from a number of package registries.

  • MacOS: Install from Homebrew:
    $ brew install fastly/tap/fastly
  • Windows: Install from Scoop:
    $ scoop bucket add fastly-cli https://github.com/fastly/scoop-cli.git
    $ scoop install fastly
  • Linux: Packages are available for Debian/Ubuntu, Fedora, CentOS, and SUSE, along with prebuilt binaries. Visit the GitHub repo to download the package for your distro and see installation instructions for your package manager.

Verify everything works by running fastly version. For example:

$ fastly version
Fastly CLI version vX.Y.Z (abc0001)
Built with go version go1.13.1 linux/amd64

The CLI will notify you if a new version is available. You can update it using the fastly update command.

Configure the Fastly CLI

The CLI interacts with Fastly via our API, authenticated using an API token. Configure the CLI to act on your behalf using the token you previously created. Choose one of the following options to give the CLI access to your API token:

  • (Recommended) Run fastly configure and follow the interactive prompts. This will store your API token credential in a configuration file and remember it for subsequent commands.
  • Include the token explicitly on each command you run using the --token or -t flags.
  • Set a FASTLY_API_TOKEN environment variable.

For an overview of all available commands, run fastly with no arguments. Succinct help about any command or subcommand is available via the --help flag (e.g., fastly service -h). For verbose help, use the help command (e.g., fastly help service).

Provision a new Compute@Edge service

Use the CLI setup wizard to provision a new Fastly service with the type of "wasm" (it’s the default type, so you don’t need to specify it). By default, the CLI will generate source code for your project in the current working directory.

To get you started, Fastly provides a library of Compute@Edge applications that are ready to compile and run on your service, so you can start from a working example that is as close as possible to the solution you are trying to achieve.

Right now, we offer the following starter kits:

When you initialize a Compute@Edge project with fastly compute init, you'll be prompted to choose one of these starter kits.

Start the setup wizard:

$ fastly compute init

The system will display a series of prompts with which you can specify details about your service.

Name: [example]
Description: hello world rust project
Author: Service Author
Language:
[1] Rust
[2] AssemblyScript (beta)
Choose option: [1] 1
Starter kit:
[1] Default (https://github.com/fastly/fastly-template-rust-default.git)
Choose option or type URL: [1]
Domain: [random-funky-words.edgecompute.app]
Backend (originless, hostname or IP address): [originless]

At the prompts, provide details about the service you're creating:

  • Name: Enter a name for your service. By default, the CLI will use the name of the current directory.
  • Description: Enter a short description for your service, or leave it blank.
  • Author: The CLI will offer to use the email address of the user associated with your API token, but you can provide a different email address as the author of the service package if desired.
  • Language: Select the toolchain you wish to use to build your service.
  • Starter kit: Choose from the available starter kits or press enter to accept the default. You may also enter the URL of a GitHub repo to use a template not in in the list.
  • Domain: Press enter to accept the automatically generated domain name (we'll take care of the TLS and DNS and give you a working domain immediately) or enter the name of the domain you'd like to associate with your service. You can also accept the default now and add more domains to the service later if you prefer.
  • Backend: If you want to configure an origin server for your service, enter a valid hostname, or an IPv4 or IPv6 address. Alternatively enter (or accept the default) "originless" to create a service with no origin server. Such services cannot forward requests to your servers, but they can respond to client requests with a response composed within your Compute@Edge package.

Currently, it is not possible for Fastly services to have no backend, so if you choose specify "originless", a backend with address 127.0.0.1 will be added to the service. This backend will not accept traffic and can be deleted if you add a real origin server later.

Once you've responded to all the prompts, the CLI will display a series of service initialization messages, as well as some useful links and commands for working with your service:

✓ Initializing...
✓ Creating service...
✓ Creating domain...
✓ Creating backend...
✓ Fetching package template...
✓ Updating package manifest...
Initialized package example to:
/DIR/SERVICE_AUTHOR/example
Manage this service at:
https://manage.fastly.com/configure/services/PS1Z4isxPaoZGVKVdv0eY
To compile the package, run:
fastly compute build
To deploy the package, run:
fastly compute deploy
SUCCESS: Initialized service PS1Z4isxPaoZGVKVdv0eY

The service initialization process provides a link to your service in the Fastly web interface. You can use this link to access features that allow you to do a variety of things like add or manage domains, change origin server names, and set up logging endpoints.

Install local dependencies

To build your project, the Fastly CLI requires your local toolchain to be available and up to date. To install the toolchain for your chosen language, follow these instructions:

  1. Rust
  2. AssemblyScript

Compiling Rust applications for Compute@Edge requires Rust 1.46.0 and the wasm32-wasi toolchain. Install Rust and its dependencies so you can begin building Compute@Edge services:

Install Rust:

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.46.0

If you already have rustup installed:

$ rustup toolchain add 1.46.0

Install the wasm32-wasi target for the 1.46.0 toolchain:

$ rustup target add wasm32-wasi --toolchain 1.46.0

Compile the project to a Wasm binary

HINT: If you want to dive right in to the code, check out the language-specific guides on Using Rust or Using AssemblyScript.

After editing the source code, you'll compile it into a WebAssembly module that can be packaged for Fastly use. The Fastly CLI internally runs your language's compiler and generates the necessary WebAssembly binary.

$ fastly compute build

A successful build looks like this:

$ fastly compute build
✓ Initializing...
✓ Verifying package manifest...
✓ Verifying local <selected language> toolchain...
✓ Building package using <selected language> toolchain...
✓ Creating package archive...
SUCCESS: Built <selected language> package tmp (pkg/tmp.tar.gz)

During the limited availability phase of Compute@Edge, we require that your toolchain is up to date to build a package, so you may see a warning if you need to update before you can build.

Deploy the project to your Fastly service

Once you’re happy with your code and want to deploy the project to Fastly, run the deploy command:

$ fastly compute deploy
✓ Initializing...
✓ Reading package manifest...
✓ Validating package...
✓ Fetching latest version...
✓ Uploading package...
✓ Activating version...
✓ Updating package manifest...
Manage this service at:
https://manage.fastly.com/configure/services/PS1Z4isxPaoZGVKVdv0eY
View this service at:
https://random-funky-words.edgecompute.app
SUCCESS: Deployed package (service PS1Z4isxPaoZGVKVdv0eY, version 1)

After the command completes, it may take up to an additional 20 seconds before the package begins handling requests, and any previous version of the package may continue to handle requests for up to a minute (there will be no previous version on your first deploy).

Test and celebrate

Open a browser or use a command line HTTP client such as cURL to issue a request to the domain that you assigned to the service.

$ curl -si "https://previously-solid-mite.edgecompute.app/"
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 31
date: Wed, 27 May 2020 20:42:32 GMT
Welcome to Fastly Compute@Edge!

Or if you prefer, test it in a web browser:

Compute@Edge welcome content

Next Steps

Now that you have a working project deployed, you have the basic building blocks in place to be successful with Compute@Edge.

If you would like to learn more about how Compute@Edge integrates with your preferred language, read our getting started guides for Using Rust or Using AssemblyScript.

If you are already familiar with VCL and want to migrate an existing VCL configuration to Compute@Edge, try the VCL to Compute@Edge migration guide, which shows examples of the most common use cases in VCL and how to implement the same functionality using Compute@Edge's supported languages.

Or maybe you have an idea in mind and you want to experiment with examples? Try cloning a starter kit, copy and pasting code from some recipes, or following a tutorial.

Feedback

As an early customer, your feedback is invaluable to us and will help shape the future of Compute@Edge. We'd really appreciate any and all feedback on your experience, but especially any experiences related to:

  • problems you had with the onboarding process.
  • problems you had with the tools: the Fastly CLI or our Rust crates.
  • problems you have with the programming model or the architecture of your application
  • things that you haven’t been able to do, especially those you were expecting to but couldn’t.

Please be aware that not all features available within VCL services are yet available in Compute@Edge.

If you aren't sure where to provide feedback, your Fastly account contact can help or you can contact support@fastly.com.