Uploading and Activating a Edge Function Package
Deployment includes two steps, uploading the package and activating it.
These steps can be done via a variety of methods including the CLI, UI, API and API SDKs.
The core APIs used for all the approaches aside from the UI are to use the package upload API and the service activation API:
Upload a Compute@Edge package API
PUT /service/{service_id}/version/{version_id}/package
Activate a service version API
PUT /service/{service_id}/version/{version_id}/activate
The following provides a short description of this for each.
Uploading and Activating the Package using the CLI
The CLI is available from GitHub. Using the Fastly CLI is described in detail in the Learning Guide.
From the project root, execute the following command. The command for building the package file, fastly compute build
, should have created the file pkg/my-package.tar.gz
in your project root.
Uploading the Package with the Management Console
In the Fastly web management console, nagivate to your Compute "Service configuration" page and then use the drag-and-drop functionality to upload your Edge Code package.
The in the upper right corner of the page, click the "Activate" button.
Uploading the Package with cURL
% curl -D - -X PUT --location "https://api.fastly.com/service/SU1Z0isxPaozGVKXdv0eY/version/1/package" \
-H "Accept: application/json" \
-H "Fastly-Key: YOUR_FASTLY_TOKEN" \
-H "expect: 100-continue" \
-F "package=@/path/to/file"
Activating the Package with cURL
Uploading the Package with Go ⇗
Call the UpdatePackage
function on your fastly.Client
instance, which has the following definition:
Example function call:
// fastlyClient is an instance of `fastly.Client`
pkg, err := fastlyClient.UpdatePackage(
&fastly.UpdatePackageInput{
ServiceID: "YOUR_SERVICE_ID", // required
ServiceVersion: 1, // required. Service version is an integer
PackagePath: "/path/to/your-package.tar.gz",
},
)
Activating the Package with Go ⇗
Call the ActivateVersion
function on your fastly.Client
instance, which has the following definition:
Example function call:
Uploading the Package with JavaScript
Use the JavaScript SDK's putPackage
function:
const options = {
service_id: "service_id_example", // required
version_id: 56, // required
expect: 100-continue,
_package: "/path/to/file",
};
apiInstance.putPackage(options)
.then((data) => {
console.log(data, "API called successfully.");
})
.catch((error) => {
console.error(error);
});
Activating the Package with JavaScript
Use the activateServiceVersion
function:
Uploading the Package with PHP
Use the PHP SDK's putPackage
function:
$options['service_id'] = 'service_id_example'; // string | Alphanumeric string identifying the service.
$options['version_id'] = 56; // int | Integer identifying a service version.
$options['expect'] = 100-continue; // string | We recommend using the Expect header because it may identify issues with the request based upon the headers alone instead of requiring you to wait until the entire binary package upload has completed.
$options['package'] = "/path/to/file.txt"; // \SplFileObject | The content of the Wasm binary package.
try {
$result = $apiInstance->putPackage($options);
} catch (Exception $e) {
echo 'Exception when calling PackageApi->putPackage: ', $e->getMessage(), PHP_EOL;
}
Activating the Package with PHP
Use the PHP SDK's activateserviceversion
function:
$options['service_id'] = 'service_id_example'; // string | Alphanumeric string identifying the service.
$options['version_id'] = 56; // int | Integer identifying a service version.
try {
$result = $apiInstance->activateServiceVersion($options);
} catch (Exception $e) {
echo 'Exception when calling VersionApi->activateServiceVersion: ', $e->getMessage(), PHP_EOL;
}
Uploading the Package HTTP info
PUT /service/SU1Z0isxPaozGVKXdv0eY/version/1/package HTTP/1.1
Host: api.fastly.com
Content-Type: multipart/form-data; boundary="boundary"
Accept: application/json
Fastly-Key: YOUR_FASTLY_TOKEN
expect: 100-continue
--boundary
Content-Disposition: form-data; name="package"
(binary data ...)
Activating the Package HTTP info