From 0625e33a66007b8b81ddc67dc1dc399002d9e172 Mon Sep 17 00:00:00 2001 From: Alex Leith Date: Wed, 28 Jun 2023 11:37:58 +1000 Subject: [PATCH] Working first pass --- app.py | 20 +------------ source.bat | 13 --------- sssi/sssi_stack.py | 70 ++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 59 insertions(+), 44 deletions(-) delete mode 100644 source.bat diff --git a/app.py b/app.py index 9e21cbb..c33a7b7 100644 --- a/app.py +++ b/app.py @@ -1,28 +1,10 @@ #!/usr/bin/env python3 -import os import aws_cdk as cdk from sssi.sssi_stack import SssiStack - app = cdk.App() -SssiStack(app, "SssiStack", - # If you don't specify 'env', this stack will be environment-agnostic. - # Account/Region-dependent features and context lookups will not work, - # but a single synthesized template can be deployed anywhere. - - # Uncomment the next line to specialize this stack for the AWS Account - # and Region that are implied by the current CLI configuration. - - #env=cdk.Environment(account=os.getenv('CDK_DEFAULT_ACCOUNT'), region=os.getenv('CDK_DEFAULT_REGION')), - - # Uncomment the next line if you know exactly what Account and Region you - # want to deploy the stack to. */ - - #env=cdk.Environment(account='123456789012', region='us-east-1'), - - # For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html - ) +SssiStack(app, "SssiStack") app.synth() diff --git a/source.bat b/source.bat deleted file mode 100644 index 9e1a834..0000000 --- a/source.bat +++ /dev/null @@ -1,13 +0,0 @@ -@echo off - -rem The sole purpose of this script is to make the command -rem -rem source .venv/bin/activate -rem -rem (which activates a Python virtualenv on Linux or Mac OS X) work on Windows. -rem On Windows, this command just runs this batch file (the argument is ignored). -rem -rem Now we don't need to document a Windows command for activating a virtualenv. - -echo Executing .venv\Scripts\activate.bat for you -.venv\Scripts\activate.bat diff --git a/sssi/sssi_stack.py b/sssi/sssi_stack.py index ac61156..7c7fbd2 100644 --- a/sssi/sssi_stack.py +++ b/sssi/sssi_stack.py @@ -1,19 +1,65 @@ -from aws_cdk import ( - # Duration, - Stack, - # aws_sqs as sqs, -) +from aws_cdk import Stack +from aws_cdk import aws_certificatemanager as acm +from aws_cdk import aws_cloudfront as cloudfront +from aws_cdk import aws_s3 as s3 +import aws_cdk as cdk from constructs import Construct -class SssiStack(Stack): +# Old DNS 13.54.216.29 + +class SssiStack(Stack): def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: super().__init__(scope, construct_id, **kwargs) - # The code that defines your stack goes here + # Create an S3 bucket called sssi.org.au with a redirect to https://geospatialcouncil.org.au + sssi_bucket = s3.Bucket( + self, + "sssi.org.au.bucket", + bucket_name="sssi.org.au", + website_redirect=s3.RedirectTarget( + host_name="geospatialcouncil.org.au", + protocol=s3.RedirectProtocol.HTTPS, + + ), + removal_policy=cdk.RemovalPolicy.DESTROY + ) + + # Set up an ACM certificate for sssi.org.au + sssi_cert = acm.Certificate( + self, + "sssi.org.au.cert", + domain_name="sssi.org.au", + validation=acm.CertificateValidation.from_dns(), + ) - # example resource - # queue = sqs.Queue( - # self, "SssiQueue", - # visibility_timeout=Duration.seconds(300), - # ) + # Set up cloudfront distribution for sssi.org.au + cloudfront.CloudFrontWebDistribution( + self, + "sssi.org.au.distribution", + origin_configs=[ + cloudfront.SourceConfiguration( + custom_origin_source=cloudfront.CustomOriginConfig( + domain_name=sssi_bucket.bucket_website_domain_name, + origin_protocol_policy=cloudfront.OriginProtocolPolicy.HTTP_ONLY, + ), + behaviors=[ + cloudfront.Behavior( + is_default_behavior=True + ) + ], + ) + ], + viewer_certificate=cloudfront.ViewerCertificate.from_acm_certificate( + certificate=sssi_cert, + aliases=["sssi.org.au"], + ), + price_class=cloudfront.PriceClass.PRICE_CLASS_ALL, + error_configurations=[ + cloudfront.CfnDistribution.CustomErrorResponseProperty( + error_code=404, + response_code=404, + response_page_path="/404.html", + ) + ], + )