Tradhox_domain_settings/partner/partner_stack.py

52 lines
2 KiB
Python

from aws_cdk import (
Stack,
aws_s3 as s3,
aws_cloudfront as cloudfront,
aws_cloudfront_origins as origins,
aws_certificatemanager as acm,
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. 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),
viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
),
domain_names=["partners.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",
),
],
)