You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(custom-resources): add update and delete action for app runner alias (#2589)
This PR implements the "Delete" action for the custom resource.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
// Expectedly lambda time out would be triggered before 20-th attempt. This ensures that we attempts to wait for it to be disassociated as much as possible.
updateCNAMERecordAndWait(customDomainName,data.DNSTarget,appHostedZoneID,"UPSERT"),// Upsert the record that maps `customDomainName` to the DNS of the app runner service.
thrownewError(`wait for domain ${customDomainName} to be active: `+err.message);
166
-
});
167
-
168
-
letdomain;
169
-
for(constdofdata.CustomDomains){
170
-
if(d.DomainName===customDomainName){
171
-
domain=d;
172
-
break;
173
-
}
174
-
}
175
-
176
-
if(!domain){
177
-
thrownewError(`wait for domain ${customDomainName} to be active: domain ${customDomainName} is not associated`);
178
-
}
179
-
180
-
if(domain.Status!==DOMAIN_STATUS_ACTIVE){
181
-
// Exponential backoff with jitter based on 200ms base
182
-
// component of backoff fixed to ensure minimum total wait time on
183
-
// slow targets.
184
-
constbase=Math.pow(2,i);
185
-
awaitsleep(Math.random()*base*50+base*150);
186
-
continue;
146
+
}).promise();
147
+
}catch(err){
148
+
constisDomainAlreadyAssociated=err.message.includes(`${customDomainName} is already associated with`);
149
+
if(!isDomainAlreadyAssociated){
150
+
throwerr;
187
151
}
188
-
return;
189
152
}
190
153
191
-
if(i===ATTEMPTS_WAIT_FOR_ACTIVE){
192
-
console.log("Fail to wait for the domain status to become ACTIVE. It usually takes a long time to validate domain and can be longer than the 15 minutes duration for which a Lambda function can run at most. Try associating the domain manually.");
193
-
thrownewError(`fail to wait for domain ${customDomainName} to become ${DOMAIN_STATUS_ACTIVE}`);
154
+
if(!data){
155
+
// If domain is already associated, data would be undefined.
156
+
data=awaitappRunnerClient.describeCustomDomains({
157
+
ServiceArn: serviceARN,
158
+
}).promise();
194
159
}
160
+
161
+
returnPromise.all([
162
+
updateCNAMERecordAndWait(customDomainName,data.DNSTarget,appHostedZoneID,"UPSERT"),// Upsert the record that maps `customDomainName` to the DNS of the app runner service.
thrownewError(`update validation records for domain ${domainName}: `+err.message);
221
+
})
222
+
);
247
223
}
248
-
break;
224
+
returnPromise.all(promises);
249
225
}
250
226
251
227
if(i===ATTEMPTS_WAIT_FOR_PENDING){
252
228
thrownewError(`update validation records for domain ${domainName}: fail to wait for state ${DOMAIN_STATUS_PENDING_VERIFICATION}, stuck in ${lastDomainStatus}`);
253
229
}
254
230
}
255
231
232
+
/**
233
+
* There are one known scenarios where status could be ACTIVE right after it's associated:
234
+
* When the domain just got deleted and added again. In this case, even though the validation records could
235
+
* have been deleted, the previously successful validation results are still cached. Because of the cache,
236
+
* the domain will show to be ACTIVE immediately after it's associated , although the validation records are not
237
+
* there anymore.
238
+
* In this case, the status won't transit to PENDING_VERIFICATION, so we need to check whether the validation
239
+
* records are ready by counting if there are three of them.
if(err.message.includes(`No custom domain ${customDomainName} found for the provided service`)){
273
+
return;
274
+
}
275
+
throwerr;
276
+
}
277
+
278
+
returnPromise.all([
279
+
updateCNAMERecordAndWait(customDomainName,data.DNSTarget,appHostedZoneID,"DELETE"),// Delete the record that maps `customDomainName` to the DNS of the app runner service.
280
+
removeValidationRecords(data.CustomDomain),
281
+
]);
282
+
}
283
+
284
+
/**
285
+
* Remove validation records for a custom domain.
286
+
*
287
+
* @param {object} domain information containing DomainName, Status, CertificateValidationRecords, etc.
0 commit comments