GuideReference
TrainingSupportCommunity
Guide

Enable EdgeWorkers functions

Dynamically manage your web traffic, customize visitor experiences, and eliminate trips to your origin by creating and deploying an edge-native application on the edge.

👍

Tip

See the Akamai Edge Computing demo for EdgeWorker use cases with and without EdgeKV.

What you'll do

After completing some admin tasks to set up the product, you'll create an EdgeWorker and add to it your bundled JavaScript code.

❗️

Important

Because the set up for EdgeWorkers affects your company's billing plan, Terraform integration for EdgeWorkers requires admin access to your Akamai account.

Complete admin tasks

Complete these initial tasks to set up EdgeWorkers using Akamai Control Center, Akamai EdgeWorkers CLI, or the EdgeWorkers API.

  1. Ensure EdgeWorkers is enabled on your account. If not, add it through the Marketplace.
  2. Make sure you have read and write privileges to the EdgeWorkers API. See roles and permission levels for guidance on selecting the right type of access.
  3. Get your contract and group IDs.
  4. Choose a resource tier to set your resource consumption in the Create an EdgeWorker step.
  5. Understand EdgeWorkers product limitations.
  6. If you intend to use an optional EdgeKV with your EdgeWorkers instance, review the EdgeKV product limitations.

With these steps complete, you're ready to create an EdgeWorker.

Create an EdgeWorker

📘

EdgeWorkers are stateless and relay responses without storing any information by default. To create a stateful instance, add an EdgeKV database.

  1. Combine the group ID and resource tier you chose with a unique name to create an EdgeWorker.

    resource "akamai_edgeworker" "my_edgeworker" {
      group_id         = 12345
      name             = "My_EdgeWorker"
      resource_tier_id = 100
    }
    
  2. Run terraform plan to check your syntax and then terraform-apply to create the EdgeWorker. Creation can take up to 20 minutes.

Returned to you on completion is your EdgeWorker's ID. Use it to add your code bundle and in activation.

Add an EdgeKV database

You can add an optional EdgeKV database to make your EdgeWorker instance stateful. This lets you save information about interactions with your site.

❗️

Important

You are responsible for maintaining control over the data hosted through this service and for the appropriate use of the data returned.

While EdgeKV encrypts data at rest and in transit, it does not protect against unauthorized disclosure or support the storage of sensitive information. Choosing to store sensitive information would be a serious business or compliance issue.

  1. Import the EdgeKV helper library into your JavaScript bundle and configure for your business need.

  2. Create an EdgeKV database.

    resource "akamai_edgekv" "my_edgekv" {
      network              = "STAGING"
      namespace_name       = "My_EdgeKV"
      retention_in_seconds = 15724800
      group_id             = 12345
    }
    
  3. Add in a group and items. Groups work to classify the types of information saved in the database, and items represent those types using key-value pairs.

    Note: The group_name here is the name of the group to which your items belong, not your contract's group name.

    resource "akamai_edgekv_group_items" "my_group_items" {
      namespace_name = "My_EdgeKV"
      network        = "staging"
      group_name     = "My_EKV_group"
      items = {
        key1 = "value1"
        key2 = "value2"
        key3 = "value3"
      }
    }
    
  4. Run terraform plan to check your syntax and then terraform-apply when you're ready to create and activate your database.

Configure property rule

Before you can activate your EdgeWorker and use it on a network, it needs to be included in your property configuration.

  1. Create a rule or use an existing rule.
  2. Add the EdgeWorker behavior.
  3. Set its criteria.
  4. Configure your site failover strategy.
  5. Activate or reactivate your property.

If you haven't already, bundle your JavaScript and add it to your EdgeWorker. If you have, activate your EdgeWorker.

Bundle your JavaScript

Bundle your JavaScript code and a manifest in a .tgz file to add it to your EdgeWorker.

  1. Name your JavaScript file main.js. It should include the EdgeWorkers library, and if you associated an EdgeKV database, its library with your use case configuration.

  2. Provide at least your EdgeWorker's version number in a manifest file named bundle.json.

    NameTypeDescriptionRequired
    edgeworker-versionStringYour EdgeWorker's version.✔️
    bundle-versionIntegerBundle format version.
    api-versionStringVersion of JavaScript API when the EdgeWorkers code was created.
    descriptionStringPhrase describing the EdgeWorkers script function.
    miscObjectInformation you can include in the manifest to identify the EdgeWorkers function.
  3. Compress your JavaScript and manifest. Your tar command may vary.

    $ tar -czf <filename>.tgz main.js bundle.json
    
  4. Add it to your EdgeWorker.

    resource "akamai_edgekv" "my_edgekv" {
      network              = "STAGING"
      namespace_name       = "My_EdgeKV"
      retention_in_seconds = 15724800
      group_id             = 12345
      local_bundle         = "./my_bundle.tgz"
    }
    
  5. Run terraform plan to check your syntax and then terraform-apply when you're ready to add your bundle.

You're ready to activate your EdgeWorker on a network.

Test and go live

Activate your property on staging first, promoting your configuration to production when you're satisfied with your test results.

resource "akamai_edgeworkers_activation" "my_activation" {
  edgeworker_id = 12345
  network       = "STAGING"
  version       = "1"
}

Run terraform plan to check your syntax and then terraform-apply to activate your EdgeWorker. Activation can take up to 20 minutes.