AWS CloudFront Distribution

This page shows how to write Terraform and CloudFormation for CloudFront Distribution and write them securely.

aws_cloudfront_distribution (Terraform)

The Distribution in CloudFront can be configured in Terraform with the resource name aws_cloudfront_distribution. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

cloudfront.tf#L1
resource "aws_cloudfront_distribution" "lib-haxe-org" {
  aliases         = ["lib.haxe.org"]
  enabled         = true
  is_ipv6_enabled = true
  price_class     = "PriceClass_100"

cloudfront_tls_distribution.tf#L1
resource "aws_cloudfront_distribution" "default" {
  viewer_certificate {
    cloudfront_default_certificate = true
  }
}

positive.tf#L1
resource "aws_cloudfront_distribution" "positive1" {
  origin {
    domain_name = aws_s3_bucket.b.bucket_regional_domain_name
    origin_id   = local.s3_origin_id

    s3_origin_config {
main.tf#L3
resource "aws_cloudfront_distribution" "pass" {
  enabled = true

  default_cache_behavior {
    response_headers_policy_id = aws_cloudfront_response_headers_policy.pass.id
  }
aws_cloudfront_access_logging.tf#L1
resource "aws_cloudfront_distribution" "allowed" {
  web_acl_id = "arn:1234"
  logging_config {}
}

resource "aws_cloudfront_distribution" "denied" {

Parameters

Explanation in Terraform Registry

Creates an Amazon CloudFront web distribution. For information about CloudFront distributions, see the [Amazon CloudFront Developer Guide][1]. For specific information about creating CloudFront web distributions, see the [POST Distribution][2] page in the Amazon CloudFront API Reference.

NOTE: CloudFront distributions take about 15 minutes to a deployed state after creation or modification. During this time, deletes to resources will be blocked. If you need to delete a distribution that is enabled and you do not want to wait, you need to use the retain_on_delete flag.

AWS::CloudFront::Distribution (CloudFormation)

The Distribution in CloudFront can be configured in CloudFormation with the resource name AWS::CloudFront::Distribution. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Parameters

Explanation in CloudFormation Registry

A distribution tells CloudFront where you want content to be delivered from, and the details about how to track and manage content delivery.

Frequently asked questions

What is AWS CloudFront Distribution?

AWS CloudFront Distribution is a resource for CloudFront of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS CloudFront Distribution?

For Terraform, the HaxeFoundation/haxe-terraform, snyk-labs/infrastructure-as-code-goof and Checkmarx/kics source code examples are useful. See the Terraform Example section for further details.