I am building a serverless API using AWS CDK, API gateway and lambda. Now I am testing out managing deployments for different stages of my API. Building what I am trying to is that I am trying to create multiple stages and each associated with its own deployment. And I can choose which stage I want to update by updating the respective deployment resource's logical id. According to this article, if the deployment resource's logical ID does not change, the stage is not updated as the deployment was not made to the stage. But even though I did not change the logical id of the deployment, it's still deployment the latest changes. Here is what I did.

I have created a deployment and a stage like this

this.api = new apigateway.RestApi(this, `TodoAppApi`, {
        restApiName: buildConfig.apiName,
        description: buildConfig.apiDescription,
        cloudWatchRole: true,
        deploy: false,
    });

const v1Deployment = new apigateway.Deployment(this, `ApiDeployment-v1-1), {
            api: this.api,
            retainDeployments: true,
        });

        const v1LogGroup = new LogGroup(this, `ApiLogGroup-v1`);

        const v1Stage = new apigateway.Stage(this, `ApiV1Stage`, {
            deployment: v1Deployment,
            stageName: `v1`,
            accessLogDestination: new apigateway.LogGroupLogDestination(v1LogGroup),
            accessLogFormat: apigateway.AccessLogFormat.jsonWithStandardFields(),
            metricsEnabled: true,
            loggingLevel: apigateway.MethodLoggingLevel.INFO,
            dataTraceEnabled: true,
            cachingEnabled: false,
        });

    const v1Handler = this.createHandler(`v1/greeting.handlers`, `Greeting-v1`, `greet`)

        this.addApiRoute(`greet`, `GET`, v1Handler, false);

As you can see in the code, the deployment has logical id of the deployment is ApiDeployment-v1-1.

Also this.addApiRoute is the custom function I wrote to simply add the lambda as an api route to the API.

Then I deploy the api by running cdk synth --all && cdk deploy --all.

The API was deployed successfully.

Then I updated the lambda function locally. Then I run cdk synth --all && cdk deploy --all again. But the lambda function changes are deployed to the existing API even thought I did not change the deployment's logical resource's ID. How can I make it to only deploy the changes when the deployment's id changes as mentioned in the article?

0

There are 0 best solutions below