This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
forked from NASA-IMPACT/veda-backend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
125 lines (103 loc) · 3.61 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
""" CDK Configuration for the veda-backend stack."""
from aws_cdk import App, Aspects, Stack, Tags, aws_iam
from constructs import Construct
from config import veda_app_settings
from database.infrastructure.construct import RdsConstruct
from domain.infrastructure.construct import DomainConstruct
from network.infrastructure.construct import VpcConstruct
from raster_api.infrastructure.construct import RasterApiLambdaConstruct
from routes.infrastructure.construct import CloudfrontDistributionConstruct
from stac_api.infrastructure.construct import StacApiLambdaConstruct
app = App()
class VedaStack(Stack):
"""CDK stack for the veda-backend stack."""
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
"""."""
super().__init__(scope, construct_id, **kwargs)
if veda_app_settings.permissions_boundary_policy_name:
permission_boundary_policy = aws_iam.ManagedPolicy.from_managed_policy_name(
self,
"permissions-boundary",
veda_app_settings.permissions_boundary_policy_name,
)
aws_iam.PermissionsBoundary.of(self).apply(permission_boundary_policy)
from permission_boundary import PermissionBoundaryAspect
Aspects.of(self).add(PermissionBoundaryAspect(permission_boundary_policy))
veda_stack = VedaStack(
app,
f"{veda_app_settings.app_name}-{veda_app_settings.stage_name()}",
env=veda_app_settings.cdk_env(),
)
if veda_app_settings.vpc_id:
vpc = VpcConstruct(
veda_stack,
"network",
vpc_id=veda_app_settings.vpc_id,
stage=veda_app_settings.stage_name(),
)
else:
vpc = VpcConstruct(veda_stack, "network", stage=veda_app_settings.stage_name())
database = RdsConstruct(
veda_stack, "database", vpc.vpc, 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(
veda_stack,
"stac-api",
stage=veda_app_settings.stage_name(),
vpc=vpc.vpc,
database=database,
raster_api=raster_api,
domain=domain,
)
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,
region=veda_app_settings.cdk_default_region,
)
# 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,
)
for key, value in {
"Project": veda_app_settings.app_name,
"Stack": veda_app_settings.stage_name(),
"Client": "nasa-impact",
"Owner": "ds",
}.items():
if value:
Tags.of(app).add(key=key, value=value)
app.synth()