From cfb5cd5fd9dba2101d9e8c53a415a2937e029bc0 Mon Sep 17 00:00:00 2001 From: vickytechkey Date: Fri, 11 Sep 2026 21:28:51 +0530 Subject: [PATCH] fix(ssl): configure ACM SSL certificates and domain names for CloudFront distributions --- partner/partner_stack.py | 14 ++++++++++++-- shopping/shopping_stack.py | 26 ++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/partner/partner_stack.py b/partner/partner_stack.py index bdbddb8..90c2d49 100644 --- a/partner/partner_stack.py +++ b/partner/partner_stack.py @@ -3,6 +3,7 @@ from aws_cdk import ( aws_s3 as s3, aws_cloudfront as cloudfront, aws_cloudfront_origins as origins, + aws_certificatemanager as acm, RemovalPolicy, ) from constructs import Construct @@ -20,12 +21,21 @@ class PartnerStack(Stack): removal_policy=RemovalPolicy.RETAIN, ) - # 2. Create the CloudFront Distribution with OAC (Origin Access Control) + # 2. SSL Certificate in us-east-1 for partners.tradhox.com + certificate = acm.Certificate.from_certificate_arn( + self, "PartnerSiteCertificate", + "arn:aws:acm:us-east-1:764709663363:certificate/e0e835c2-9ef6-4768-894c-2207b6fcfd19", + ) + + # 3. Create the CloudFront Distribution with OAC (Origin Access Control) self.distribution = cloudfront.Distribution( self, "PartnerSiteDistribution", default_behavior=cloudfront.BehaviorOptions( - origin=origins.S3BucketOrigin.with_origin_access_control(partner_bucket) + origin=origins.S3BucketOrigin.with_origin_access_control(partner_bucket), + viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, ), + domain_names=["partners.tradhox.com"], + certificate=certificate, default_root_object="index.html", error_responses=[ cloudfront.ErrorResponse( diff --git a/shopping/shopping_stack.py b/shopping/shopping_stack.py index 719d6c7..5ffe85c 100644 --- a/shopping/shopping_stack.py +++ b/shopping/shopping_stack.py @@ -3,6 +3,7 @@ from aws_cdk import ( aws_s3 as s3, aws_cloudfront as cloudfront, aws_cloudfront_origins as origins, + aws_certificatemanager as acm, RemovalPolicy, ) from constructs import Construct @@ -20,11 +21,32 @@ class ShoppingStack(Stack): removal_policy=RemovalPolicy.RETAIN, ) - # 2. Create the CloudFront Distribution with OAC (Origin Access Control) + # 2. SSL Certificate in us-east-1 for tradhox.com and *.tradhox.com + certificate = acm.Certificate.from_certificate_arn( + self, "ShoppingSiteCertificate", + "arn:aws:acm:us-east-1:764709663363:certificate/037281b1-e7ef-416e-af27-54dbc34cf6c3", + ) + + # 3. Create the CloudFront Distribution with OAC (Origin Access Control) self.distribution = cloudfront.Distribution( self, "ShoppingSiteDistribution", default_behavior=cloudfront.BehaviorOptions( - origin=origins.S3BucketOrigin.with_origin_access_control(shopping_bucket) + origin=origins.S3BucketOrigin.with_origin_access_control(shopping_bucket), + viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, ), + domain_names=["tradhox.com", "www.tradhox.com"], + certificate=certificate, default_root_object="index.html", + error_responses=[ + cloudfront.ErrorResponse( + http_status=403, + response_http_status=200, + response_page_path="/index.html", + ), + cloudfront.ErrorResponse( + http_status=404, + response_http_status=200, + response_page_path="/index.html", + ), + ], )