Skip to content

Commit

Permalink
feat: custom domain names for apis (#63)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
jjfrench and emileten authored Aug 21, 2023
1 parent 9ea2c18 commit c9eeb00
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
13 changes: 13 additions & 0 deletions lib/ingestor-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class StacIngestor extends Construct {
stage: props.stage,
endpointConfiguration: props.apiEndpointConfiguration,
policy: props.apiPolicy,
ingestorDomainNameOptions: props.ingestorDomainNameOptions,
});

this.buildIngestor({
Expand Down Expand Up @@ -191,7 +192,9 @@ export class StacIngestor extends Construct {
stage: string;
policy?: iam.PolicyDocument;
endpointConfiguration?: apigateway.EndpointConfiguration;
ingestorDomainNameOptions?: apigateway.DomainNameOptions;
}): apigateway.LambdaRestApi {

return new apigateway.LambdaRestApi(
this,
`${Stack.of(this).stackName}-ingestor-api`,
Expand All @@ -205,6 +208,11 @@ export class StacIngestor extends Construct {

endpointConfiguration: props.endpointConfiguration,
policy: props.policy,

domainName: props.ingestorDomainNameOptions ? {
domainName: props.ingestorDomainNameOptions.domainName,
certificate: props.ingestorDomainNameOptions.certificate,
} : undefined,
}
);
}
Expand Down Expand Up @@ -277,4 +285,9 @@ export interface StacIngestorProps {
* API Policy Document, useful for creating private APIs.
*/
readonly apiPolicy?: iam.PolicyDocument;

/**
* Custom Domain Name Options for Ingestor API
*/
readonly ingestorDomainNameOptions?: apigateway.DomainNameOptions;
}
10 changes: 9 additions & 1 deletion lib/stac-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PythonFunction,
PythonFunctionProps,
} from "@aws-cdk/aws-lambda-python-alpha";
import { HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
import { IDomainName, HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
import { Construct } from "constructs";

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

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

Expand Down Expand Up @@ -102,6 +105,11 @@ export interface PgStacApiLambdaProps {
* Customized environment variables to send to fastapi-pgstac runtime.
*/
readonly apiEnv?: Record<string, string>;

/**
* Custom Domain Name Options for STAC API,
*/
readonly stacApiDomainName?: IDomainName;
}

export interface ApiEntrypoint {
Expand Down
11 changes: 9 additions & 2 deletions lib/titiler-pgstac-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Duration,
aws_logs,
} from "aws-cdk-lib";
import { HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
import { IDomainName, HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
import { Construct } from "constructs";

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

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

Expand Down Expand Up @@ -111,4 +114,8 @@ import {
*/
readonly buckets?: string[];

}
/**
* Custom Domain Name Options for Titiler Pgstac API,
*/
readonly titilerPgstacApiDomainName?: IDomainName;
}
5 changes: 3 additions & 2 deletions lib/titiler-pgstac-api/runtime/src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import os
from mangum import Mangum
from utils import get_secret_dict
from titiler.pgstac.main import app
from titiler.pgstac.db import connect_to_db

pgstac_secret_arn = os.environ["PGSTAC_SECRET_ARN"]

Expand All @@ -22,6 +20,9 @@
}
)

from titiler.pgstac.main import app # noqa: E402
from titiler.pgstac.db import connect_to_db # noqa: E402


@app.on_event("startup")
async def startup_event() -> None:
Expand Down

0 comments on commit c9eeb00

Please sign in to comment.