Question about the <Api path mapping>: AWS has sup...
# help
g
Question about the Api path mapping: AWS has supported multi-level base maps for the past few months, but when I try to construct an API with a custom domain with a multilevel
path
, it throws the following error:
Copy code
Error: An ApiMapping key may contain only letters, numbers and one of $-_.+!*'(),
    at new ApiMapping (app/node_modules/@aws-cdk/aws-apigatewayv2/lib/common/api-mapping.ts:69:13)
    at HttpStage._addDomainMapping (app/node_modules/@aws-cdk/aws-apigatewayv2/lib/common/base.ts:48:5)
    at new HttpStage (app/node_modules/@aws-cdk/aws-apigatewayv2/lib/http/stage.ts:118:12)
    at new HttpApi (app/node_modules/@aws-cdk/aws-apigatewayv2/lib/http/api.ts:300:27)
    at new Api (app/node_modules/@serverless-stack/resources/src/Api.ts:178:22)
This comment on aws-cdk seems to be related to v1 of the apigateway, but I’m not sure if v2 supports it in CDK yet.
f
Hmm.. it might be CDK hasn’t added support for it.
Let me check their code.
Yup, CDK hasn’t supported it yet. But take a look at this issue, give that workaround a try - https://github.com/aws/aws-cdk/issues/14822
g
@Frank if you want to add to the docs, instead of using the customDomain option for sst.Api, I did the following:
Copy code
import {CfnApiMapping, IStage} from "@aws-cdk/aws-apigatewayv2";
...
        const myApi = sst.Api(...)
        
        const customDomainMapping = new CfnApiMapping(this, "customDomainMapping", {
            apiId: myApi.httpApi.apiId,
            domainName: '<http://api.myapp.com|api.myapp.com>',
            stage: (<IStage>myApi.httpApi.defaultStage).stageName,
            apiMappingKey: (scope.stage !== 'prod' ? {path: scope.stage + '/orders/returns'} : {path: 'orders/returns'})
        })
        
        this.addOutputs({
            "CustomEndpoint": 'https://' + customDomainMapping.domainName + '/' + customDomainMapping.apiMappingKey
        });
fyi @Cory Gackenheimer
f
Oh wow.. u got it working fast!
I just opened an issue documenting the workaround - https://github.com/serverless-stack/serverless-stack/issues/529