Skip to content

Commit c9eeb00

Browse files
jjfrenchemileten
andauthored
feat: custom domain names for apis (#63)
* feat: custom domain names for apis * import the titiler app AFTER setting up the postgres env vars in the titiler-pgstac handler * add the missing ingestorDomainNameOptions parameter when calling the ingestor construct buildApiEndpoint method * fixes a titiler-pgstac handler bug introduced in #61 --------- Co-authored-by: emileten <[email protected]>
1 parent 9ea2c18 commit c9eeb00

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

lib/ingestor-api/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class StacIngestor extends Construct {
6262
stage: props.stage,
6363
endpointConfiguration: props.apiEndpointConfiguration,
6464
policy: props.apiPolicy,
65+
ingestorDomainNameOptions: props.ingestorDomainNameOptions,
6566
});
6667

6768
this.buildIngestor({
@@ -191,7 +192,9 @@ export class StacIngestor extends Construct {
191192
stage: string;
192193
policy?: iam.PolicyDocument;
193194
endpointConfiguration?: apigateway.EndpointConfiguration;
195+
ingestorDomainNameOptions?: apigateway.DomainNameOptions;
194196
}): apigateway.LambdaRestApi {
197+
195198
return new apigateway.LambdaRestApi(
196199
this,
197200
`${Stack.of(this).stackName}-ingestor-api`,
@@ -205,6 +208,11 @@ export class StacIngestor extends Construct {
205208

206209
endpointConfiguration: props.endpointConfiguration,
207210
policy: props.policy,
211+
212+
domainName: props.ingestorDomainNameOptions ? {
213+
domainName: props.ingestorDomainNameOptions.domainName,
214+
certificate: props.ingestorDomainNameOptions.certificate,
215+
} : undefined,
208216
}
209217
);
210218
}
@@ -277,4 +285,9 @@ export interface StacIngestorProps {
277285
* API Policy Document, useful for creating private APIs.
278286
*/
279287
readonly apiPolicy?: iam.PolicyDocument;
288+
289+
/**
290+
* Custom Domain Name Options for Ingestor API
291+
*/
292+
readonly ingestorDomainNameOptions?: apigateway.DomainNameOptions;
280293
}

lib/stac-api/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
PythonFunction,
1111
PythonFunctionProps,
1212
} from "@aws-cdk/aws-lambda-python-alpha";
13-
import { HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
13+
import { IDomainName, HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
1414
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
1515
import { Construct } from "constructs";
1616

@@ -58,6 +58,9 @@ export class PgStacApiLambda extends Construct {
5858
this.stacApiLambdaFunction.connections.allowTo(props.db, ec2.Port.tcp(5432));
5959

6060
const stacApi = new HttpApi(this, `${Stack.of(this).stackName}-stac-api`, {
61+
defaultDomainMapping: props.stacApiDomainName ? {
62+
domainName: props.stacApiDomainName
63+
} : undefined,
6164
defaultIntegration: new HttpLambdaIntegration("integration", this.stacApiLambdaFunction),
6265
});
6366

@@ -102,6 +105,11 @@ export interface PgStacApiLambdaProps {
102105
* Customized environment variables to send to fastapi-pgstac runtime.
103106
*/
104107
readonly apiEnv?: Record<string, string>;
108+
109+
/**
110+
* Custom Domain Name Options for STAC API,
111+
*/
112+
readonly stacApiDomainName?: IDomainName;
105113
}
106114

107115
export interface ApiEntrypoint {

lib/titiler-pgstac-api/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Duration,
1010
aws_logs,
1111
} from "aws-cdk-lib";
12-
import { HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
12+
import { IDomainName, HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
1313
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
1414
import { Construct } from "constructs";
1515

@@ -67,6 +67,9 @@ import {
6767
this.titilerPgstacLambdaFunction.connections.allowTo(props.db, ec2.Port.tcp(5432), "allow connections from titiler");
6868

6969
const stacApi = new HttpApi(this, `${Stack.of(this).stackName}-titiler-pgstac-api`, {
70+
defaultDomainMapping: props.titilerPgstacApiDomainName ? {
71+
domainName: props.titilerPgstacApiDomainName
72+
} : undefined,
7073
defaultIntegration: new HttpLambdaIntegration("integration", this.titilerPgstacLambdaFunction),
7174
});
7275

@@ -111,4 +114,8 @@ import {
111114
*/
112115
readonly buckets?: string[];
113116

114-
}
117+
/**
118+
* Custom Domain Name Options for Titiler Pgstac API,
119+
*/
120+
readonly titilerPgstacApiDomainName?: IDomainName;
121+
}

lib/titiler-pgstac-api/runtime/src/handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import os
77
from mangum import Mangum
88
from utils import get_secret_dict
9-
from titiler.pgstac.main import app
10-
from titiler.pgstac.db import connect_to_db
119

1210
pgstac_secret_arn = os.environ["PGSTAC_SECRET_ARN"]
1311

@@ -22,6 +20,9 @@
2220
}
2321
)
2422

23+
from titiler.pgstac.main import app # noqa: E402
24+
from titiler.pgstac.db import connect_to_db # noqa: E402
25+
2526

2627
@app.on_event("startup")
2728
async def startup_event() -> None:

0 commit comments

Comments
 (0)