Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove cloudfront distribution and custom alternate domain from backend #422

Merged
merged 11 commits into from
Aug 23, 2024
73 changes: 8 additions & 65 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@

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
from network.infrastructure.construct import VpcConstruct
from permissions_boundary.infrastructure.construct import PermissionsBoundaryAspect
from raster_api.infrastructure.construct import RasterApiLambdaConstruct
from routes.infrastructure.construct import CloudfrontDistributionConstruct
from s3_website.infrastructure.construct import VedaWebsite
from stac_api.infrastructure.construct import StacApiLambdaConstruct

Expand Down Expand Up @@ -71,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(
Expand All @@ -89,23 +84,12 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
vpc=vpc.vpc,
database=database,
raster_api=raster_api,
domain=domain,
)

website = VedaWebsite(
veda_stack, "stac-browser-bucket", stage=veda_app_settings.stage_name()
)

veda_routes = CloudfrontDistributionConstruct(
veda_stack,
"routes",
stage=veda_app_settings.stage_name(),
raster_api_id=raster_api.raster_api.api_id,
stac_api_id=stac_api.stac_api.api_id,
origin_bucket=website.bucket,
region=veda_app_settings.cdk_default_region,
)

# Only create a stac browser if we can infer the catalog url from configuration before synthesis (API Gateway URL not yet available)
stac_catalog_url = veda_app_settings.get_stac_catalog_url()
if stac_catalog_url:
Expand All @@ -120,23 +104,27 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
db_secret_name = database.pgstac.secret.secret_name
db_security_group = database.db_security_group

base_api_url = f"https://{veda_app_settings.stage_name()}.{veda_app_settings.veda_custom_host}".strip(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't VEDA_CUSTOM_HOST already include the stage name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it does!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"/"
)
stac_api_url = f"{base_api_url}{veda_app_settings.veda_stac_root_path}/"
raster_api_url = f"{base_api_url}{veda_app_settings.veda_raster_root_path}/"

# ingestor config requires references to other resources, but can be shared between ingest api and bulk ingestor
ingestor_config = ingest_config(
stage=veda_app_settings.stage_name(),
stac_db_security_group_id=db_security_group.security_group_id,
stac_api_url=stac_api.stac_api.url,
raster_api_url=raster_api.raster_api.url,
stac_api_url=stac_api_url,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could handle inferring the cloudfront urls in config with a property or function

@property
def veda_stac_api_cf_url(self) -> str:
    """inferred cloudfront url of the stac api if app is configured with a custom host and root path"""
    if self.veda_custom_host and self.veda_stac_root_path:
        return f"https://{self.veda_custom_host}{self.veda_stac_root_path}"
    return None 

and then conditionally use them here so that we have a way to use the API gateway url if a cloudfront is not used.

stac_api_url=settings.stac_api_cf_url if settings.stac_api_cf_url else stac_api.stac_api.url

raster_api_url=raster_api_url,
)


ingest_api = ingest_api_construct(
veda_stack,
"ingest-api",
config=ingestor_config,
db_secret=database.pgstac.secret,
db_vpc=vpc.vpc,
db_vpc_subnets=database.vpc_subnets,
domain=domain,
)

ingestor = ingestor_construct(
Expand All @@ -149,51 +137,6 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
db_vpc_subnets=database.vpc_subnets,
)

veda_routes.add_ingest_behavior(
ingest_api=ingest_api.api, stage=veda_app_settings.stage_name()
)

# Must be done after all CF behaviors exist
veda_routes.create_route_records(stage=veda_app_settings.stage_name())


# TODO this conditional supports deploying a second set of APIs to a separate custom domain and should be removed if no longer necessary
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

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()
Expand Down
16 changes: 6 additions & 10 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ class vedaAppSettings(BaseSettings):

veda_stac_root_path: str = Field(
"",
description="Optional path prefix to add to all api endpoints. Used to infer url of stac-api before app synthesis.",
description="STAC API root path. Used to infer url of stac-api before app synthesis.",
)

veda_raster_root_path: str = Field(
"",
description="Raster API root path",
ciaransweet marked this conversation as resolved.
Show resolved Hide resolved
)

veda_domain_create_custom_subdomains: bool = Field(
Expand All @@ -115,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()
Expand Down
49 changes: 0 additions & 49 deletions domain/infrastructure/config.py

This file was deleted.

148 changes: 0 additions & 148 deletions domain/infrastructure/construct.py

This file was deleted.

Loading