> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://akamai.ferndocs.com/edge-workers/create-a-code-bundle/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://akamai.ferndocs.com/_mcp/server.
# Create a code bundle
Refer to these guidelines to create an EdgeWorkers code bundle.
EdgeWorkers functions are defined in a file entitled `main.js`. You also need to create a manifest file called `bundle.json`. These are packaged together, along with any other dependencies as a compressed `.tgz` file.
For example, a package called `mybundle.tgz` includes two files:
- `main.js`. The JavaScript source that contains event handler functions.
- `bundle.json`. The manifest file that includes necessary meta information.
> π The EdgeWorkers code bundle cannot contain any executable files.
>
> Any files with a `.\_` notation inside the EdgeWorkers code bundle are ignored.
> π You cannot re-use a version that you deleted from an EdgeWorker ID. You need to use a new unique version in the `bundle.json` and re-package it and any other files with your `main.js` file.
| Name | Type | Required | Description |
| --- | --- | :---: | --- |
| `edgeworker-version` | String | β | Unique identifier for the version
If you delete a version from an EdgeWorker ID you cannot re-use it. Follow the steps below to create a new code bundle that you can use to create a version. |
| `bundle-version` | Integer | β | Bundle format version |
| `api-version` | String | β | Version of JavaScript API that the functions are coded against |
| `description` | String | β | Descriptive phrase for the code function |
| `misc` | Object | β | Miscellaneous data you can include in the manifest to identify the function |
Follow these steps to create the bundle.
> π You can also use the code bundle editor to [create an EdgeWorker version](manage-edgeworkers.md#create-an-edgeworker-version).
1. Create the JavaScript source in a file called `main.js`.
You can also [enable subWorkers](create-a-code-bundle-copy.md#enable-subworkers) and [change the default JavaScript logging level](create-a-code-bundle-copy.md#change-the-default-javascript-logging-level) in the `main.js` file.
2. Each time you create a new version of the code bundle you need to increment the `edgeworker-version` in the `bundle.json` file.
```json
{
"edgeworker-version": "1.2",
"description" : "Perform redirect"
}
```
3. Compress the files into a code bundle.
Make sure that the code bundle doesn't contain any executable files. If you include any executable files in the .tgz it will fail when you try to upload it.
```
tar -czvf filename.tgz main.js bundle.json
```
Once you have created the code bundle, you can use the [EdgeWorkers Management application](manage-edgeworkers.md) to create an EdgeWorker version.
# Code bundle configuration settings
These configuration settings let you enable or disable EdgeWorkers features from within the code bundle.
## Enable subWorkers
To enable subWorkers you need to add the `invoke-for-edgeworker-clients` config setting to the `bundle.json` file and set it to `true`. For more information, go to [Create a subWorker](create-a-subworker.md) in this guide.
| Name | Description |
| :------------------------------ | :----------------------------------------------------------------------------------------------------------- |
| `subrequest` | Includes config settings for sub-requests. Currently it only includes βinvoke-for-edgeworkers-clientβ. |
| `invoke-for-edgeworkers-client` | When set to true, it enables support for subWorkers. By default, this configuration setting is set to false. |
```json
{
"edgeworker-version": "0.2",
"description" : "Hello World Example",
"config": {
"subrequest": {
"invoke-for-edgeworker-clients": true
}
}
}
```
If the configuration setting is set to `false` or not included, the EdgeWorkers function will return an information status 22, `SubworkerNotEnabled`, if a sub-request is made to the EdgeWorkers URL. The sub-request will continue to process without invoking the EdgeWorker.
## Change the default JavaScript logging level
You can set the [JavaScript logging](enable-javascript-logging.md) in the code bundle and deliver these logs using a [DataStream 2](https://techdocs.akamai.com/datastream2/docs/welcome-datastream2) stream. By default, JavaScript logs are set to ERROR.
> π For more information about how to deliver the logs, go to the [Use DataStream 2 to deliver JavaScript logs](ds2-javascript-logging.md) tutorial.
To change the default JavaScript log level you need to add the `logging` config setting to the `bundle.json` file.
| Name | Description |
| --- | --- |
| `level` | The log level applied to the EdgeWorkers code bundle. You can use this parameter to override the default log level, ERROR.
The log levels are **trace**, **debug**, **info**, **warn**, and **error**. |
| `schema` | Not currently in use. Use `v1` as a placeholder. |
| `ds2id` | The DataStream2 stream id to associate with the log data.
The stream needs to be active before you include it in the EdgeWorkers code bundle.
When you add the `logging` config setting to the `bundle.json` file, the `ds2id` is required. |
You can change the `ds2id` using the [EdgeWorkers CLI](https://github.com/akamai/cli-edgeworkers).
```json
{
"edgeworker-version": "1.2.3",
"bundle-version": 1,
"api-version": "0.3",
"description": "A bundle describing overriding the default log level.",
"config": {
"logging": {
"level": "info",
"schema": "v1",
"ds2id": 1234
}
}
}
```
## Enable True Client-IP
Pass the [True-Client-IP request header](request-object.md#clientip) forward in a sub-request. When enabled, the origin receives the IP address of the client.
| Name | Description |
| :----------------- | :--------------------------------------------------------------------------------------------------------------------------------------- |
| `client-ip-header` | When set to true, it enables the origin to receive the IP address of the client. By default, this configuration setting is set to false. |
```json
{
"edgeworker-version": "0.2",
"description" : "Hello World Example",
"config": {
"logging": {
"level": "error"
},
"subrequest": {
"invoke-for-edgeworker-clients": false
},
"client-ip-header": true
}
}
```
## Docs
- [Code bundle format](https://akamai.ferndocs.com/edge-workers/code-bundle-format.md):