- Newest
- Most votes
- Most comments
Hello,
If your manually-defined deployment resource's (e.g. apiGatewayDeployment) logical ID does not change — it will continue to represent the snapshot in time in which it was created. This means that any newly-added methods or resources will be attached to restApi.latestDeployment (enabled by default) or won't reflect unless a new deployment resource is created [1].
To replicate the behavior of restApi.latestDeployment for your manually-defined deployment:
- Use
addToLogicalId()to modify the logical ID ofApiGatewayDeploymentwhenever stack changes are made:
- For example, add
apiGatewayDeployment.addToLogicalId(new Date().toISOString())to your stack file [1] - Alternatively, you may include a timestamp during the deployment's creation:
const apiGatewayDeployment = new apigateway.Deployment(this, 'ApiGatewayDeployment' + new Date().toISOString() [...][2]
- As an extra/optional step (as you've already done) include
node.addDependency(dep)— doing so will further replicate the provisioning behavior of restApi.latestDeployment for your manually-defined deployment.
Note: It's still necessary that the logical ID be augmented — as you've mentioned, calling node.addDependency() alone won't suffice.
Lastly, you may opt to set your REST API's deploy property to false [3] — this will prevent new methods/resources from being attached to restApi.latestDeployment (i.e. prod stage).
References:
[1] https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.Deployment.html
[3] https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html#deploy
Relevant content
- AWS OFFICIALUpdated 2 years ago
