示例#1
0
    def __init__(self, scope: Construct, id: str, *, deployment: Deployment,
                 **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        Tags.of(self).add("Application", self.application_name)
        Tags.of(self).add("Deployment", deployment.value)

        func = lambda_edge.create_function(
            self,
            f"Preview{deployment.value}IndexRedirect",
            runtime=Runtime.NODEJS_10_X,
            handler="index.handler",
            code=Code.from_asset("./lambdas/preview-redirect"),
        )

        s3_cloud_front = S3CloudFront(
            self,
            "S3CloudFront",
            subdomain_name=self.subdomain_name,
            error_folder="/errors",
            lambda_function_associations=[
                LambdaFunctionAssociation(
                    event_type=LambdaEdgeEventType.ORIGIN_REQUEST,
                    lambda_function=func,
                ),
            ],
        )

        S3CloudFrontPolicy(
            self,
            "S3cloudFrontPolicy",
            s3_cloud_front=s3_cloud_front,
        )
示例#2
0
    def __init__(
        self,
        scope: Construct,
        id: str,
        *,
        deployment: Deployment,
        additional_fqdns: Optional[List[str]] = None,
        **kwargs,
    ) -> None:
        super().__init__(scope, id, **kwargs)

        Tags.of(self).add("Application", self.application_name)
        Tags.of(self).add("Deployment", deployment.value)

        func = lambda_edge.create_function(
            self,
            f"BananasCdnRedirect{deployment.value}",
            runtime=Runtime.NODEJS_10_X,
            handler="index.handler",
            code=Code.from_asset("./lambdas/bananas-cdn"),
        )

        s3_cloud_front = S3CloudFront(
            self,
            "S3CloudFront",
            subdomain_name=self.subdomain_name,
            error_folder="/errors",
            lambda_function_associations=[
                LambdaFunctionAssociation(
                    event_type=LambdaEdgeEventType.ORIGIN_REQUEST,
                    lambda_function=func,
                ),
            ],
            price_class=PriceClass.PRICE_CLASS_ALL,
            additional_fqdns=additional_fqdns,
            viewer_protocol_policy=ViewerProtocolPolicy.
            ALLOW_ALL,  # OpenTTD client doesn't support HTTPS
        )
        self.bucket = s3_cloud_front.bucket_site

        S3CloudFrontPolicy(
            self,
            "S3cloudFrontPolicy",
            s3_cloud_front=s3_cloud_front,
            with_s3_get_object_access=True,
        )
示例#3
0
    def __init__(self,
                 scope: Construct,
                 id: str,
                 *,
                 deployment: Deployment,
                 additional_fqdns: Optional[List[str]] = None,
                 **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        Tags.of(self).add("Application", self.application_name)
        Tags.of(self).add("Deployment", deployment.value)

        func = lambda_edge.create_function(
            self,
            "CdnIndexRedirect",
            runtime=Runtime.NODEJS_10_X,
            handler="index.handler",
            code=Code.from_asset("./lambdas/index-redirect"),
        )

        s3_cloud_front = S3CloudFront(
            self,
            "S3CloudFront",
            subdomain_name=self.subdomain_name,
            error_folder="/errors",
            lambda_function_associations=[
                LambdaFunctionAssociation(
                    event_type=LambdaEdgeEventType.ORIGIN_REQUEST,
                    lambda_function=func,
                ),
            ],
            additional_fqdns=additional_fqdns,
            price_class=PriceClass.PRICE_CLASS_ALL,
        )

        S3CloudFrontPolicy(
            self,
            "S3cloudFrontPolicy",
            s3_cloud_front=s3_cloud_front,
            with_s3_get_object_access=True,
        )
示例#4
0
    def __init__(self, scope: Construct, id: str, *, deployment: Deployment, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        Tags.of(self).add("Application", self.application_name)
        Tags.of(self).add("Deployment", deployment.value)

        hosted_zone = HostedZone.from_lookup(
            self,
            "Zone",
            domain_name="openttd.com",
        )
        fqdn = "www.openttd.com"

        certificate = DnsValidatedCertificate(
            self,
            "OpenttdCom-Certificate",
            hosted_zone=hosted_zone,
            domain_name=fqdn,
            subject_alternative_names=["*.openttd.com", "openttd.com"],
            region="us-east-1",
            validation_method=ValidationMethod.DNS,
        )

        func = lambda_edge.create_function(
            self,
            "OpenttdComRedirect",
            runtime=Runtime.NODEJS_10_X,
            handler="index.handler",
            code=Code.from_asset("./lambdas/openttd-com-redirect"),
        )

        s3_cloud_front = S3CloudFront(
            self,
            "S3CloudFront",
            subdomain_name=fqdn,
            cert=CertificateResult(certificate, certificate.certificate_arn, fqdn),
            additional_fqdns=["*.openttd.com", "openttd.com"],
            lambda_function_associations=[
                LambdaFunctionAssociation(
                    event_type=LambdaEdgeEventType.ORIGIN_REQUEST,
                    lambda_function=func,
                ),
            ],
            no_dns=True,
        )

        S3CloudFrontPolicy(
            self,
            "S3cloudFrontPolicy",
            s3_cloud_front=s3_cloud_front,
        )

        for record_name in ("www", None):
            route53.ARecord(
                self,
                f"{record_name}.openttd.com-ARecord",
                target=RecordTarget.from_alias(CloudFrontTarget(s3_cloud_front.distribution)),
                zone=hosted_zone,
                record_name=record_name,
            )
            route53.AaaaRecord(
                self,
                f"{record_name}.openttd.com-AaaaRecord",
                target=RecordTarget.from_alias(CloudFrontTarget(s3_cloud_front.distribution)),
                zone=hosted_zone,
                record_name=record_name,
            )