Integrate with Property Manager
This tutorial integrates a Spin application - deployed to your Akamai Functions account - with an existing Akamai Property to route requests through your property to the Spin application.
The goal of this tutorial is to route a specific path on your existing property, for example, <https://www.mydomain.com/hello> to your Spin application deployed to Akamai Functions.
As this guide does not provide an introduction to Akamai Properties you may want to consult the Akamai Property Manager documentation.
Prerequisites
Before you start this tutorial, make sure you have the following prerequisites. You can also follow the steps in the Quickstart guide to get up and running with Akamai Functions in less than two minutes.
- Create and configure a Property in Akamai Control Center.
- Sign up for the public preview so you can login to Akamai Functions. If you haven’t already requested access, please complete the Onboarding form.
- Install Spin and the aka Plugin for Spin.
Build and deploy the Spin app
We'll use a simple Spin application as part of this tutorial.
- Use the
spinCLI to create a new application using thehttp-jstemplate and move it into the application directory.
spin new -t http-js -a hello-akamai-functions
cd hello-akamai-functions- To modify the implementation of the app, replace the contents of the
index.jsfile with the following lines of JavaScript code. Theindex.jsfile is located in thesrcdirectory of your application.
Fimport { AutoRouter } from 'itty-router';
let router = AutoRouter();
router.get("/", () => new Response("Hello, Akamai Functions"));
addEventListener('fetch', async (event) => {
event.respondWith(router.fetch(event.request));
});- Once you’ve updated the
src/index.jsfile, use thespin buildcommand to compile your source code to WebAssembly. Then use thespin aka deploycommand to deploy the application to Akamai Functions.
spin build
spin aka deployYou need to be authenticated to use the
spin aka deploycommand. Use thespin aka logincommand to authenticate using your Akamai Control Center or GitHub account credentials.
- The
spin aka deploycommand will generate an output similar to the one shown below.
Name of new app: hello-akamai-functions
Creating new app hello-akamai-functions 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-akamai-functions
Waiting for app to be ready... ready
App Routes:
- hello-akamai-functions: https://ec8a19d8-6d10-4056-bb69-cc864306b489.aka.akamai.tech (wildcard)- Copy the URL from the output in your terminal window, we’ll need it in a second to configure the Akamai Property.
Route traffic to the Spin application through an Akamai property
Next, we have to update the Property in Akamai Control Center.
- Navigate to Akamai Control Center and find your Property.
- Open its latest version, and press the Edit New Version button (located in the top right corner).
- From the Property Configuration Settings click the + Rule button, select the Blank Rule Template and provide a name for the new rule.
- Next, add a new match condition using the + Match button from the Criteria panel and configure it for
Pathtomatches one ofand add/hello/*as the value.
With the match condition in place, we can add the custom behaviors using the Behaviors panel.
- Add the Origin Server behavior using the Standard Property Behavior button from within the + Behavior drop-down button. We’ll leave the majority of properties settings unchanged. However, ensure to update these fields.
| Field name | Desired value |
|---|---|
| Origin Server Hostname | <origin* of your Spin application.You can use the spin aka app status command or spin aka deploy command to find the origin server host name of your Spin application. |
| Forward Host Header | Origin Hostname |
You can get the origin of your Spin Application by removing the
https://prefix and the trailing slash (/) from the end of its URL.
- Next, we'll prevent the Akamai Property from sending the routing criteria
(/hello/)as a path to the Spin application running on Akamai Functions.
To do this, we'll add a Modify Outgoing Request Path behavior to our rule. Use the Standard Property Behavior button from within the + Behaviors drop-down button. Update the following fields in the Modify Outgoing Request Path behavior.
| Field name | Desired value |
|---|---|
| Action | Replace Part of the incoming path |
| Find what | /hello/ |
| Replace with | / |
| Occurrences | First occurrence only |
| Keep the query parameters | Yes |
Here are the behaviors configured for this tutorial.
Click the Save button.
Activate the new property version
At this point, the new rule isn’t active, yet! We have to activate the latest version of our Property in order for our changes to take effect. Activate the latest version of your Property using the Activate tab.
We highly recommend activating and testing the property modifications using the Staging environment instead of going straight to production.
Call the Spin app through the Akamai property
To test the rule added as part of this tutorial, you can use a tool like curl to send a GET request to https://engineerd.xyz/hello/ . Make sure you replace https://engineerd.xyz with the domain associated to your Property.
If the rule is configured correctly, we should see the same response being printed to stdout as if we would send a GET request to the root route of our Spin application deployed to Akamai Functions.
curl https://engineerd.xyz/hello/You should see Hello, Akamai Functions printed to stdout. This means that you’ve successfully integrated a Spin application, running on Akamai Functions, with an existing Property.
Updated 6 days ago
