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.
Before you begin
Important
Because the set up for EdgeWorkers affects your company's billing plan, Terraform integration for EdgeWorkers requires admin access to your Akamai account.
- Understand the basics of Terraform.
- Complete the steps in Get started.
- Have your JavaScript code bundled.
How to
Complete admin tasks
Complete these initial tasks to set up EdgeWorkers using Akamai Control Center, Akamai EdgeWorkers CLI, or the EdgeWorkers API.
- Ensure EdgeWorkers is enabled on your account. If not, add it through the Marketplace.
- Set up roles and permission levels for those roles.
- Choose a resource tier to set your resource consumption.
- Understand EdgeWorkers product limitations.
- If you intend to use an 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.
-
Combine your group ID and resource tier choice with a unique name to create an EdgeWorker.
resource "akamai_edgeworker" "my_edgeworker" { group_id = 12345 name = "My_EdgeWorker" resource_tier_id = 100 }
-
Run
terraform plan
to check your syntax and thenterraform-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
Add an EdgeKV database to make your EdgeWorker instance stateful so you can 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. Your choosing to store sensitive information would be a serious business or compliance issue.
-
Import the EdgeKV helper library into your JavaScript bundle and configure for your business need.
-
Create an EdgeKV database.
resource "akamai_edgekv" "my_edgekv" { network = "STAGING" namespace_name = "My_EdgeKV" retention_in_seconds = 15724800 group_id = 12345 }
-
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" } }
-
Run
terraform plan
to check your syntax and thenterraform-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.
- Create a rule or use an existing rule.
- Add the EdgeWorker behavior.
- Set its criteria.
- Configure your site failover strategy.
- 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.
-
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. -
Provide at least your EdgeWorker's version number in a manifest file named
bundle.json
.Name Type Description Required edgeworker-version
String Your EdgeWorker's version. ✔️ bundle-version
Integer Bundle format version. api-version
String Version of JavaScript API when the EdgeWorkers code was created. description
String Phrase describing the EdgeWorkers script function. misc
Object Information you can include in the manifest to identify the EdgeWorkers function. -
Compress your JavaScript and manifest. Your
tar
command may vary.$ tar -czf <filename>.tgz main.js bundle.json
-
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" }
-
Run
terraform plan
to check your syntax and thenterraform-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.
Updated 2 months ago