Skip to content

Commit eac7695

Browse files
Elad Ben-Israelmergify[bot]
authored andcommitted
fix(apigateway): deployment not invalidated when integration is changed (#4552)
* fix(apigateway): deployment not invalidated when integration is changed The calculation of the deployment logical id is based on a hash of the apigateway model, which includes components such as the resource and method configurations. method integrations, which are part of the method configuration are also included, and could possible include references to other resources such as lambda functions. When the hash was calculated, tokens have been resolved using `StringConcat` which basically converted all tokens to `[Object object]`. This means, for example, that if we changed the reference of an integration lambda to a different handler, the hash would remain the same. There is no apparent reason why we can't simply resolve tokens using the CloudFormation concatenation function during "prepare", which means that if we now reference a different resource, the token will resolve to a different value and deployment will be invalidated. Fixes #4551 Fixes aws-samples/aws-cdk-intro-workshop#83 * fix lint errors * update expectations * add lambda asset * update expectation * update expectations * update decdk tests
1 parent b149b02 commit eac7695

File tree

11 files changed

+1088
-972
lines changed

11 files changed

+1088
-972
lines changed

packages/@aws-cdk/aws-apigateway/lib/deployment.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Construct, DefaultTokenResolver, Lazy, RemovalPolicy, Resource, Stack, StringConcat, Tokenization } from '@aws-cdk/core';
1+
import { Construct, Lazy, RemovalPolicy, Resource, Stack } from '@aws-cdk/core';
22
import crypto = require('crypto');
33
import { CfnDeployment, CfnDeploymentProps } from './apigateway.generated';
44
import { IRestApi } from './restapi';
@@ -121,20 +121,13 @@ class LatestDeploymentResource extends CfnDeployment {
121121
* add via `addToLogicalId`.
122122
*/
123123
protected prepare() {
124+
const stack = Stack.of(this);
125+
124126
// if hash components were added to the deployment, we use them to calculate
125127
// a logical ID for the deployment resource.
126128
if (this.hashComponents.length > 0) {
127129
const md5 = crypto.createHash('md5');
128-
this.hashComponents
129-
.map(c => {
130-
return Tokenization.resolve(c, {
131-
scope: this,
132-
resolver: new DefaultTokenResolver(new StringConcat()),
133-
preparing: true,
134-
});
135-
})
136-
.forEach(c => md5.update(JSON.stringify(c)));
137-
130+
this.hashComponents.map(x => stack.resolve(x)).forEach(c => md5.update(JSON.stringify(c)));
138131
this.overrideLogicalId(this.originalLogicalId + md5.digest("hex"));
139132
}
140133
super.prepare();

packages/@aws-cdk/aws-apigateway/test/integ.cors.expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Name": "cors-api-test"
77
}
88
},
9-
"corsapitestDeployment2BF1633Af56aad239353437f465d2090f2edab0c": {
9+
"corsapitestDeployment2BF1633A197b7a426736ab40a59d8a41c2d3d50d": {
1010
"Type": "AWS::ApiGateway::Deployment",
1111
"Properties": {
1212
"RestApiId": {
@@ -29,7 +29,7 @@
2929
"Ref": "corsapitest8682546E"
3030
},
3131
"DeploymentId": {
32-
"Ref": "corsapitestDeployment2BF1633Af56aad239353437f465d2090f2edab0c"
32+
"Ref": "corsapitestDeployment2BF1633A197b7a426736ab40a59d8a41c2d3d50d"
3333
},
3434
"StageName": "prod"
3535
}

0 commit comments

Comments
 (0)