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.
resource "aws_cloudfront_function" "test" {
name = "test"
runtime = "cloudfront-js-2.0"
comment = "my function"
publish = true
code = file("${path.module}/function.js")
}
The following arguments are required:
name
- (Required) Unique name for your CloudFront Function.code
- (Required) Source code of the functionruntime
- (Required) Identifier of the function's runtime. Valid values are cloudfront-js-1.0
and cloudfront-js-2.0
.The following arguments are optional:
comment
- (Optional) Comment.publish
- (Optional) Whether to publish creation/change as Live CloudFront Function Version. Defaults to true
.key_value_store_associations
- (Optional) List of aws_cloudfront_key_value_store
ARNs to be associated to the function. AWS limits associations to on key value store per function.This resource exports the following attributes in addition to the arguments above:
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.live_stage_etag
- ETag hash of any LIVE
stage of the function.status
- Status of the function. Can be UNPUBLISHED
, UNASSOCIATED
or ASSOCIATED
.In Terraform v1.5.0 and later, use an import
block to import CloudFront Functions using the name
. For example:
import {
to = aws_cloudfront_function.test
id = "my_test_function"
}
Using terraform import
, import CloudFront Functions using the name
. For example:
% terraform import aws_cloudfront_function.test my_test_function