Update the API Gateway Stage Name in AWS CDK

avatar

Borislav Hadzhiev

Sat May 01 20211 min read

Updating the API Gateway Stage Name in AWS CDK #

By default the RestApi class creates a stage named prod in which it deploys our APIs.

In order to update the name of the stage for an API Gateway deployment in CDK, we have to set the deployOptions prop when instantiating the RestApi class.

import * as apigateway from '@aws-cdk/aws-apigateway'; import * as cdk from '@aws-cdk/core'; export class CdkStarterStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props: StackProps) { super(scope, id, props); const api = new apigateway.RestApi(this, 'api', { deployOptions: { // ๐Ÿ‘‡ update stage name to `dev` stageName: 'dev', }, }); } }

The deployOptions prop allows us to set the stage name for the API Gateway deployment.

The name of the stage is then included in the API url, for example: https://api-id.execute-api.region.amazonaws.com/STAGE-NAME/.

Further Reading #

Add me on LinkedIn

I'm a Web Developer with TypeScript, React.js, Node.js and AWS experience.

Let's connect on LinkedIn

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee