Hello World using the EdgeWorkers Management application

Here's a high-level overview of the steps required to activate a code sample using the EdgeWorkers Management application.

For instructions on how to return detailed debugging information about your EdgeWorkers, go to the Enhanced debug headers section.

Step Description Link
1 Create a code bundle using the hello world code sample. Create the Hello World code bundle
2 Use the EdgeWorkers Management application to create an EdgeWorker ID, and to create and activate an EdgeWorker version. Activate the Hello World code bundle with the UI
3 Enable the EdgeWorkers behavior on a Property. Add the EdgeWorkers behavior to a Property
4 Test your EdgeWorkers function. Test the Hello World code sample

Create the Hello World code bundle

The EdgeWorkers code bundle must contain the main.js and bundle.json files.

Before you begin

Review the steps required to create an EdgeWorkers function.

How to

  1. Create a folder on your computer for the code bundle files.
  2. Go to the Akamai EdgeWorkers GitHub repository and download the main.js and bundle.json files from the helloworld project or create them using the values below.
  3. Use the Hello World code sample to create the JavaScript source in a file called main.js.
    // Hello World Example
    
    export function onClientRequest(request) {
      request.respondWith(
          200, {},
          '<html><body><h1>Hello World From Akamai EdgeWorkers</h1></body></html>');
    }
    
    export function onClientResponse(request, response) {
      response.setHeader('X-Hello-World', 'From Akamai EdgeWorkers');
    }
  4. Increment the edgeworker-version in the bundle.json file.
  5. Compress the files into a code bundle.
    tar -czvf filename.tgz main.js bundle.json

Activate the Hello World code bundle with the UI

Once you've created the code bundle you can use the EdgeWorkers Management application to activate your Hello World code sample on the staging network.

Before you begin

Review the steps in Hello World using the EdgeWorkers Management application.

How to

  1. Log in to Control Center.
  2. Go to > CDN > EdgeWorkers.
  3. Click Create EdgeWorker ID.
    A unique identifier is auto-generated and cannot be edited.
    Create an EdgeWorker ID
  4. Enter a name for the EdgeWorker ID.
    Your EdgeWorker name can be 1 to 64 characters long, and contain only alphanumeric (0-9, a-z, A-Z), period (.), space ( ), and hashtag (#) characters.
  5. Select a Group Association.
    You can only select a group that you have permission to access.
  6. Click Create EdgeWorker ID.
  7. From the EdgeWorkers IDs page, click on the EdgeWorker ID or name that you just created.
  8. Click the Create version button.
    Create a version
  9. Drag and drop the Hello World code bundle onto the window and click the Create version button.
  10. From the EdgeWorkers versions page, select the Hello World EdgeWorker.
    Only the EdgeWorkers you have permission to access appear in the list.
  11. Click the Activate version button.
  12. Select the EdgeWorker version that you want to activate.
  13. Select the Staging network to test the Hello World code sample.

Add the EdgeWorkers behavior to a Property

This section describes how your Akamai administrator can enable the EdgeWorkers behavior in Property Manager. This step can also be used to define which requests apply EdgeWorkers functions. By limiting the scope you can avoid unnecessary serverless hits to improve performance and reduce cost.

Before you begin

Make sure you have reviewed the prerequisites. To complete this an Akamai administrator will need to access the Akamai Control Center.

How to

  1. Navigate to your property in Control Center.
    You can use Property Manager to scope where and when to execute the EdgeWorker function.
  2. Click Edit.
  3. Click Add rule.
  4. Enter a name.
  5. Choose a match criteria and scope.
    Note: The criteria allows you to define which requests apply EdgeWorkers functions. By limiting the scope you can avoid unnecessary serverless hits.
  6. Search for EdgeWorkers in available behaviors.
  7. Change the setting to On.
  8. Click Insert Behavior.
  9. Select an EdgeWorker identifier from the list.
    If you haven't created an EdgeWorker identifier, click the link in the information dialog. The EdgeWorkers Management application will open in a new window.

    Once you have created your EdgeWorker identifier, close the window and reload the Property Manager Editor page. Now you can select the new EdgeWorker identifier from the list.
  10. Save your property.
  11. Click the Activate tab.
  12. Click the Activate v<#> on Staging or Activate v<#> on Production button.

Test the Hello World code sample

To test the Hello World code sample make a request to exercise the EdgeWorker and note the response.

Before you begin

Activate the Hello World code sample on your staging network.

How to

Use the following curl request, resolved to staging, to exercise the Hello World EdgeWorker.
For instructions on how to resolve an IP address refer to the Getting Started for HTTPS Properties documentation.
curl http://[your website name]/helloworld --resolve [your website name]:80:[your staging ip address]
The curl request should produce the following HTML output:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 70
Date: Wed, 20 Nov 2019 17:09:17 GMT
Connection: keep-alive
X-Hello-World: From Akamai EdgeWorkers

<html><body><h1>Hello World From Akamai EdgeWorkers</h1></body></html>