Create a code bundle

Refer to these guidelines when creating your EdgeKV-enabled EdgeWorkers code bundle.

To create a code bundle, package the following files together, along with any other dependencies as a compressed .tgz (tarball) file:

  • main.js

  • bundle.json

  • edgekv.js (helper library)

  • edgekv_tokens.js (access token)

    For more information go to Create a code bundle in the EdgeWorkers User Guide.

Add the main.js and bundle.json files

The main.js file contains JavaScript source code that contains the event handler functions for EdgeWorkers. The bundle.json file is the manifest file that includes the necessary metadata information about your application.

  1. Create a local folder for your EdgeWorkers code bundle.

  2. Create the main.js file, write your EdgeWorkers code, and add it to the code bundle folder.

    You need to use the following import statement to add the edgekv.js helper file to your code bundle:

import { EdgeKV } from './edgekv.js';

📘

You'll receive an error message if this import statement is missing even if the edgekv.js helper file is included in the code bundle.

👍

You can also download the hello-world example from the EdgeKV GitHub repo.

  1. Create the bundle.json manifest file and add it to the code bundle folder.

    For instructions on how to create a bundle.json file see Create a code bundle in the EdgeWorkers User Guide.

Download the EdgeKV helper library

To access the EdgeKV database, your EdgeWorkers code bundle must include the JavaScript helper library.

The edgekv.js library file:

  • Allows you to set the namespace and/or group to use.
  • Uses the methods provided in the library to access the specified namespace and group in the EdgeKV database.
  • Provides read/write/delete methods that allow you to easily access the data from within an EdgeWorker.
  • Leverages the EdgeWorkers async promise-based capabilities.
  • Allows you to set a timeout on the EdgeKV request to specify the maximum time to wait for the response.
  1. Go to the Akamai EdgeWorkers GitHub repository and download the edgekv.js file.

    For detailed library documentation refer to the Library helper methods section.

  2. Copy the edgekv.js file to your code bundle folder.

📘

The the edgekv.js helper file is not required when using the administrative APIs to control EdgeKV database functions outside of EdgeWorkers code.

Add the access token file

The edgekv.js library automatically uses the appropriate token to access the corresponding namespace. If a token is missing, an exception is thrown by the EdgeKV methods with a 401 error.

  1. Add the edgekv_tokens.js file containing the EdgeKV access token to your EdgeWorkers code bundle folder.