Skip to content

Commit d6aedd7

Browse files
authored
feat: remove cloudfront distribution and custom alternate domain from backend (#422)
### Issue #403 #221 ### What + Why - Remove cloudfront distribution CDK from veda-backend because it's now managed in veda-routes - Update values passed into ingestor config to derive endpoint values using the custom host and stac and raster API root paths - Remove configuration and support for hosting duplicate stac and raster apis as alternative domains. ### Testing? Deployed to UAH
2 parents 72f446a + 8735f45 commit d6aedd7

File tree

11 files changed

+76
-606
lines changed

11 files changed

+76
-606
lines changed

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# veda-backend
2+
23
This project deploys a complete backend for a [SpatioTemporal Asset Catalog](https://stacspec.org/) including a postgres database, a metadata API, and raster tiling API. Veda-backend is a non-forked version of the [eoAPI](https://github.com/developmentseed/eoAPI) demo project. Veda-backend is decoupled from the demo project to selectively incorporate new stable functionality from the fast moving development in eoAPI while providing a continuous baseline for veda-backend users and to support project specific business and deployment logic.
34

45
The primary tools employed in the [eoAPI demo](https://github.com/developmentseed/eoAPI) and this project are:
6+
57
- [stac-spec](https://github.com/radiantearth/stac-spec)
68
- [stac-api-spec](https://github.com/radiantearth/stac-api-spec)
79
- [stac-fastapi](https://github.com/stac-utils/stac-fastapi)
@@ -11,6 +13,7 @@ The primary tools employed in the [eoAPI demo](https://github.com/developmentsee
1113
- [eoapi-cdk](https://github.com/developmentseed/eoapi-cdk/tree/main#eoapi-cdk-constructs) + [radiantearth/stac-browser](https://github.com/radiantearth/stac-browser)
1214

1315
## VEDA backend context
16+
1417
![architecture diagram](.readme/veda-overview-bw.svg)
1518

1619
_Edit this diagram in VS Code using the [Draw.io Integration Extension](https://marketplace.visualstudio.com/items?itemName=hediet.vscode-drawio) and export a new SVG_
@@ -33,12 +36,14 @@ An [.example.env](.example.env) template is supplied for local deployments. If u
3336
3437
### Fetch environment variables using AWS CLI
3538

36-
To retrieve the variables for a stage that has been previously deployed, the secrets manager can be used to quickly populate an .env file with [scripts/sync-env-local.sh](scripts/sync-env-local.sh).
39+
To retrieve the variables for a stage that has been previously deployed, the secrets manager can be used to quickly populate an .env file with [scripts/sync-env-local.sh](scripts/sync-env-local.sh).
3740

38-
```
41+
```bash
3942
./scripts/sync-env-local.sh <app-secret-name>
4043
```
44+
4145
### Basic environment variables
46+
4247
| Name | Explanation |
4348
| --- | --- |
4449
| `APP_NAME` | Optional app name used to name stack and resources, defaults to `veda-backend` |
@@ -48,6 +53,7 @@ To retrieve the variables for a stage that has been previously deployed, the sec
4853
| `VEDA_DB_SNAPSHOT_ID` | **Once used always REQUIRED** Optional RDS snapshot identifier to initialize RDS from a snapshot |
4954

5055
### Advanced configuration
56+
5157
The constructs and applications in this project are configured using pydantic. The settings are defined in config.py files stored alongside the associated construct or application--for example the settings for the RDS PostgreSQL construct are defined in database/infrastructure/config.py. For custom configuration, use environment variables to override the pydantic defaults.
5258

5359
| Construct | Env Prefix | Configuration |
@@ -64,24 +70,28 @@ The constructs and applications in this project are configured using pydantic. T
6470
### Deploying to the cloud
6571

6672
#### Install deployment pre-requisites
73+
6774
- [Node](https://nodejs.org/)
6875
- [NVM](https://github.com/nvm-sh/nvm#node-version-manager---)
6976
- [jq](https://jqlang.github.io/jq/) (used for exporting environment variable secrets to `.env` in [scripts/sync-env-local.sh](/scripts/sync-env-local.sh))
7077

7178
These can be installed with [homebrew](https://brew.sh/) on MacOS
72-
```
79+
80+
```bash
7381
brew install node
7482
brew install nvm
7583
brew install jq
7684
```
7785

7886
#### Virtual environment example
79-
```
87+
88+
```bash
8089
python3 -m venv .venv
8190
source .venv/bin/activate
8291
```
8392

8493
#### Install requirements
94+
8595
```bash
8696
nvm use --lts
8797
npm install --location=global aws-cdk
@@ -99,7 +109,7 @@ cdk diff
99109
# Execute deployment and standby--security changes will require approval for deployment
100110
cdk deploy
101111
```
102-
112+
103113
## Deleting the CloudFormation stack
104114

105115
If this is a development stack that is safe to delete, you can delete the stack in CloudFormation console or via `cdk destroy`, however, the additional manual steps were required to completely delete the stack resources:
@@ -112,44 +122,51 @@ If this is a development stack that is safe to delete, you can delete the stack
112122
## Custom deployments
113123

114124
The default settings for this project generate a complete AWS environment including a VPC and gateways for the stack. See this guidance for adjusting the veda-backend stack for existing managed and/or shared AWS environments.
125+
115126
- [Deploy to an existing managed AWS environment](docs/deploying_to_existing_environments.md)
116127
- [Creating a shared base VPC and AWS environment](docs/deploying_to_existing_environments.md#optional-deploy-standalone-base-infrastructure)
117128

118129
## Local Docker deployment
119130

120131
Start up a local stack
121-
```
132+
133+
```bash
122134
docker compose up
123135
```
136+
124137
Clean up after running locally
125-
```
138+
139+
```bash
126140
docker compose down
127141
```
128142

129143
## Running tests locally
130144

131145
To run tests implicated in CI, a script is included that requires as little setup as possible
132-
```
146+
147+
```bash
133148
./scripts/run-local-tests.sh
134149
```
135150

136151
In case of failure, all container logs will be written out to `container_logs.log`.
137152

138153
# Operations
139154

140-
## Adding new data to veda-backend
155+
## Adding new data to veda-backend
141156

142157
> **Warning** PgSTAC records should be loaded in the database using [pypgstac](https://github.com/stac-utils/pgstac#pypgstac) for proper indexing and partitioning.
143158
144159
The VEDA ecosystem includes tools specifially created for loading PgSTAC records and optimizing data assets. The [veda-data-airflow](https://github.com/NASA-IMPACT/veda-data-airflow) project provides examples of cloud pipelines that transform data to cloud optimized formats, generate STAC metadata, and submit records for publication to the veda-backend database via veda-backend's ingest API. Veda-backend's integrated ingest system includes an API lambda for enqueuing collection and item records in a DynamoDB table and an ingestor lambda that batch loads DDB enqueued records into the PgSTAC database. Currently, the client id and domain of an existing Cognito user pool programmatic client must be supplied in [configuration](ingest_api/infrastructure/config.py) as `VEDA_CLIENT_ID` and `VEDA_COGNITO_DOMAIN` (the [veda-auth project](https://github.com/NASA-IMPACT/veda-auth) can be used to deploy a Cognito user pool and client). To dispense auth tokens via the ingest API swagger docs and `/token` endpoints, an administrator must add the ingest API lambda URL to the allowed callbacks of the Cognito client.
145160

146161
## Support scripts
147162
Support scripts are provided for manual system operations.
163+
148164
- [Rotate pgstac password](support_scripts/README.md#rotate-pgstac-password)
149165

150166
# VEDA ecosystem
151167

152168
## Projects
169+
153170
| Name | Explanation |
154171
| --- | --- |
155172
| **veda-backend** | Central index (database) and APIs for recording, discovering, viewing, and using VEDA assets |
@@ -159,6 +176,7 @@ Support scripts are provided for manual system operations.
159176
| [**veda-data**](https://github.com/NASA-IMPACT/veda-data) | Collection and asset discovery configuration |
160177
| [**veda-data-airflow**](https://github.com/NASA-IMPACT/veda-data-airflow) | Cloud optimize data assets and submit records for publication to veda-stac-ingestor |
161178
| [**veda-docs**](https://github.com/NASA-IMPACT/veda-docs) | Documentation repository for end users of VEDA ecosystem data and tools |
179+
| [**veda-routes**](https://github.com/NASA-IMPACT/veda-routes)| Configuration for VEDA's Content Delivery Network |
162180

163181
## VEDA usage examples
164182

@@ -169,7 +187,9 @@ Support scripts are provided for manual system operations.
169187
# STAC community resources
170188

171189
## STAC browser
190+
172191
Radiant Earth's [stac-browser](https://github.com/radiantearth/stac-browser) is a browser for STAC catalogs. The demo version of this browser [radiantearth.github.io/stac-browser](https://radiantearth.github.io/stac-browser/#/) can be used to browse the contents of the veda-backend STAC catalog, paste the veda-backend stac-api URL deployed by this project in the demo and click load. Read more about the recent developments and usage of stac-browser [here](https://medium.com/radiant-earth-insights/the-exciting-future-of-the-stac-browser-2351143aa24b).
173192

174193
# License
194+
175195
This project is licensed under **Apache 2**, see the [LICENSE](LICENSE) file for more details.

app.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88

99
from config import veda_app_settings
1010
from database.infrastructure.construct import RdsConstruct
11-
from domain.infrastructure.construct import DomainConstruct
1211
from ingest_api.infrastructure.config import IngestorConfig as ingest_config
1312
from ingest_api.infrastructure.construct import ApiConstruct as ingest_api_construct
1413
from ingest_api.infrastructure.construct import IngestorConstruct as ingestor_construct
1514
from network.infrastructure.construct import VpcConstruct
1615
from permissions_boundary.infrastructure.construct import PermissionsBoundaryAspect
1716
from raster_api.infrastructure.construct import RasterApiLambdaConstruct
18-
from routes.infrastructure.construct import CloudfrontDistributionConstruct
1917
from s3_website.infrastructure.construct import VedaWebsite
2018
from stac_api.infrastructure.construct import StacApiLambdaConstruct
2119

@@ -71,15 +69,12 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
7169
stage=veda_app_settings.stage_name(),
7270
)
7371

74-
domain = DomainConstruct(veda_stack, "domain", stage=veda_app_settings.stage_name())
75-
7672
raster_api = RasterApiLambdaConstruct(
7773
veda_stack,
7874
"raster-api",
7975
stage=veda_app_settings.stage_name(),
8076
vpc=vpc.vpc,
8177
database=database,
82-
domain=domain,
8378
)
8479

8580
stac_api = StacApiLambdaConstruct(
@@ -89,23 +84,12 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
8984
vpc=vpc.vpc,
9085
database=database,
9186
raster_api=raster_api,
92-
domain=domain,
9387
)
9488

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

99-
veda_routes = CloudfrontDistributionConstruct(
100-
veda_stack,
101-
"routes",
102-
stage=veda_app_settings.stage_name(),
103-
raster_api_id=raster_api.raster_api.api_id,
104-
stac_api_id=stac_api.stac_api.api_id,
105-
origin_bucket=website.bucket,
106-
region=veda_app_settings.cdk_default_region,
107-
)
108-
10993
# Only create a stac browser if we can infer the catalog url from configuration before synthesis (API Gateway URL not yet available)
11094
stac_catalog_url = veda_app_settings.get_stac_catalog_url()
11195
if stac_catalog_url:
@@ -128,15 +112,13 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
128112
raster_api_url=raster_api.raster_api.url,
129113
)
130114

131-
132115
ingest_api = ingest_api_construct(
133116
veda_stack,
134117
"ingest-api",
135118
config=ingestor_config,
136119
db_secret=database.pgstac.secret,
137120
db_vpc=vpc.vpc,
138121
db_vpc_subnets=database.vpc_subnets,
139-
domain=domain,
140122
)
141123

142124
ingestor = ingestor_construct(
@@ -149,51 +131,6 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
149131
db_vpc_subnets=database.vpc_subnets,
150132
)
151133

152-
veda_routes.add_ingest_behavior(
153-
ingest_api=ingest_api.api, stage=veda_app_settings.stage_name()
154-
)
155-
156-
# Must be done after all CF behaviors exist
157-
veda_routes.create_route_records(stage=veda_app_settings.stage_name())
158-
159-
160-
# TODO this conditional supports deploying a second set of APIs to a separate custom domain and should be removed if no longer necessary
161-
if veda_app_settings.alt_domain():
162-
alt_domain = DomainConstruct(
163-
veda_stack,
164-
"alt-domain",
165-
stage=veda_app_settings.stage_name(),
166-
alt_domain=True,
167-
)
168-
169-
alt_raster_api = RasterApiLambdaConstruct(
170-
veda_stack,
171-
"alt-raster-api",
172-
stage=veda_app_settings.stage_name(),
173-
vpc=vpc.vpc,
174-
database=database,
175-
domain_name=alt_domain.raster_domain_name,
176-
)
177-
178-
alt_stac_api = StacApiLambdaConstruct(
179-
veda_stack,
180-
"alt-stac-api",
181-
stage=veda_app_settings.stage_name(),
182-
vpc=vpc.vpc,
183-
database=database,
184-
raster_api=raster_api,
185-
domain_name=alt_domain.stac_domain_name,
186-
)
187-
188-
alt_ingest_api = ingest_api_construct(
189-
veda_stack,
190-
"alt-ingest-api",
191-
config=ingestor_config,
192-
db_secret=database.pgstac.secret,
193-
db_vpc=vpc.vpc,
194-
domain_name=alt_domain.ingest_domain_name,
195-
)
196-
197134
git_sha = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
198135
try:
199136
git_tag = subprocess.check_output(["git", "describe", "--tags"]).decode().strip()

config.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ class vedaAppSettings(BaseSettings):
9090

9191
veda_stac_root_path: str = Field(
9292
"",
93-
description="Optional path prefix to add to all api endpoints. Used to infer url of stac-api before app synthesis.",
93+
description="STAC API root path. Used to infer url of stac-api before app synthesis.",
94+
)
95+
96+
veda_raster_root_path: str = Field(
97+
"",
98+
description="Raster API root path",
9499
)
95100

96101
veda_domain_create_custom_subdomains: bool = Field(
@@ -115,15 +120,6 @@ def cdk_env(self) -> dict:
115120
else:
116121
return {}
117122

118-
def alt_domain(self) -> bool:
119-
"""True if alternative domain and host parameters provided"""
120-
return all(
121-
[
122-
self.veda_domain_alt_hosted_zone_id,
123-
self.veda_domain_alt_hosted_zone_name,
124-
]
125-
)
126-
127123
def stage_name(self) -> str:
128124
"""Force lowercase stage name"""
129125
return self.stage.lower()

domain/infrastructure/config.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)