Skip to content

Commit 3fc1dfd

Browse files
Merge pull request #105 from developmentseed/NewVpc
New vpc
2 parents f76a5b4 + 39d17c8 commit 3fc1dfd

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

infrastructure/aws/cdk/app.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,34 @@ def __init__( # noqa: C901
134134
"""Define stack."""
135135
super().__init__(scope, id, **kwargs)
136136

137-
vpc = ec2.Vpc(self, f"{id}-vpc", nat_gateways=0)
137+
# vpc = ec2.Vpc(self, f"{id}-vpc", nat_gateways=0)
138+
139+
vpc = ec2.Vpc(
140+
self,
141+
f"{id}-vpc",
142+
subnet_configuration=[
143+
ec2.SubnetConfiguration(
144+
name="ingress",
145+
cidr_mask=24,
146+
subnet_type=ec2.SubnetType.PUBLIC,
147+
),
148+
ec2.SubnetConfiguration(
149+
name="application",
150+
cidr_mask=24,
151+
subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS,
152+
),
153+
ec2.SubnetConfiguration(
154+
name="rds",
155+
cidr_mask=28,
156+
subnet_type=ec2.SubnetType.PRIVATE_ISOLATED,
157+
),
158+
],
159+
nat_gateways=1,
160+
)
161+
print(
162+
"""The eoAPI stack use AWS NatGateway for the Raster service so it can reach the internet.
163+
This might incurs some cost (https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html)."""
164+
)
138165

139166
interface_endpoints = [
140167
(
@@ -164,6 +191,8 @@ def __init__( # noqa: C901
164191
ec2.InstanceSize(eodb_settings.instance_size),
165192
),
166193
database_name="postgres",
194+
# should set the subnet to `PRIVATE_ISOLATED` but then we need either a bastion host to connect to the db
195+
# or an API to ingest/delete data in the DB
167196
vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC),
168197
backup_retention=Duration.days(7),
169198
deletion_protection=eoapi_settings.stage.lower() == "production",
@@ -230,6 +259,9 @@ def __init__( # noqa: C901
230259
platform="linux/amd64",
231260
),
232261
vpc=vpc,
262+
vpc_subnets=ec2.SubnetSelection(
263+
subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS
264+
),
233265
allow_public_subnet=True,
234266
handler="handler.handler",
235267
memory_size=eoraster_settings.memory,
@@ -251,6 +283,7 @@ def __init__( # noqa: C901
251283
)
252284

253285
db.connections.allow_from(eoraster_function, port_range=ec2.Port.tcp(5432))
286+
254287
raster_api = apigw.HttpApi(
255288
self,
256289
f"{id}-raster-endpoint",
@@ -306,7 +339,6 @@ def __init__( # noqa: C901
306339
platform="linux/amd64",
307340
),
308341
vpc=vpc,
309-
allow_public_subnet=True,
310342
handler="handler.handler",
311343
memory_size=eostac_settings.memory,
312344
timeout=Duration.seconds(eostac_settings.timeout),
@@ -361,6 +393,8 @@ def __init__( # noqa: C901
361393

362394
if "DB_MAX_CONN_SIZE" not in env:
363395
env["DB_MAX_CONN_SIZE"] = "1"
396+
if "DB_MIN_CONN_SIZE" not in env:
397+
env["DB_MIN_CONN_SIZE"] = "1"
364398

365399
eovector_function = aws_lambda.Function(
366400
self,
@@ -375,7 +409,6 @@ def __init__( # noqa: C901
375409
platform="linux/amd64",
376410
),
377411
vpc=vpc,
378-
allow_public_subnet=True,
379412
handler="handler.handler",
380413
memory_size=eovector_settings.memory,
381414
timeout=Duration.seconds(eovector_settings.timeout),

0 commit comments

Comments
 (0)