Reputation: 571
How to set 'Stage' using AWS-CDK in API-GW Custom Domain Base Path Mapping?
Here is the aws-cdk code that creates api-gw custom domain with base path mapping, but the stage is set as '*' I need to set it to a specific stage How can I do that?
cdk version: 1.6.1 (build a09203a)
const restApiObj = {
node: this.node,
stack: Stack.of(this),
restApiId: api.ref
};
this.customDomainName = new apiGateway.DomainName(this, "DomainName", {
endpointType: EndpointType.REGIONAL,
certificate: {
certificateArn: props.customDomainNameProps.customDomainNameCertificateARN,
node: this.node,
stack: Stack.of(this)
},
domainName: (props.customDomainNameProps.customDomainName)?props.customDomainNameProps.customDomainName:defaultApiGWDomainName,
});
this.customDomainName.addBasePathMapping(restApiObj, {
basePath: (props.customDomainNameProps.domainNameBasePathMapping?props.customDomainNameProps.domainNameBasePathMapping : ApigwConstruct.API_GW_DEFAULT_BASE_MAPPING)
});
Upvotes: 0
Views: 1688
Reputation: 571
I found a way of how solving this, by using low level constructs - CfnBaseMapping, here is the code:
const basePathMapping = new CfnBasePathMapping(this, "basePathMapping", {
basePath: (props.customDomainNameProps.domainNameBasePathMapping?props.customDomainNameProps.domainNameBasePathMapping : ApigwConstruct.API_GW_DEFAULT_BASE_MAPPING),
domainName: this.customDomainName.domainName,
restApiId: api.ref,
stage: props.stageName
});
Upvotes: 2