@@ -123,7 +123,7 @@ interface LatestDeploymentResourceProps {
123
123
124
124
class LatestDeploymentResource extends CfnDeployment {
125
125
private hashComponents = new Array < any > ( ) ;
126
- private originalLogicalId : string ;
126
+
127
127
private api : IRestApi ;
128
128
129
129
constructor ( scope : Construct , id : string , props : LatestDeploymentResourceProps ) {
@@ -133,7 +133,31 @@ class LatestDeploymentResource extends CfnDeployment {
133
133
} ) ;
134
134
135
135
this . api = props . restApi ;
136
- this . originalLogicalId = Stack . of ( this ) . getLogicalId ( this ) ;
136
+
137
+ const originalLogicalId = Stack . of ( this ) . getLogicalId ( this ) ;
138
+
139
+ this . overrideLogicalId ( Lazy . stringValue ( { produce : ctx => {
140
+ const hash = [ ...this . hashComponents ] ;
141
+
142
+ if ( this . api instanceof RestApi || this . api instanceof SpecRestApi ) { // Ignore IRestApi that are imported
143
+
144
+ // Add CfnRestApi to the logical id so a new deployment is triggered when any of its properties change.
145
+ const cfnRestApiCF = ( this . api . node . defaultChild as any ) . _toCloudFormation ( ) ;
146
+ hash . push ( ctx . resolve ( cfnRestApiCF ) ) ;
147
+ }
148
+
149
+ let lid = originalLogicalId ;
150
+
151
+ // if hash components were added to the deployment, we use them to calculate
152
+ // a logical ID for the deployment resource.
153
+ if ( hash . length > 0 ) {
154
+ const md5 = crypto . createHash ( 'md5' ) ;
155
+ hash . map ( x => ctx . resolve ( x ) ) . forEach ( c => md5 . update ( JSON . stringify ( c ) ) ) ;
156
+ lid += md5 . digest ( 'hex' ) ;
157
+ }
158
+
159
+ return lid ;
160
+ } } ) ) ;
137
161
}
138
162
139
163
/**
@@ -149,28 +173,4 @@ class LatestDeploymentResource extends CfnDeployment {
149
173
150
174
this . hashComponents . push ( data ) ;
151
175
}
152
-
153
- /**
154
- * Hooks into synthesis to calculate a logical ID that hashes all the components
155
- * add via `addToLogicalId`.
156
- */
157
- protected prepare ( ) {
158
- if ( this . api instanceof RestApi || this . api instanceof SpecRestApi ) { // Ignore IRestApi that are imported
159
-
160
- // Add CfnRestApi to the logical id so a new deployment is triggered when any of its properties change.
161
- const cfnRestApiCF = ( this . api . node . defaultChild as any ) . _toCloudFormation ( ) ;
162
- this . addToLogicalId ( Stack . of ( this ) . resolve ( cfnRestApiCF ) ) ;
163
- }
164
-
165
- const stack = Stack . of ( this ) ;
166
-
167
- // if hash components were added to the deployment, we use them to calculate
168
- // a logical ID for the deployment resource.
169
- if ( this . hashComponents . length > 0 ) {
170
- const md5 = crypto . createHash ( 'md5' ) ;
171
- this . hashComponents . map ( x => stack . resolve ( x ) ) . forEach ( c => md5 . update ( JSON . stringify ( c ) ) ) ;
172
- this . overrideLogicalId ( this . originalLogicalId + md5 . digest ( 'hex' ) ) ;
173
- }
174
- super . prepare ( ) ;
175
- }
176
176
}
0 commit comments