From 8add9990d861cd93ec06ccf21269308354e26342 Mon Sep 17 00:00:00 2001 From: vickytechkey Date: Fri, 11 Sep 2026 20:53:56 +0530 Subject: [PATCH] feat: add route53 records for main domain and pass shopping distribution to domain stack --- app.py | 4 +++- shopping/shopping_stack.py | 2 +- tradhoxdomain/tradhoxdomain_stack.py | 33 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 05c6fe4..15d5de8 100644 --- a/app.py +++ b/app.py @@ -21,12 +21,13 @@ partner_stack = PartnerStack( ) # Shopping stack in ap-south-2 -ShoppingStack( +shopping_stack = ShoppingStack( app, "ShoppingStack", env=cdk.Environment( account=os.getenv("CDK_DEFAULT_ACCOUNT"), region="ap-south-2", ), + cross_region_references=True, ) # Domain stack in ap-south-2 @@ -38,6 +39,7 @@ TradhoxdomainStack( ), cross_region_references=True, partner_distribution=partner_stack.distribution, + shopping_distribution=shopping_stack.distribution, ) app.synth() diff --git a/shopping/shopping_stack.py b/shopping/shopping_stack.py index 6837dc4..719d6c7 100644 --- a/shopping/shopping_stack.py +++ b/shopping/shopping_stack.py @@ -21,7 +21,7 @@ class ShoppingStack(Stack): ) # 2. Create the CloudFront Distribution with OAC (Origin Access Control) - distribution = cloudfront.Distribution( + self.distribution = cloudfront.Distribution( self, "ShoppingSiteDistribution", default_behavior=cloudfront.BehaviorOptions( origin=origins.S3BucketOrigin.with_origin_access_control(shopping_bucket) diff --git a/tradhoxdomain/tradhoxdomain_stack.py b/tradhoxdomain/tradhoxdomain_stack.py index f7688e0..70d47b4 100644 --- a/tradhoxdomain/tradhoxdomain_stack.py +++ b/tradhoxdomain/tradhoxdomain_stack.py @@ -17,6 +17,10 @@ class TradhoxdomainStack(Stack): construct_id: str, partner_distribution: Optional[cloudfront.IDistribution] = None, partner_distribution_domain_name: Optional[str] = None, + shopping_distribution: Optional[cloudfront.IDistribution] = None, + shopping_distribution_domain_name: Optional[str] = None, + main_distribution: Optional[cloudfront.IDistribution] = None, + main_distribution_domain_name: Optional[str] = None, **kwargs ) -> None: super().__init__(scope, construct_id, **kwargs) @@ -42,6 +46,7 @@ class TradhoxdomainStack(Stack): "beta-mailservices", "betawhatsapp", "betapayments", + "pipeline" ] # Target IP address provided by the user @@ -73,6 +78,34 @@ class TradhoxdomainStack(Stack): ttl=Duration.minutes(5), ) + # Route main domain ('tradhox.com' and 'www.tradhox.com') to Shopping / Main CloudFront distribution + target_main_distribution = shopping_distribution or main_distribution + target_main_distribution_domain_name = shopping_distribution_domain_name or main_distribution_domain_name + + if target_main_distribution: + # Apex domain A Record (tradhox.com) + route53.ARecord( + self, "MainDomainApexRecord", + zone=hosted_zone, + record_name="", + target=route53.RecordTarget.from_alias(targets.CloudFrontTarget(target_main_distribution)) + ) + # www subdomain A Record (www.tradhox.com) + route53.ARecord( + self, "MainDomainWwwRecord", + zone=hosted_zone, + record_name="www", + target=route53.RecordTarget.from_alias(targets.CloudFrontTarget(target_main_distribution)) + ) + elif target_main_distribution_domain_name: + route53.CnameRecord( + self, "MainDomainWwwRecord", + zone=hosted_zone, + record_name="www", + domain_name=target_main_distribution_domain_name, + ttl=Duration.minutes(5), + ) + # MX records for Hostinger mail services route53.MxRecord( self, "TradhoxMxRecord",