Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
How do I retrieve the apiId when creating a CfnDeployment via CDK?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use Ref.

AWS::ApiGatewayV2::Api CloudFormation docs: Ref: When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the API ID, such as a1bcdef2gh.

// synth-time token, deploy-time string
const apiId = cdk.Fn.ref(api.logicalId);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!