feat: add ShoppingStack with S3 bucket and CloudFront distribution
This commit is contained in:
parent
431efbf28d
commit
3906d7066c
3 changed files with 35 additions and 0 deletions
4
app.py
4
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()
|
||||
|
|
|
|||
1
shopping/__init__.py
Normal file
1
shopping/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Shopping Stack Package
|
||||
30
shopping/shopping_stack.py
Normal file
30
shopping/shopping_stack.py
Normal file
|
|
@ -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",
|
||||
)
|
||||
Loading…
Reference in a new issue