From 4b18b203d40fe2d283dc48a98b3c1f857f0af24f Mon Sep 17 00:00:00 2001 From: Jennifer Tran <12633533+botanical@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:39:15 -0700 Subject: [PATCH] feat: remove alternate domain support --- app.py | 44 -------- config.py | 9 -- domain/infrastructure/config.py | 49 -------- domain/infrastructure/construct.py | 148 ------------------------- ingest_api/infrastructure/construct.py | 15 --- raster_api/infrastructure/construct.py | 15 --- stac_api/infrastructure/construct.py | 14 --- 7 files changed, 294 deletions(-) delete mode 100644 domain/infrastructure/config.py delete mode 100644 domain/infrastructure/construct.py diff --git a/app.py b/app.py index 511271a8..60045428 100644 --- a/app.py +++ b/app.py @@ -8,7 +8,6 @@ from config import veda_app_settings from database.infrastructure.construct import RdsConstruct -from domain.infrastructure.construct import DomainConstruct from ingest_api.infrastructure.config import IngestorConfig as ingest_config from ingest_api.infrastructure.construct import ApiConstruct as ingest_api_construct from ingest_api.infrastructure.construct import IngestorConstruct as ingestor_construct @@ -70,15 +69,12 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: stage=veda_app_settings.stage_name(), ) -domain = DomainConstruct(veda_stack, "domain", stage=veda_app_settings.stage_name()) - raster_api = RasterApiLambdaConstruct( veda_stack, "raster-api", stage=veda_app_settings.stage_name(), vpc=vpc.vpc, database=database, - domain=domain, ) stac_api = StacApiLambdaConstruct( @@ -88,7 +84,6 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: vpc=vpc.vpc, database=database, raster_api=raster_api, - domain=domain, ) website = VedaWebsite( @@ -123,7 +118,6 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: raster_api_url=raster_api_url, ) - ingest_api = ingest_api_construct( veda_stack, "ingest-api", @@ -131,7 +125,6 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: db_secret=database.pgstac.secret, db_vpc=vpc.vpc, db_vpc_subnets=database.vpc_subnets, - domain=domain, ) ingestor = ingestor_construct( @@ -144,43 +137,6 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: db_vpc_subnets=database.vpc_subnets, ) -# TODO this conditional supports deploying a second set of APIs to a separate custom domain and should be removed if no longer necessary -if veda_app_settings.alt_domain(): - alt_domain = DomainConstruct( - veda_stack, - "alt-domain", - stage=veda_app_settings.stage_name(), - alt_domain=True, - ) - - alt_raster_api = RasterApiLambdaConstruct( - veda_stack, - "alt-raster-api", - stage=veda_app_settings.stage_name(), - vpc=vpc.vpc, - database=database, - domain_name=alt_domain.raster_domain_name, - ) - - alt_stac_api = StacApiLambdaConstruct( - veda_stack, - "alt-stac-api", - stage=veda_app_settings.stage_name(), - vpc=vpc.vpc, - database=database, - raster_api=raster_api, - domain_name=alt_domain.stac_domain_name, - ) - - alt_ingest_api = ingest_api_construct( - veda_stack, - "alt-ingest-api", - config=ingestor_config, - db_secret=database.pgstac.secret, - db_vpc=vpc.vpc, - domain_name=alt_domain.ingest_domain_name, - ) - git_sha = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip() try: git_tag = subprocess.check_output(["git", "describe", "--tags"]).decode().strip() diff --git a/config.py b/config.py index 7f8152bb..c792b1b7 100644 --- a/config.py +++ b/config.py @@ -120,15 +120,6 @@ def cdk_env(self) -> dict: else: return {} - def alt_domain(self) -> bool: - """True if alternative domain and host parameters provided""" - return all( - [ - self.veda_domain_alt_hosted_zone_id, - self.veda_domain_alt_hosted_zone_name, - ] - ) - def stage_name(self) -> str: """Force lowercase stage name""" return self.stage.lower() diff --git a/domain/infrastructure/config.py b/domain/infrastructure/config.py deleted file mode 100644 index b74c4e88..00000000 --- a/domain/infrastructure/config.py +++ /dev/null @@ -1,49 +0,0 @@ -"""Configuration options for a custom API domain.""" - -from typing import Optional - -from pydantic import BaseSettings, Field - - -class vedaDomainSettings(BaseSettings): - """Application settings""" - - hosted_zone_id: Optional[str] = Field( - None, description="Route53 hosted zone identifier if using a custom domain name" - ) - hosted_zone_name: Optional[str] = Field( - None, description="Custom domain name, i.e. veda-backend.xyz" - ) - create_custom_subdomains: bool = Field( - False, - description=( - "When true and hosted zone config is provided, create a unique subdomain for stac and raster apis. " - "For example -stac. and -raster." - ), - ) - api_prefix: Optional[str] = Field( - None, - description=( - "Domain prefix override supports using a custom prefix instead of the " - "STAGE variabe (an alternate version of the stack can be deployed with a " - "unique STAGE=altprod and after testing prod API traffic can be cut over " - "to the alternate version of the stack by setting the prefix to prod)" - ), - ) - - # Temporary support for deploying APIs to a second custom domain - alt_hosted_zone_id: Optional[str] = Field( - None, description="Second Route53 zone identifier if using a custom domain name" - ) - alt_hosted_zone_name: Optional[str] = Field( - None, description="Second custom domain name, i.e. alt-veda-backend.xyz" - ) - - class Config: - """model config""" - - env_file = ".env" - env_prefix = "VEDA_DOMAIN_" - - -veda_domain_settings = vedaDomainSettings() diff --git a/domain/infrastructure/construct.py b/domain/infrastructure/construct.py deleted file mode 100644 index 61b133fa..00000000 --- a/domain/infrastructure/construct.py +++ /dev/null @@ -1,148 +0,0 @@ -"""CDK Construct for a custom API domain.""" -from typing import Optional - -from aws_cdk import ( - CfnOutput, - aws_apigatewayv2_alpha, - aws_certificatemanager, - aws_route53, - aws_route53_targets, -) -from constructs import Construct - -from .config import veda_domain_settings - - -class DomainConstruct(Construct): - """CDK Construct for a custom API domain.""" - - def __init__( - self, - scope: Construct, - construct_id: str, - stage: str, - alt_domain: Optional[bool] = False, - **kwargs, - ) -> None: - """.""" - super().__init__(scope, construct_id, **kwargs) - - self.stac_domain_name = None - self.raster_domain_name = None - self.ingest_domain_name = None - - if veda_domain_settings.create_custom_subdomains: - # If alternative custom domain provided, use it instead of the default - if alt_domain is True: - hosted_zone_name = veda_domain_settings.alt_hosted_zone_name - hosted_zone_id = veda_domain_settings.alt_hosted_zone_id - else: - hosted_zone_name = veda_domain_settings.hosted_zone_name - hosted_zone_id = veda_domain_settings.hosted_zone_id - - hosted_zone = aws_route53.HostedZone.from_hosted_zone_attributes( - self, - "hosted-zone", - hosted_zone_id=hosted_zone_id, - zone_name=hosted_zone_name, - ) - certificate = aws_certificatemanager.Certificate( - self, - "certificate", - domain_name=f"*.{hosted_zone_name}", - validation=aws_certificatemanager.CertificateValidation.from_dns( - hosted_zone=hosted_zone - ), - ) - - # Use custom api prefix if provided or deployment stage if not - if veda_domain_settings.api_prefix: - raster_url_prefix = f"{veda_domain_settings.api_prefix.lower()}-raster" - stac_url_prefix = f"{veda_domain_settings.api_prefix.lower()}-stac" - ingest_url_prefix = f"{veda_domain_settings.api_prefix.lower()}-ingest" - else: - raster_url_prefix = f"{stage.lower()}-raster" - stac_url_prefix = f"{stage.lower()}-stac" - ingest_url_prefix = f"{stage.lower()}-ingest" - raster_domain_name = f"{raster_url_prefix}.{hosted_zone_name}" - stac_domain_name = f"{stac_url_prefix}.{hosted_zone_name}" - ingest_domain_name = f"{ingest_url_prefix}.{hosted_zone_name}" - - self.raster_domain_name = aws_apigatewayv2_alpha.DomainName( - self, - "rasterApiCustomDomain", - domain_name=raster_domain_name, - certificate=certificate, - ) - - aws_route53.ARecord( - self, - "raster-api-dns-record", - zone=hosted_zone, - target=aws_route53.RecordTarget.from_alias( - aws_route53_targets.ApiGatewayv2DomainProperties( - regional_domain_name=self.raster_domain_name.regional_domain_name, - regional_hosted_zone_id=self.raster_domain_name.regional_hosted_zone_id, - ) - ), - # Note: CDK will append the hosted zone name (eg: `veda-backend.xyz` to this record name) - record_name=raster_url_prefix, - ) - - self.stac_domain_name = aws_apigatewayv2_alpha.DomainName( - self, - "stacApiCustomDomain", - domain_name=stac_domain_name, - certificate=certificate, - ) - - aws_route53.ARecord( - self, - "stac-api-dns-record", - zone=hosted_zone, - target=aws_route53.RecordTarget.from_alias( - aws_route53_targets.ApiGatewayv2DomainProperties( - regional_domain_name=self.stac_domain_name.regional_domain_name, - regional_hosted_zone_id=self.stac_domain_name.regional_hosted_zone_id, - ) - ), - # Note: CDK will append the hosted zone name (eg: `veda-backend.xyz` to this record name) - record_name=stac_url_prefix, - ) - - self.ingest_domain_name = aws_apigatewayv2_alpha.DomainName( - self, - "ingestApiCustomDomain", - domain_name=ingest_domain_name, - certificate=certificate, - ) - - aws_route53.ARecord( - self, - "ingest-api-dns-record", - zone=hosted_zone, - target=aws_route53.RecordTarget.from_alias( - aws_route53_targets.ApiGatewayv2DomainProperties( - regional_domain_name=self.ingest_domain_name.regional_domain_name, - regional_hosted_zone_id=self.ingest_domain_name.regional_hosted_zone_id, - ) - ), - # Note: CDK will append the hosted zone name (eg: `veda-backend.xyz` to this record name) - record_name=ingest_url_prefix, - ) - - CfnOutput( - self, - "raster-api", - value=f"https://{raster_url_prefix}.{hosted_zone_name}/docs", - ) - CfnOutput( - self, - "stac-api", - value=f"https://{stac_url_prefix}.{hosted_zone_name}/", - ) - CfnOutput( - self, - "ingest-api", - value=f"https://{ingest_url_prefix}.{hosted_zone_name}/", - ) diff --git a/ingest_api/infrastructure/construct.py b/ingest_api/infrastructure/construct.py index c4322647..b8fe01da 100644 --- a/ingest_api/infrastructure/construct.py +++ b/ingest_api/infrastructure/construct.py @@ -17,10 +17,6 @@ from .config import IngestorConfig -if typing.TYPE_CHECKING: - from domain.infrastructure.construct import DomainConstruct - - class ApiConstruct(Construct): def __init__( self, @@ -30,7 +26,6 @@ def __init__( db_secret: secretsmanager.ISecret, db_vpc: ec2.IVpc, db_vpc_subnets=ec2.SubnetSelection, - domain: Optional["DomainConstruct"] = None, **kwargs, ) -> None: super().__init__(scope, construct_id, **kwargs) @@ -95,7 +90,6 @@ def __init__( self.api: aws_apigatewayv2_alpha.HttpApi = self.build_api( construct_id=construct_id, handler=self.api_lambda, - domain=domain, custom_host=config.custom_host, ) @@ -193,7 +187,6 @@ def build_api( *, construct_id: str, handler: aws_lambda.IFunction, - domain, custom_host: Optional[str], ) -> aws_apigatewayv2_alpha.HttpApi: integration_kwargs = dict(handler=handler) @@ -212,20 +205,12 @@ def build_api( ) ) - domain_mapping = None - # Legacy method to use a custom subdomain for this api (i.e. -ingest..com) - # If using a custom root path and/or a proxy server, do not use a custom subdomain - if domain and domain.ingest_domain_name: - domain_mapping = aws_apigatewayv2_alpha.DomainMappingOptions( - domain_name=domain.ingest_domain_name - ) stack_name = Stack.of(self).stack_name return aws_apigatewayv2_alpha.HttpApi( self, f"{stack_name}-{construct_id}", default_integration=ingest_api_integration, - default_domain_mapping=domain_mapping, ) def build_jwks_url(self, userpool_id: str) -> str: diff --git a/raster_api/infrastructure/construct.py b/raster_api/infrastructure/construct.py index c7362148..a98f9b08 100644 --- a/raster_api/infrastructure/construct.py +++ b/raster_api/infrastructure/construct.py @@ -19,10 +19,6 @@ from .config import veda_raster_settings -if typing.TYPE_CHECKING: - from domain.infrastructure.construct import DomainConstruct - - class RasterApiLambdaConstruct(Construct): """CDK Construct for a Lambda based TiTiler API with pgstac extension.""" @@ -34,8 +30,6 @@ def __init__( vpc, database, code_dir: str = "./", - # domain_name: aws_apigatewayv2_alpha.DomainName = None, - domain: Optional["DomainConstruct"] = None, **kwargs, ) -> None: """.""" @@ -102,19 +96,10 @@ def __init__( ) ) - domain_mapping = None - # Legacy method to use a custom subdomain for this api (i.e. -raster..com) - # If using a custom root path and/or a proxy server, do not use a custom subdomain - if domain and domain.raster_domain_name: - domain_mapping = aws_apigatewayv2_alpha.DomainMappingOptions( - domain_name=domain.raster_domain_name - ) - self.raster_api = aws_apigatewayv2_alpha.HttpApi( self, f"{stack_name}-{construct_id}", default_integration=raster_api_integration, - default_domain_mapping=domain_mapping, ) CfnOutput( diff --git a/stac_api/infrastructure/construct.py b/stac_api/infrastructure/construct.py index f4848a41..fe334840 100644 --- a/stac_api/infrastructure/construct.py +++ b/stac_api/infrastructure/construct.py @@ -18,10 +18,6 @@ from .config import veda_stac_settings -if typing.TYPE_CHECKING: - from domain.infrastructure.construct import DomainConstruct - - class StacApiLambdaConstruct(Construct): """CDK Construct for a Lambda backed API implementing stac-fastapi.""" @@ -34,7 +30,6 @@ def __init__( database, raster_api, # TODO: typing! code_dir: str = "./", - domain: Optional["DomainConstruct"] = None, **kwargs, ) -> None: """.""" @@ -108,19 +103,10 @@ def __init__( ) ) - domain_mapping = None - # Legacy method to use a custom subdomain for this api (i.e. -stac..com) - # If using a custom root path and/or a proxy server, do not use a custom subdomain - if domain and domain.stac_domain_name: - domain_mapping = aws_apigatewayv2_alpha.DomainMappingOptions( - domain_name=domain.stac_domain_name - ) - self.stac_api = aws_apigatewayv2_alpha.HttpApi( self, f"{stack_name}-{construct_id}", default_integration=stac_api_integration, - default_domain_mapping=domain_mapping, ) CfnOutput(