Skip to content

Resource: awsCloudfrontFunction

Provides a CloudFront Function resource. With CloudFront Functions in Amazon CloudFront, you can write lightweight functions in JavaScript for high-scale, latency-sensitive CDN customizations.

See CloudFront Functions

\~> NOTE: 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.

Example Usage

Basic Example

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.cloudfrontFunction.CloudfrontFunction(this, "test", {
  code: '${file("${path.module}/function.js")}',
  comment: "my function",
  name: "test",
  publish: true,
  runtime: "cloudfront-js-1.0",
});

Argument Reference

The following arguments are required:

  • name - (Required) Unique name for your CloudFront Function.
  • code - (Required) Source code of the function
  • runtime - (Required) Identifier of the function's runtime. Currently only cloudfrontJs10 is valid.

The following arguments are optional:

  • comment - (Optional) Comment.
  • publish - (Optional) Whether to publish creation/change as Live CloudFront Function Version. Defaults to true.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • arn - Amazon Resource Name (ARN) identifying your CloudFront Function.
  • etag - ETag hash of the function. This is the value for the development stage of the function.
  • liveStageEtag - ETag hash of any live stage of the function.
  • status - Status of the function. Can be unpublished, unassociated or associated.

Import

CloudFront Functions can be imported using the name, e.g.,

$ terraform import aws_cloudfront_function.test my_test_function