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 Akamai Functions.
- 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 -E akamai-functions -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.fwf.app (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.
- Select Functions as the Origin Type for your Origin Server.
It is not required that you select Functions, but it is highly recommended.
When you select Functions as the Origin type the Global Request Number behavior is automatically added to your property. This behavior generates a unique identifier for each request on the Akamai edge network.
If you pass the Global Request Number with custom metadata you should use
AKA_GRN_HEADERas the header name to prevent duplication when selecting Functions as the Origin Type.
- Add the Akamai Functions origin that you want to use to retrieve the content in the Functions Origin textbox.
- 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 about 13 hours ago
