Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom parameter mapping when using custom API domain #75

Closed
vincentsarago opened this issue Oct 5, 2023 · 1 comment · Fixed by #105
Closed

Add custom parameter mapping when using custom API domain #75

vincentsarago opened this issue Oct 5, 2023 · 1 comment · Fixed by #105

Comments

@vincentsarago
Copy link
Member

When using custom API domain in API Gateway the FastAPI application (starlette) will still receive the api gateway hostname and thus use it internally (e.g if you have an endpoint that construct other endpoint url, it will return the API gateway url instead of you custom domain name)

e.g titiler

import httpx

resp = httpx.get("https://stac.eoapi.dev")
print(resp.json()["links"][2]

>>      {
      "rel": "data",
      "type": "application/json",
      "href": "https://stac.eoapi.dev/collections"
    }

☝️ this is giving the correct result (stac.eoapi.dev hostname) because I've manually added custom parameter mapping in the API Gateway console:

Screenshot 2023-10-05 at 1 00 59 PM

I believe we can automatically create this in 👇

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

with:
https://constructs.dev/packages/@aws-cdk/aws-apigatewayv2/v/1.204.0/api/ParameterMapping?lang=typescript

    const stacApi = new HttpApi(this, `${Stack.of(this).stackName}-stac-api`, {
      defaultDomainMapping: props.stacApiDomainName ? { 
        domainName: props.stacApiDomainName
      } : undefined,
      defaultIntegration: new HttpLambdaIntegration("integration", this.stacApiLambdaFunction, parameterMapping = props.stacApiDomainName ? {new ParameterMapping().overwriteHeader('host', MappingValue.requestHeader(props.stacApiDomainName))} : undefined),
    });
@slesaad
Copy link

slesaad commented Oct 5, 2023

@vincentsarago i tested this with the ghg center backend, and MappingValue.requestHeader threw an error

Invalid mapping expression specified: Validation Result: warnings : [], errors : [Host header manipulation only supports overwriting and must be statically defined] (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: 2e6e9902-e3c9-4fe7-8e22-3fbc4bee9d92; Proxy: null

should probably be custom instead

MappingValue.custom(props.stacApiDomainName)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants