Hello All,
Below is my Cloudfront Config.
my s3 is hosted in eu-west-1 region.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "6.26.0"
}
}
}
resource "aws_cloudfront_distribution" "APP_cloudfrontdistribution" {
depends_on = [ aws_cloudfront_origin_access_control.abc, aws_s3_bucket.abc ]
origin {
#domain_name = "s3b-xyz-st2-euwe01-abc-cft-01.s3.eu-west-1.amazonaws.com"
domain_name = "${aws_s3_bucket.abc.bucket}.s3.amazonaws.com"
origin_access_control_id = aws_cloudfront_origin_access_control.abc.id
origin_id = "cfo-s3-01"
}
resource "aws_s3_bucket" "abc" {
provider = aws
bucket = var.UI_bucket_name
tags = var.Default_Tags
}
main.tf > Provider.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "6.26.0"
}
}
required_version = ">= 1.13.5"
}
provider "aws" {
region = "eu-west-1"
profile = "abc-nonprod"
}
provider "aws" {
alias = "us"
region = "us-east-1"
profile = "abc-nonprod"
}
I am getting below error. can some help me on this, even ChatGPT, Co-poilet unable to figure out the issue.
╷
│ Error: updating CloudFront Distribution (E3EDTVZQNABCLS): operation error CloudFront: UpdateDistribution, https response error StatusCode: 400, RequestID: 74ae43c0-1c1a-4f46-9c49-a0bdd0819718, InvalidArgument: The parameter Origin DomainName does not refer to a valid S3 bucket.
│
│ with module.cloudfront.aws_cloudfront_distribution.APP_cloudfrontdistribution,
│ on …\modules\frontend\cloudfront\main.tf line 62, in resource “aws_cloudfront_distribution” “APP_cloudfrontdistribution”:
│ 62: resource “aws_cloudfront_distribution” “APP_cloudfrontdistribution” {
Try using the `bucket_regional_domain_name` property and see if that works?
domain_name = aws_s3_bucket.abc.bucket_regional_domain_name
The documentation for origin domain names suggests that indeed the S3 bucket domain must include a region, so using the regional domain name will hopefully work.
However, I notice it also says:
If you recently created the S3 bucket, the CloudFront distribution might return HTTP 307 Temporary Redirect responses for up to 24 hours. It can take up to 24 hours for the S3 bucket name to propagate to all AWS Regions. When the propagation is complete, the distribution automatically stops sending these redirect responses; you don’t need to take any action. For more information, see Why am I getting an HTTP 307 Temporary Redirect response from Amazon S3? and Temporary Request Redirection.
Because this Terraform configuration includes both the S3 bucket and the Cloudfront distribution that refers to it, when you apply this configuration for the first time (when nothing exists yet) the request to create the Cloudfront distribution will probably only happen a few seconds after the S3 bucket is created, which is considerably shorter than the 24 hour delay this warns about.
I mention this mainly just because if you’ve already been working with this configuration then you probably created your S3 bucket successfully on the first terraform apply and so now only the Cloudfront distribution needs to be created, so it’ll probably work once you get the domain name correct. But if you were to use this configuration again later to create a separate S3 bucket and Cloudfront distribution then you’d be more likely to encounter that “temporary redirect” error.
Hi, As mentioned I tried with
domain_name = “<bucket_name>.s3.eu-west-1.amazonaws.com” but still the issue exists, the same code work for other env. Is it something to do with the TF version (1.13.5) and aws provider(6.26), really need to solve this issue.