AWS Fundamentals Logo
AWS Fundamentals
L1 ConstructAWS::CloudFront::Function

CfnFunction

Creates a CloudFront function. To create a function, you provide the function code and some configuration information about the function. The response contains an Amazon Resource Name (ARN) that uniquely identifies the function, and the function’s stage. By default, when you create a function, it’s in the `DEVELOPMENT` stage. In this stage, you can [test the function](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/test-function.html) in the CloudFront console (or with `TestFunction` in the CloudFront API). When you’re ready to use your function with a CloudFront distribution, publish the function to the `LIVE` stage. You can do this in the CloudFront console, with `PublishFunction` in the CloudFront API, or by updating the `AWS::CloudFront::Function` resource with the `AutoPublish` property set to `true` . When the function is published to the `LIVE` stage, you can attach it to a distribution’s cache behavior, using the function’s ARN. To automatically publish the function to the `LIVE` stage when it’s created, set the `AutoPublish` property to `true` .

Import

import { CfnFunction } from 'aws-cdk-lib/aws-cloudfront';

Or use the module namespace:

import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
// cloudfront.CfnFunction

Properties

Configuration passed to the constructor as CfnFunctionProps.

functionCodeRequired
string

The function code. For more information about writing a CloudFront function, see [Writing function code for CloudFront Functions](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/writing-function-code.html) in the *Amazon CloudFront Developer Guide* .

functionConfigRequired
IResolvable | FunctionConfigProperty

Contains configuration information about a CloudFront function.

nameRequired
string

A name to identify the function.

autoPublishOptional
boolean | IResolvable

A flag that determines whether to automatically publish the function to the `LIVE` stage when it’s created. To automatically publish to the `LIVE` stage, set this property to `true` .

functionMetadataOptional
IResolvable | FunctionMetadataProperty

Contains metadata about a CloudFront function.

CloudFormation Resource

This L1 construct maps directly to the following CloudFormation resource type.

Get the Amazon CloudFront Cheat Sheet

Everything you need to know about Amazon CloudFront on one page. HD quality, print-friendly.

Download Free Infographic