The Kameleoon Akamai Edgeworkers Starter Kit demonstrates Kameleoon experimentation and feature flags on Akamai Edgeworkers service.
This repository is home to the Kameleoon starter kit for Akamai Edgeworkers. Kameleoon is a powerful experimentation and personalization platform for product teams that enables you to make insightful discoveries by testing the features on your roadmap. Discover more at https://kameleoon.com, or see the developer documentation.
This starter kit provides quickstart instructions for developers using the Kameleoon NodeJS SDK with Akamai Edgeworkers.
Make sure you have the following requirements before you get started:
- A Kameleoon user account. Visit kameleoon.com to learn more.
- An Akamai Account with EdgeWorkers Acces. For more information, visit the official Akamai Edgworkers product page here.
First, you'll set up an Akamai EdgeWorker. For this step, please follow the guide below:
-
Create an EdgeWorker ID.
-
Add the EdgeWorker Behavior.
-
Install the Akamai CLI.
-
Install the EdgeWorkers CLI.
-
Setup Authentication credentials. Two different sets of permissions are involved:
- Setup credentials (steps 6–7, CLI/API): generating access tokens, initializing EdgeKV and creating namespaces require the
EdgeKV Adminrole (or a custom role withEdgeKV Access Token - Create,EdgeKV Namespace - Createand the related permissions). Akamai recommends creating these credentials with the Admin role. - Kameleoon integration credentials (used in the Kameleoon App): the App only lists your EdgeKV namespaces and writes the project configuration into the selected namespace, so a restricted API client is enough:
- API service:
EdgeKVwith access levelREAD-WRITE(Control Center → Identity & Access → Users and API Clients → Edit API client → APIs). - Role: the predefined
EdgeKV Publisherrole, or a custom role including:EdgeKV Namespace - View— list namespacesEdgeKV Data - Read— read itemsEdgeKV Data - Write— write items
- Access group: the API client must belong to the access group that owns the namespace (or the namespace must be created with
groupId=0).
- API service:
Note:
Staging onlyvariants of the permissions work only with the Staging network. Without the matching permission for the selected network, Akamai returns410on Staging and401on Production.See Manage access to EdgeKV for details.
- Setup credentials (steps 6–7, CLI/API): generating access tokens, initializing EdgeKV and creating namespaces require the
-
Generate EdgeKv access tooken.
-
Initialize EdgeKv and create namespaces for the Akamai environment you plan to use.
- Go to the Integrations dashboard.
- Choose the project you’re going to work with and apply your API credentials which you obtained in step 5.
- Select Akamai Environment and namespace.
The Kameleoon Akamai EdgeWorker Starter Kit uses and extends the Kameleoon NodeJS SDK to provide experimentation and feature flagging on the edge.
Once you succesfully have an Akamai EdgeWorker set up, you can clone this starter kit, edit it, build it, and upload the build to your EdgeWorker.
-
Create a new folder and pull the code from this Starter kit.
-
Install node modules.
npm i
-
Add your Kameleoon
SITE_CODE,CLIENT_IDandCLIENT_SECRETinsrc/constants.ts. They can be found in the Kameleoon application. -
Add your Akamai
NAMESPACEinsrc/constants.ts, the one selected during the Akamai configuration in the Kameleoon App.Note: Kameleoon writes two items into the namespace:
{SITE_CODE}(legacy format for outdated SDK versions, may be removed in the future) and{SITE_CODE}_V3(current format). The starter kit derives the version from the configuration URL the SDK requests (https://sdk-config.kameleoon.eu/v3/...), so the item always matches the format the installed SDK expects. If Kameleoon releases a new breaking configuration format (e.g.{SITE_CODE}_V4), upgrading@kameleoon/nodejs-sdkto a version that supports it is enough. -
Add your edgeKv access-token in
src/lib/edgekv_tokens.js.
// example of edgekv_tokens.js
var edgekv_access_tokens = {
"namespace-kameleoon" : {
"name": "kameleoon-token",
"reference" : "32c17r413-af4d-5da2-1t6s-5aab6013e458"
},
"namespace-kameleoon2" : {
"name": "kameleoon-token2",
"reference" : "32c17r413-af4d-5da2-1t6s-5aab6013e458"
},
}
export { edgekv_access_tokens };
Note: Access tokens can be created for multiple namespaces. Each namespace should have its own object with an associated access token. Prefix the token object key with
namespace-followed by the specific namespace. The full object key should be formatted asnamespace-${namespace}
- Build the bundle.
npm run build
- Upload the bundle
npm run deploy -- {WORKER_ID}
- Activate the version
akamai edgeworkers activate {WORKER_ID} {ENVIRONMENT} {EDGEWORKER_VERSION}
WORKER_ID: Unique ID for your EdgeWorker. This can be obtained from the Akamai control center.ENVIRONMENT: The environment the EdgeWorker is being deployed on.EDGEWORKER_VERSION: The custom version of the EdgeWorker as mentioned inbundle.json. This should be updated on every new deployment.
- Enable Advanced debug headers to receive debug logs in the response headers.
Out of the box, Kameleoon's SDKs require a user-provided identifier at runtime to drive experimentation and feature flag results. If the client doesn't provide the User ID directly, this starter kit generates a unique ID as a fallback, stores it into the cookie, and re-uses it to ensure decisions are consistent throughout the user session. Alternatively, you can use an existing unique identifier available within your application and pass it in as the value for the KAMELEOON_USER_ID cookie.
For more information about Akamai EdgeWorkers, you may visit the following resources: