EdgeWorkers

Dynamically manage your web traffic, customize visitor experiences, and eliminate trips to your origin by deploying your custom JavaScript together with our EdgeWorkers code on the edge.

Get base IDs

You need your contract IDs to work with these commands. If you don't have it, run Get-Contracts to get one.

Get EdgeWorkers

  1. Get a list of all your current EdgeWorkers.

    List-Edgeworkers
    
    edgeWorkerId     : 12345
    name             : My-Edgeworker
    accountId        : A-CCT1234
    groupId          : 12345
    resourceTierId   : 200
    createdBy        : jsmith
    createdTime      : 11/29/2022 11:24:31 AM
    lastModifiedBy   : jsmith
    lastModifiedTime : 12/29/2022 12:52:01 PM
    
    edgeWorkerId     : 56789
    name             : My-Edgeworker-2
    accountId        : A-CCT1234
    groupId          : 12345
    resourceTierId   : 100
    createdBy        : jsmith
    createdTime      : 12/1/2022 8:22:21 AM
    lastModifiedBy   : jsmith
    lastModifiedTime : 12/1/2022 8:22:21 AM
    

    Use response provides values for groupId, edgeworkerID, and name you can use in downstream commands.

  2. Use an EdgeWorker's name or ID to get its details.

Create new EdgeWorker

Create a new EdgeWorker using your group ID and assigning a resource tier. Resource tiers let you select between different sets of resource consumption limits for your EdgeWorker's functions.

There two resource tiers available, basic compute and dynamic compute. To identify which tier you assign to your EdgeWorker, pass its respective number as the -ResourceTierID parameter's value.

  • Basic compute = 100
  • Dynamic compute = 200
  1. Get your group ID and name.

    # List all EdgeWorker groups
    List-EdgeWorkerGroups
    
    # List all Edgeworker groups response
    groupId     groupName                         capabilities
    -------     ---------                         ------------
    grp_12345     John and Jane                     {VIEW, EDIT, DELETE, VIEW_VERSION…}
    grp_X123    Admin Users                       {VIEW, EDIT, DELETE, VIEW_VERSION…}
    grp_X4567   old_group                         {VIEW, EDIT, DELETE, VIEW_VERSION…}
    grp_X89012  test 2                            {VIEW, EDIT, DELETE, VIEW_VERSION…}
    
    
  2. Pass a unique name, your group ID or group name, and a resource tier designation to create a new EdgeWorker.

    New-EdgeWorker -Name demo -GroupID 12345 -ResourceTierID 200
    
    edgeWorkerId     : 12123
    name             : My-edgeworker-3
    accountId        : A-CCT1234
    groupId          : 12345
    resourceTierId   : 200
    createdBy        : jsmith
    createdTime      : 1/11/2023 9:43:29 PM
    lastModifiedBy   : jsmith
    lastModifiedTime : 1/11/2023 9:43:29 PM
    

List Resource Tiers

Get a list of your EdgeWorkers' resource tiers with your contract ID.

List-EdgeWorkerResourceTiers -ContractId C-0N7RAC7
resourceTierId resourceTierName edgeWorkerLimits
-------------- ---------------- ----------------
100 Basic Compute    {@{limitName=Maximum CPU time during initialization; limitValue=60; limitUnit=MILLISECOND}, @{limitName=Maximum wal…
200 Dynamic Compute  {@{limitName=Maximum CPU time during initialization; limitValue=60; limitUnit=MILLISECOND}, @{limitName=Maximum wal…

Update an EdgeWorker

You can update the name of an existing EdgeWorker or create a new version of your EdgeWorker to update its code bundles.

Update name

Using the Set command with your group ID, pass values for both the old name and a new name.

Set-Edgeworker -Name My-edgeworker -NewName My-new-name -GroupID 12345
edgeWorkerId     : 12345
name             : My-new-name
accountId        : A-CCT1234
groupId          : 12345
resourceTierId   : 200
createdBy        : jsmith
createdTime      : 11/29/2022 11:24:31 AM
lastModifiedBy   : jsmith
lastModifiedTime : 1/11/2023 10:07:50 PM

Update with new version

To update an existing EdgeWorker with a new code bundle, create a new version and provide the file path.

📘

This requires your operating system to support the tar command. Windows only started shipping tar with Windows 10 version 17063. If your version of Windows is older than that, you will need to create the .tgz manually.

# Windows
\---demo_ew
      bundle.json
      main.js

# MacOS or Linux
~/demo_ew ls -a
.    ..    bundle.json    main.js	
# Windows
New-EdgeWorkerVersion -Name My-edgeworker-2 -CodeDirectory .\demo_ew\

# Mac
# 1. Change into your code bundle's directory
$ cd demo_ew 
# 2. Create a .tar file of the contents
$ tar czf example.tgz *
# 3. Pass exact path to the .tar to create a new version
$ New-EdgeWorkerVersion -Name My-edgeworker -CodeBundle ~/demo_ew/example.tgz
edgeWorkerId   : 12345
version        : 6
accountId      : A-CCT1234
checksum       : checksum0d383242729cf94c893caf8aeacc150ed72af368a6903f34b2c1a4ab
sequenceNumber : 2
createdBy      : jsmith
createdTime    : 1/12/2023 7:40:45 PM

For Windows users, PowerShell will read the version number from the bundle.json file, create a .tgz file from the contents of the folder, excluding any other .tgz present, and push out your bundle update.

For Mac or Linux users, you have to create the .tgz yourself and then run the version command to push your bundle update.

When you're done making changes, activate your Edgeworker on the network.

Activating an EdgeWorker

When you're ready to apply your changes, activate your EdgeWorker on either STAGING or PRODUCTION.

Activate-EdgeWorker -Name <string> -Version <string> -Network {STAGING | PRODUCTION}
edgeWorkerId     : 12345
version          : 6
activationId     : 1
accountId        : A-CCT1234
status           : PRESUBMIT
network          : STAGING
createdBy        : jsmith
createdTime      : 1/12/2023 8:17:32 PM
lastModifiedTime : 1/12/2023 8:17:32 PM

Your activation will cycle through presubmit and pending states before it's complete and live on the network you chose.