feat: add route53 records for main domain and pass shopping distribution to domain stack
This commit is contained in:
parent
de80dc9a93
commit
8add9990d8
3 changed files with 37 additions and 2 deletions
4
app.py
4
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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue