I'm using aws-cdk-lib
version 2 to create a CloudFormation stack. I define my API as follows:
const api = new apigatewayv2.CfnApi(this, 'MyApi', { body: YAML.parse(apiSpec), failOnWarnings: true });
This successfully creates my API on deploy. Now I'd like to automate creating a stage for this API. This is what I'm attempting:
new apigatewayv2.CfnStage(this, 'dev-stage', {
stageName: 'dev',
apiId: '???????', // <--- How do I find this value?
autoDeploy: true,
});
As you can see, one of the required parameters when creating CfnStage
is apiId
, which doesn't seem available via the CfnApi
object created earlier (there is a logicalId
property, but it's not the value CfnStage
is expecting).
I can find the correct value on the AWS console after the CDK script runs, but that doesn't do me much good if I'm trying to automate the creation of the stage via CDK all in a single deploy.
So: How do I determine the correct apiId
when creating a CfnStage
without having to have already deployed the API?