- Newest
- Most votes
- Most comments
Hello.
The "DomainName" of "AWS::CloudFront::Distribution" must be set to the EC2 domain name.
So, try setting the private DNS name for your EC2 instance as follows:
Also, please modify the code so that the ID returned by "AWS::CloudFront::VpcOrigin" is obtained using !GetAtt.
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-distribution-origin.html#cfn-cloudfront-distribution-origin-domainname
RendezvousCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
DependsOn: RendezvousVpcOrigin # Ensure VPC Origin is deployed before the distribution
Properties:
DistributionConfig:
Enabled: true
Comment: !Sub "CloudFront distribution for Rendezvous Rust Service (${EnvironmentName})"
Origins:
- Id: RendezvousEc2Origin # Logical ID for the origin
DomainName: "ip-172-31-x-x.ap-northeast-1.compute.internal" # Edit
VpcOriginConfig:
VpcOriginId: !GetAtt RendezvousVpcOrigin.Id #Edit
OriginKeepaliveTimeout: 5
OriginReadTimeout: 30
.....
The error "The parameter origin name must be a domain name" occurs because you're not using the correct property for the VPC Origin integration in your CloudFront distribution.
When using AWS::CloudFront::VpcOrigin with a CloudFront distribution, you need to reference it properly in the Origins section. The issue is with how you're setting up the DomainName property in your CloudFront distribution's origin configuration.
The DomainName property requires a valid domain name, but you're trying to use !GetAtt RendezvousVpcOrigin.Id which doesn't return a domain name. For VPC origins, you don't need to specify a DomainName at all when using VpcOriginConfig.
Here's how you should modify your CloudFront distribution's origin configuration:
Origins: - Id: RendezvousEc2Origin VpcOriginConfig: VpcOriginId: !Ref RendezvousVpcOrigin OriginKeepaliveTimeout: 5 OriginReadTimeout: 30
Remove the DomainName property entirely when using VpcOriginConfig. The VpcOriginId property is sufficient to establish the connection between your CloudFront distribution and the VPC origin.
Also, make sure your EC2 instance has a publicly resolvable DNS name that routes requests from clients to targets over the internet, as this is required for CloudFront origins. Since you mentioned your EC2 instance is in a public subnet but deliberately has no Public IPv4, you'll need to ensure it's still accessible to CloudFront through the VPC origin configuration.
Sources
Origin settings - Amazon CloudFront
Troubleshoot CloudFront distribution access issues with CNAMEs and custom origins | AWS re:Post
answered a year ago

When I remove the DomainName, I get:
Properties validation failed for resource RendezvousCloudFrontDistribution with message: #/DistributionConfig/Origins/0: required key [DomainName] not found