Copy of Quickstart
Follow the steps in this Quickstart guide to get up and running with Akamai Functions in less than two minutes. Akamai Functions is the platform for running Spin applications on Akamai Cloud.
To complete this tutorial you need access to the public preview of Akamai Functions. If you haven’t already requested access, please complete this form. The Akamai Functions team will review your request and follow up shortly.
Install Spin
Spin is an open-source project you can use to build, run, and deploy Spin applications. It's both a CLI tool and a runtime. It provides SDKs for a variety of programming languages, including, but not limited to, Rust, Go, JavaScript and TypeScript.
To find the Spin version installed on your machine run, spin --version.
Install the aka plugin for Spin
aka plugin for SpinTo interact with Akamai Functions, you need to install the Akamai Functions for Akamai Spin plugin, aka. Use this command to install the plugin.
$ spin plugin install aka
If you’ve previously installed the aka plugin, take a moment to upgrade it to ensure compatibility with the latest features and fixes.
$ spin plugins update
$ spin plugins upgrade aka
You can learn more about managing Spin plugins in this article.
Go to the aka spin command reference for a complete list of supported commands.
Install language specific tooling
With Spin you can build applications using a wide variety of different programming languages. This quickstart, contains instructions and samples for JavaScript, TypeScript and Rust.
Follow these instructions to install language specific tooling on your machine.
Go to, WebAssembly language support matrix for more information about the supported languages.
JavaScript
To build Spin apps with JavaScript, you need Node.js installed on your system. Head over to https://nodejs.org/en/download, to download Node.js.
Once Node.js is installed on your machine, you can check its version using the following command.
node --version
v22.13.0
We recommend Node.js version 22 (or newer).
Create a new Spin application
Next we’ll prepare an application with Spin. There are code samples below for you to use, but you can write an app from scratch or use an existing template. The Spin Hub has many reference examples and templates. You can also find several code samples, sorted by use case in the Akamai Functions GitHub repo.
JavaScript
$ spin new -t http-js --accept-defaults hello-spin
The http-js template creates the application boilerplate for you. Once it's finished, change to the application directory (hello-spin).
$ cd hello-spin
From within the application directory, install the necessary dependencies using your package manager of choice (we'll use npm here).
$ npm install
The http-js template generates an idiomatic JavaScript application. Take a few seconds and explore the source code generated by the template in src/index.js.
// For AutoRouter documentation refer to <https://itty.dev/itty-router/routers/autorouter>
import { AutoRouter } from 'itty-router';
let router = AutoRouter();
// Route ordering matters, the first route that matches will be used
// Any route that does not return will be treated as a middleware
// Any unmatched route will return a 404
router
.get("/", () => new Response("hello universe"))
.get('/hello/:name', ({ name }) => `Hello, ${name}!`)
addEventListener('fetch', async (event) => {
event.respondWith(router.fetch(event.request));
});
Compile the application
Use the spin build command to compile your Spin app to WebAssembly.
$ spin build
Building component hello-spin with `npm run build`
> hello-spin@1.0.0 build
> npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -d combined-wit -n combined -o target/hello-spin.wasm
asset dist.js 5.93 KiB [compared for emit] [javascript module] (name: main)
orphan modules 25.5 KiB [orphan] 25 modules
./src/spin.js + 2 modules 5.95 KiB [built] [code generated]
webpack 5.97.1 compiled successfully in 66 ms
Using user provided wit in: combined-wit
Successfully written component
Finished building all Spin components
Test the application locally
You can test your Spin apps on your local computer by using the spin up command anytime. The spin up command starts an HTTP server on your local machine (port 3000 by default) and instantiates and invokes your Spin application for every request sent to the endpoint.
$ spin up
Logging component stdio to ".spin/logs/"
Serving <http://0.0.0.0:3000>
Available Routes:
hello-spin: <http://0.0.0.0:3000> (wildcard)
If port
3000is already in use, you could set a different port by specifying the--listenflag. For example,spin up --listen 127.0.0.1:3001.
From within an separate terminal instance, you can use a tool like curl to send an HTTP request to your Spin app
curl -i http://localhost:3000/HTTP/1.1 200 OK
content-length: 14
content-type: text/plain;charset=UTF-8
date: Tue, 14 Jan 2025 16:10:36 GMT
Hello, Fermyon
You can terminate spin up at anytime, by pressing CTRL+C.
Login to Akamai Functions
To Login you need access to the public preview of Akamai Functions. If you haven’t already requested access, please complete the Onboarding form. The Akamai Functions team will review your request and follow up shortly.
Once you’ve installed the aka plugin for Spin, and you have access to the public preview you can login. You'll need your GitHub account information to login.
$ spin aka login
Go to <https://login.infra.fermyon.tech/realms/neutrino/device?user_code=BB-AA>
and follow the prompts.
Don't worry, we'll wait here for you. You got this.
Click the link displayed as part of the output from the spin aka login command. Authenticate using your individual GitHub Account and authorize the spin CLI for interacting with your Akamai Functions account.
Deploy the application
You can use the spin aka deploy command to deploy the application to Akamai Functions.
spin aka deploy
The spin command runs using the Spin binary in your system path. It reads the Spin application definition file spin.toml in the current (hello-spin) directory to know what application to deploy. It will ask you for a name for the application and then it will ask for confirmation that you want to deploy.
Here's an example of a successful Spin application deployment on Akamai Functions.
Name of new app: hello-spin
Creating new app hello-spin in account your-account
Note: If you would instead like to deploy to an existing app, cancel this deploy and link this workspace to the app with `spin aka app link`
OK to continue? yes
Workspace linked to app hello-spin
Waiting for app to be ready... ready
App Routes:
- hello-spin: https://ec8a19d8-6d10-4056-bb69-cc864306b489.fwf.app (wildcard)
You can CTRL+Click on the link in the terminal window to visit the web application you just deployed.
Congratulations, you’ve now deployed your first Spin application to Akamai Functions!
Updated about 2 hours ago
