-
Notifications
You must be signed in to change notification settings - Fork 0
/
brodie.id.au.py
89 lines (73 loc) · 2.83 KB
/
brodie.id.au.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Defines brodie.id.au website infrastructure using AWS CDK."""
from pathlib import Path
import aws_cdk as cdk
import aws_cdk.aws_certificatemanager as acm
import aws_cdk.aws_cloudfront as cloudfront
import aws_cdk.aws_cloudfront_origins as cloudfront_origins
import aws_cdk.aws_route53 as route53
import aws_cdk.aws_route53_targets as route53_targets
import aws_cdk.aws_s3 as s3
import aws_cdk.aws_s3_deployment as s3_deployment
# Path to sphinx-build output, relative to this module.
build_path = Path(__file__).parent / "_build"
class App(cdk.App):
def __init__(self) -> None:
super().__init__()
Website(self, id="Website")
class Website(cdk.Stack):
"""brodie.id.au website stack."""
def __init__(self, scope, id: str) -> None:
super().__init__(scope, id, description="brodie.id.au website")
# This bucket contains static website files.
bucket = s3.Bucket(
scope=self,
id="Bucket",
)
# Reference existing hosted zone.
hosted_zone = route53.HostedZone.from_hosted_zone_attributes(
scope=self,
id="HostedZone",
hosted_zone_id="Z0932427366G4DNP1CWB",
zone_name="brodie.id.au",
)
# CloudFront distribution certificates must be in region us-east-1.
certificate = acm.DnsValidatedCertificate(
scope=self,
id="Certificate",
hosted_zone=hosted_zone,
region="us-east-1",
domain_name="brodie.id.au",
)
# Create a CloudFront distribution that serves content from our S3 origin.
distribution = cloudfront.Distribution(
scope=self,
id="Distribution",
default_behavior=cloudfront.BehaviorOptions(
origin=cloudfront_origins.S3Origin(bucket),
viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
),
certificate=certificate,
default_root_object="index.html",
domain_names=["brodie.id.au"],
)
# Populate bucket with files from build directory (relative to this module).
s3_deployment.BucketDeployment(
scope=self,
id="BucketDeployment",
destination_bucket=bucket,
sources=[s3_deployment.Source.asset(str(build_path))],
# Invalidate CloudFront distribution cache on change.
distribution=distribution,
)
# Create an alias record for the CloudFront distribution.
route53.ARecord(
scope=self,
id="Alias",
target=route53.RecordTarget.from_alias(
route53_targets.CloudFrontTarget(distribution)
),
zone=hosted_zone,
record_name="brodie.id.au",
)
if __name__ == "__main__":
App().synth()