Unable to map Rest API with custom domain using AWS CDK.

0

Hi, I have an API that I want to map with my custom domain. But I am getting this error - "Invalid stage identifier specified (Service: ApiGateway, Status Code: 400, Request ID: 461a0c54-ddd6-4df5-adce-d6b813208446)".

The following code I am using for API mapping -

const myAPI = new RestApi(this, MyRestAPI, { deployOptions: { stageName: props.stage, }, }); new CfnBasePathMapping(this, myAPIMapping, { basePath: 'myapi', domainName: props.domainName.domainName, restApiId: myAPI.restApiId, stage: props.stage, });

Please help me with your valuable suggestion. Thanks you.

1 Answer
0
Accepted Answer

Is the API Gateway stage created at the same time as this stack?
If the mapping is created before the API Gateway stage, the error message "Invalid stage identifier specified" may appear.
If they are created at the same time, try using "addDependency" and wait for the API Gateway stage to be created.
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib-readme.html#dependencies

The following code may fix the problem.

const CfnBasePathMapping = new CfnBasePathMapping(this, myAPIMapping, { basePath: 'myapi', domainName: props.domainName.domainName, restApiId: myAPI.restApiId, stage: props.stage, });
CfnBasePathMapping.addDependency(myAPI);
profile picture
EXPERT
answered 9 months ago
profile pictureAWS
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions