From 3906d7066cc6bad1b1da606273e41c5876b39b42 Mon Sep 17 00:00:00 2001 From: vickytechkey Date: Tue, 8 Sep 2026 19:59:10 +0530 Subject: [PATCH] feat: add ShoppingStack with S3 bucket and CloudFront distribution --- app.py | 4 ++++ shopping/__init__.py | 1 + shopping/shopping_stack.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 shopping/__init__.py create mode 100644 shopping/shopping_stack.py diff --git a/app.py b/app.py index 3aac600..3ba67df 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,7 @@ import aws_cdk as cdk from tradhoxdomain.tradhoxdomain_stack import TradhoxdomainStack from partner.partner_stack import PartnerStack +from shopping.shopping_stack import ShoppingStack app = cdk.App() @@ -31,4 +32,7 @@ TradhoxdomainStack(app, "TradhoxdomainStack", # Partner stack in ap-south-2 PartnerStack(app, "PartnerStack", env=cdk.Environment(region="ap-south-2")) +# Shopping stack in ap-south-2 +ShoppingStack(app, "ShoppingStack", env=cdk.Environment(region="ap-south-2")) + app.synth() diff --git a/shopping/__init__.py b/shopping/__init__.py new file mode 100644 index 0000000..9c045d1 --- /dev/null +++ b/shopping/__init__.py @@ -0,0 +1 @@ +# Shopping Stack Package diff --git a/shopping/shopping_stack.py b/shopping/shopping_stack.py new file mode 100644 index 0000000..b14c79b --- /dev/null +++ b/shopping/shopping_stack.py @@ -0,0 +1,30 @@ +from aws_cdk import ( + Stack, + aws_s3 as s3, + aws_cloudfront as cloudfront, + aws_cloudfront_origins as origins, + RemovalPolicy, +) +from constructs import Construct + +class ShoppingStack(Stack): + + def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: + super().__init__(scope, construct_id, **kwargs) + + # 1. Create the S3 Bucket for the shopping production site + shopping_bucket = s3.Bucket( + self, "ShoppingProductionSiteBucket", + bucket_name="shoppingproductionsite", + block_public_access=s3.BlockPublicAccess.BLOCK_ALL, + removal_policy=RemovalPolicy.RETAIN, + ) + + # 2. Create the CloudFront Distribution with OAC (Origin Access Control) + distribution = cloudfront.Distribution( + self, "ShoppingSiteDistribution", + default_behavior=cloudfront.BehaviorOptions( + origin=origins.S3Origin(shopping_bucket) + ), + default_root_object="index.html", + )