feat: add PartnerStack with S3 bucket and CloudFront distribution
This commit is contained in:
parent
9d226dbac3
commit
431efbf28d
3 changed files with 38 additions and 0 deletions
6
app.py
6
app.py
|
|
@ -4,9 +4,12 @@ import os
|
|||
import aws_cdk as cdk
|
||||
|
||||
from tradhoxdomain.tradhoxdomain_stack import TradhoxdomainStack
|
||||
from partner.partner_stack import PartnerStack
|
||||
|
||||
|
||||
app = cdk.App()
|
||||
|
||||
# Existing domain stack
|
||||
TradhoxdomainStack(app, "TradhoxdomainStack",
|
||||
# If you don't specify 'env', this stack will be environment-agnostic.
|
||||
# Account/Region-dependent features and context lookups will not work,
|
||||
|
|
@ -25,4 +28,7 @@ TradhoxdomainStack(app, "TradhoxdomainStack",
|
|||
# For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
|
||||
)
|
||||
|
||||
# Partner stack in ap-south-2
|
||||
PartnerStack(app, "PartnerStack", env=cdk.Environment(region="ap-south-2"))
|
||||
|
||||
app.synth()
|
||||
|
|
|
|||
1
partner/__init__.py
Normal file
1
partner/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Partner Stack Package
|
||||
31
partner/partner_stack.py
Normal file
31
partner/partner_stack.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from aws_cdk import (
|
||||
Stack,
|
||||
aws_s3 as s3,
|
||||
aws_cloudfront as cloudfront,
|
||||
aws_cloudfront_origins as origins,
|
||||
RemovalPolicy,
|
||||
)
|
||||
from constructs import Construct
|
||||
|
||||
class PartnerStack(Stack):
|
||||
|
||||
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
||||
super().__init__(scope, construct_id, **kwargs)
|
||||
|
||||
# 1. Create the S3 Bucket for the partner production site
|
||||
partner_bucket = s3.Bucket(
|
||||
self, "PartnerProductionSiteBucket",
|
||||
bucket_name="partnerproductionsite",
|
||||
block_public_access=s3.BlockPublicAccess.BLOCK_ALL,
|
||||
removal_policy=RemovalPolicy.RETAIN,
|
||||
)
|
||||
|
||||
# 2. Create the CloudFront Distribution with OAC (Origin Access Control)
|
||||
# S3Origin automatically configures OAC for the bucket
|
||||
distribution = cloudfront.Distribution(
|
||||
self, "PartnerSiteDistribution",
|
||||
default_behavior=cloudfront.BehaviorOptions(
|
||||
origin=origins.S3Origin(partner_bucket)
|
||||
),
|
||||
default_root_object="index.html",
|
||||
)
|
||||
Loading…
Reference in a new issue