Skip to main content

Configuration

A configuration file is required to run any CLI commands. This file contains function configuration and acts as a deployment manifest. For those familiar with the Serverless framework, it's analogous to a serverless.yml file.

The file must export default an object matching the Config type.

By default, the framework will look for a cf-functions.ts file in the current working directory when running a CLI command. This behaviour can be modified by including the -c {filepath} argument to any command.

Example​

import { Config, DistributionEventType } from "cf-functions";

export const config: Config = {
pathPrefix: "/src/handlers",
defaultRuntime: "cloudfront-js-1.0",
functions: {
AddHeader: {
handler: "/add-header/index.ts",
test: "/add-header/test.ts",
description:
"Adds the x-custom-header HTTP header to request.",
associations: [
{
distributionId: process.env.DISTRIBUTION_ID!,
eventType: DistributionEventType.VIEWER_REQUEST,
behaviourPattern: "default",
},
],
},
},
};

export default config;

Reference​

NameTypeDescriptionisRequired
pathPrefixStringPath segment to prepend to any function handler or test file paths.No
defaultRuntimeStringThe CloudFront Function runtime to be used by each function.No
functionsArrayObject map containing list of functions.Yes
functions[Name]KeyEach object key represents the name of a function.Yes
functions[Name].handlerStringThe file path to the function handler code.Yes
functions[Name].testStringThe file path to the function test code.No
functions[Name].descriptionStringA brief description of what the function does. This will appear in the AWS console.No
functions[Name].isEnabledBooleanDetermines whether the function is ignored by CLI commands (defaults true)No
functions[Name].associationsArrayThe CloudFront Distributions that the function is associated with.Yes
functions[Name].associations[0].distributionIdStringThe unique identifier of the CloudFront Distribution (found in the AWS console)Yes
functions[Name].associations[0].eventTypeStringThe CloudFront event which triggers the function - "viewer-request" or "viewer-response"Yes
functions[Name].associations[0].behaviourPatternStringThe string pattern of the CloudFront Distribution behaviour to associate the function with.Yes