1212from aws_cdk import aws_sns as sns
1313from aws_cdk import aws_sns_subscriptions as subscriptions
1414from aws_cdk .aws_apigatewayv2_integrations import HttpLambdaIntegration
15- from config import StackSettings
15+ from config import StackSettings , AppSettings
1616from constructs import Construct
1717
18- settings = StackSettings ()
18+ stack_settings , app_settings = StackSettings (), AppSettings ()
1919
2020DEFAULT_ENV = {
2121 "GDAL_CACHEMAX" : "200" , # 200 mb
@@ -77,6 +77,7 @@ def __init__(
7777 environment = {
7878 ** DEFAULT_ENV ,
7979 ** environment ,
80+ "TITILER_CMR_ROOT_PATH" : app_settings .root_path ,
8081 },
8182 log_retention = logs .RetentionDays .ONE_WEEK ,
8283 role = iam_reader_role ,
@@ -89,12 +90,19 @@ def __init__(
8990 self ,
9091 f"{ id } -endpoint" ,
9192 default_integration = HttpLambdaIntegration (
92- f"{ id } -integration" , lambda_function
93+ f"{ id } -integration" ,
94+ lambda_function ,
95+ parameter_mapping = apigw .ParameterMapping ().overwrite_header (
96+ "host" ,
97+ apigw .MappingValue (stack_settings .veda_custom_host ),
98+ )
99+ if stack_settings .veda_custom_host
100+ else None ,
93101 ),
94102 )
95103
96104 # Create an SNS Topic
97- if settings .alarm_email :
105+ if app_settings .alarm_email :
98106 topic = sns .Topic (
99107 self ,
100108 f"{ id } -500-Errors" ,
@@ -103,7 +111,7 @@ def __init__(
103111 )
104112 # Subscribe email to the topic
105113 topic .add_subscription (
106- subscriptions .EmailSubscription (settings .alarm_email ),
114+ subscriptions .EmailSubscription (app_settings .alarm_email ),
107115 )
108116
109117 # Create CloudWatch Alarm
@@ -130,30 +138,30 @@ def __init__(
130138app = App ()
131139
132140perms = []
133- if settings .buckets :
141+ if app_settings .buckets :
134142 perms .append (
135143 iam .PolicyStatement (
136144 actions = ["s3:GetObject" ],
137- resources = [f"arn:aws:s3:::{ bucket } *" for bucket in settings .buckets ],
145+ resources = [f"arn:aws:s3:::{ bucket } *" for bucket in app_settings .buckets ],
138146 )
139147 )
140148
141149lambda_stack = LambdaStack (
142150 app ,
143- f"{ settings .name } -{ settings .stage } " ,
144- memory = settings .memory ,
145- timeout = settings .timeout ,
146- concurrent = settings .max_concurrent ,
147- role_arn = settings .role_arn ,
151+ f"{ app_settings .name } -{ app_settings .stage } " ,
152+ memory = app_settings .memory ,
153+ timeout = app_settings .timeout ,
154+ concurrent = app_settings .max_concurrent ,
155+ role_arn = app_settings .role_arn ,
148156 permissions = perms ,
149- environment = settings .additional_env ,
157+ environment = app_settings .additional_env ,
150158)
151159# Tag infrastructure
152160for key , value in {
153- "Project" : settings .name ,
154- "Stack" : settings .stage ,
155- "Owner" : settings .owner ,
156- "Client" : settings .client ,
161+ "Project" : app_settings .name ,
162+ "Stack" : app_settings .stage ,
163+ "Owner" : app_settings .owner ,
164+ "Client" : app_settings .client ,
157165}.items ():
158166 if value :
159167 Tags .of (lambda_stack ).add (key , value )
0 commit comments