Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudFrontToS3 : Customize Domain Name with Certificate #1139

Open
gmarchand opened this issue Jun 19, 2024 · 3 comments
Open

CloudFrontToS3 : Customize Domain Name with Certificate #1139

gmarchand opened this issue Jun 19, 2024 · 3 comments
Labels
addressed Issue is addressed either through a release or further explanation

Comments

@gmarchand
Copy link

Use Case

I would want to customize the domain name of my Cloudfront Distribution

But I can't do it as you can see in this code:


        cfn_s3 = CloudFrontToS3(self, "lawsy-newsletter-cloudfront-s3",
            cloud_front_distribution_props=cloudfront.DistributionProps(
                domain_names=[domain_name],
                certificate=certificate_cf,
                comment="CloudFront distribution for lAWSy Newsletter",
                default_behavior=cloudfront.BehaviorOptions(
                    origin=cloudfront_origins.S3Origin(??)
                    ),

                )

            )
        )

How could it possible to customize the domain name with a TLS Certificate ?

@gmarchand gmarchand added feature-request A feature should be added or improved needs-triage The issue or PR still needs to be triaged labels Jun 19, 2024
@gmarchand
Copy link
Author

I tried this one

        certificate_cf = acm.DnsValidatedCertificate(
            self,
            "certificate-cf",
            domain_name=domain_name,
            hosted_zone=hosted_zone,
            region="us-east-1",
        )


        bucket = s3.Bucket(self, "s3-bucket",
            enforce_ssl=True,
        )

        cfn_s3 = CloudFrontToS3(self, "cloudfront-s3",
            existing_bucket_obj=bucket, # s3.Bucket
            cloud_front_distribution_props=cloudfront.DistributionProps(
                domain_names=[domain_name],
                certificate=certificate_cf,
                comment="CloudFront distribution for lAWSy Newsletter",
                default_behavior=cloudfront.BehaviorOptions(
                    origin=cloudfront_origins.S3Origin(bucket)
                    ),

                )

            )

But I have this error

Invalid request provided: AWS::CloudFront::Distribution: Cannot use both Origin Access Control and Origin Access Identity on an origin 

@biffgaut
Copy link
Contributor

Thanks, we'll take a look

@biffgaut
Copy link
Contributor

biffgaut commented Sep 30, 2024

Sorry it took so long for us to get back to this.

Reading this, it sounds like you want to replace the service generated domain name for your CloudFront distribution with your own custom domain name. If this is the case, that is not possible. To assign a custom domain name to your CloudFront to S3 architecture you will need to register your Domain Name with a DNS service such as Route53 and direct it to your CloudFront distribution url. There's lots of discussion around doing that here.

WRT to your last error around OAC and OAI, the cloudfront-s3 construct automatically creates an OAC (the recommended technology to use at this point), so if you supply your own S3Origin then you are adding an extra OAI and will see that error. You don't need to supply that, the construct will set all that up for you. This issue is also discussed here.

@biffgaut biffgaut added addressed Issue is addressed either through a release or further explanation and removed feature-request A feature should be added or improved needs-triage The issue or PR still needs to be triaged labels Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed Issue is addressed either through a release or further explanation
Projects
None yet
Development

No branches or pull requests

2 participants