DeleteFunctionCommand

Deletes a CloudFront function.

You cannot delete a function if it's associated with a cache behavior. First, update your distributions to remove the function association from all cache behaviors, then delete the function.

To delete a function, you must provide the function's name and version (ETag value). To get these values, you can use ListFunctions and DescribeFunction.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { CloudFrontClient, DeleteFunctionCommand } from "@aws-sdk/client-cloudfront"; // ES Modules import
// const { CloudFrontClient, DeleteFunctionCommand } = require("@aws-sdk/client-cloudfront"); // CommonJS import
const client = new CloudFrontClient(config);
const input = { // DeleteFunctionRequest
  Name: "STRING_VALUE", // required
  IfMatch: "STRING_VALUE", // required
};
const command = new DeleteFunctionCommand(input);
const response = await client.send(command);
// {};

DeleteFunctionCommand Input

See DeleteFunctionCommandInput for more details

Parameter
Type
Description
IfMatch
Required
string | undefined

The current version (ETag value) of the function that you are deleting, which you can get using DescribeFunction.

Name
Required
string | undefined

The name of the function that you are deleting.

DeleteFunctionCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.

Throws

Name
Fault
Details
FunctionInUse
client

Cannot delete the function because it's attached to one or more cache behaviors.

InvalidIfMatchVersion
client

The If-Match version is missing or not valid.

NoSuchFunctionExists
client

The function does not exist.

PreconditionFailed
client

The precondition in one or more of the request fields evaluated to false.

UnsupportedOperation
client

This operation is not supported in this Amazon Web Services Region.

CloudFrontServiceException
Base exception class for all service exceptions from CloudFront service.