We are using cdk(@aws-cdk/aws-apigateway) to implement API gateway and its deployment and stage creation using CfnDeployment and CfnStage cloudformation resources.
Yesterday we added one more api and through CICD it deploys to my SBX environment. When i verify the API gateway resources section , my newly added resources is there but not in stage sections. We are facing the issue from yesterday only.
we are using "@aws-cdk/aws-apigatewayv2": "1.45.0",
It's not clear from here what problem you are facing. Can you provide a code sample on what you're doing and what you mean by 'my newly added resources is there but not in stage sections'?
CfnDeployment and CfnStage are auto-generated directly from CloudFormation, so whatever you provide there gets converted into the CloudFormation template. There is no 'smart' logic behind it, so additional steps might be needed here, such as re-triggering a new deployment.
Usually, in these cases, a new deployment may have to be triggered after adjusting the resources; it does not occur automatically.
I will probably be able to help better once you add in more information.
HI @nija-at , PFB for the piece of code
const api = new apigw.CfnRestApi(this, apiGWName, {
name: awsPrefixName + apiGWName,
description: this.node.tryGetContext("apiGWDescription"),
body: openAPIDocument, // swagger file document
minimumCompressionSize: 0,
endpointConfiguration: {
types: [apigw.EndpointType.REGIONAL]
}
});
const deployment = new apigw.CfnDeployment(this, restApiDeployment, {
description: restApiDeploymentDesc,
restApiId: api.ref,
});
const stage = new apigw.CfnStage(this, restApiStage, {
deploymentId: deployment.ref,
methodSettings: [{
dataTraceEnabled: true,
httpMethod: "*",
loggingLevel: apigw.MethodLoggingLevel.INFO,
metricsEnabled: true,
resourcePath: "/*"
}],
restApiId: api.ref,
stageName: props.lambdaProps.ApiLambdaVersion.stageName,
variables: {
ApiVersion: props.lambdaProps.ApiLambdaVersion.stageName + props.lambdaProps.ApiLambdaVersion.basePathVersion
}
});
the above is the one we are using for crreating rest api with stages and deployment . For the first time , it was working fine. NExt time we added added one more resources , it is added in restapi resources section , not in stages section.
Note: We have already CfnDeployment section
We have observed same issue for our API Gateway from last week. We had to deploy API manually to reflect in stages. The cdk version we use is 1.45.0. @nija-at @KarthickEmis
The fact that you are using CfnRestApi tells me that you are using @aws-cdk/aws-apigateway package and not the @aws-cdk/awsapigatewayv2 package. Your title and description has references to apigatewayv2. Can you clarify?
This is a known limitation of using APIGateway with CloudFormation. It is not sufficient to update just the Resources and Methods in the CloudFormation template; you will also have force CloudFormation to update or replace the AWS::CloudFormation::Deployment resource type, for these changes to be reflected in the deployment.
In aws-apigateway, the CDK solves this problem when using the RestApi construct and you let the construct automatically create a new Deployment, by re-computing the logical id of the Deployment resource and hence triggering an update. For reference, the logic we apply is here. However, you are using the Cfn constructs that are auto-generated directly from CloudFormation and hence not taking advantage of this.
Either you have to switch to using our higher level constructs to take advantage of this feature, or find a way to update the Deployment resource when you change any property of the RestApi (including Methods and Resources).
Thanks @nija-at for the update.
This worked when implementing RestApi construct instead of CfnRestApi, CfnDeployment and CfnStage constructs separately.