- 最新
- 投票最多
- 评论最多
@awsmaker, did you define a Deployment in your CDK code?
The CDKv1 docs for Deployment indicate that a Deployment of a RestApi is immutable and changes to the RestApi model won't be reflected unless a new Deployment is created. (Using deploy: true
when defining the RestApi lets the RestApi construct manage a restApi.latestDeployment
deployment that it keeps up to date, but to take advantage of this you'll need to reference the latestDeployment
instead of creating another Deployment)
The docs indicate that changing the logical ID of the Deployment resource to include some arbitrary data will invalidate the Deployment and cause it to be redeployed every time the CDK is deployed. The docs recommend using the addToLogicalId(data)
method for this. I've also induced the same effect (with deploy: false
by simply adding the current timestamp to the id
param when initializing a new Deployment, like so:
this.myApi = new apig.RestApi(this, 'MyApi', {
deploy: false,
});
// force APIG deployment to be recreated every time even if no changes
const prodDeploy = new apig.Deployment(this, 'MyApiProdDeployment' + new Date().toISOString(), {
api: this.myApi,
description: 'prod deployment',
})
this.myApiStage = new apig.Stage(this, 'MyApiProdStage', {
deployment: prodDeploy,
metricsEnabled: true,
loggingLevel: apig.MethodLoggingLevel.INFO,
stageName: this.STAGE_NAME,
})
this.myApi.deploymentStage = this.myApiStage;
Just be aware that modifying the logical ID of the Deployment will cause it to be re-created with every cdk deploy
- this may not be desirable behavior in every situation.
For reference, the list of REST API updates that require redeployment can be found here: https://docs.aws.amazon.com/apigateway/latest/developerguide/updating-api.html
相关内容
- AWS 官方已更新 1 年前
Could you please share a short snippet of your CDK code to illustrate the issue?