Update the API Gateway Stage Name in AWS CDK


Borislav Hadzhiev

Last updated: Apr 14, 2022


Photo from Unsplash

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-lib/aws-apigateway'; import * as cdk from 'aws-cdk-lib/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 #

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.