@@ -84,7 +84,7 @@ const getDomainHostedZoneId = async (route53, domain, privateZone) => {
84
84
const params = {
85
85
DNSName : domain
86
86
} ;
87
-
87
+
88
88
const hostedZonesRes = await route53 . listHostedZonesByName ( params ) . promise ( ) ;
89
89
90
90
const hostedZone = hostedZonesRes . HostedZones . find (
@@ -288,7 +288,7 @@ const configureDnsForCloudFrontDistribution = async (
288
288
domainHostedZoneId ,
289
289
distributionUrl ,
290
290
domainType ,
291
- that
291
+ context
292
292
) => {
293
293
const dnsRecordParams = {
294
294
HostedZoneId : domainHostedZoneId ,
@@ -329,6 +329,11 @@ const configureDnsForCloudFrontDistribution = async (
329
329
} ) ;
330
330
}
331
331
332
+ context . debug (
333
+ "Updating Route53 DNS records with parameters:\n" +
334
+ JSON . stringify ( dnsRecordParams , null , 2 )
335
+ ) ;
336
+
332
337
return route53 . changeResourceRecordSets ( dnsRecordParams ) . promise ( ) ;
333
338
} ;
334
339
@@ -339,7 +344,8 @@ const removeCloudFrontDomainDnsRecords = async (
339
344
route53 ,
340
345
domain ,
341
346
domainHostedZoneId ,
342
- distributionUrl
347
+ distributionUrl ,
348
+ context
343
349
) => {
344
350
const params = {
345
351
HostedZoneId : domainHostedZoneId ,
@@ -364,6 +370,10 @@ const removeCloudFrontDomainDnsRecords = async (
364
370
// TODO: should the CNAME records be removed too?
365
371
366
372
try {
373
+ context . debug (
374
+ "Updating Route53 with parameters:\n" + JSON . stringify ( params , null , 2 )
375
+ ) ;
376
+
367
377
await route53 . changeResourceRecordSets ( params ) . promise ( ) ;
368
378
} catch ( e ) {
369
379
if ( e . code !== "InvalidChangeBatch" ) {
@@ -377,7 +387,8 @@ const addDomainToCloudfrontDistribution = async (
377
387
subdomain ,
378
388
certificateArn ,
379
389
domainType ,
380
- defaultCloudfrontInputs
390
+ defaultCloudfrontInputs ,
391
+ context
381
392
) => {
382
393
// Update logic is a bit weird...
383
394
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudFront.html#updateDistribution-property
@@ -398,21 +409,21 @@ const addDomainToCloudfrontDistribution = async (
398
409
399
410
// 5. then make our changes
400
411
params . DistributionConfig . Aliases . Items . push ( subdomain . domain ) ;
401
- params . DistributionConfig . Aliases . Quantity += 1 ;
402
412
if ( subdomain . domain . startsWith ( "www." ) ) {
403
413
if ( domainType === "apex" ) {
404
- params . DistributionConfig . Aliases . Items [ - 1 ] = `${ subdomain . domain . replace (
405
- "www." ,
406
- ""
407
- ) } `;
414
+ params . DistributionConfig . Aliases . Items [
415
+ params . DistributionConfig . Aliases . Items . length - 1
416
+ ] = `${ subdomain . domain . replace ( "www." , "" ) } ` ;
408
417
} else if ( domainType !== "www" ) {
409
418
params . DistributionConfig . Aliases . Items . push (
410
419
`${ subdomain . domain . replace ( "www." , "" ) } `
411
420
) ;
412
- params . DistributionConfig . Aliases . Quantity += 1 ;
413
421
}
414
422
}
415
423
424
+ params . DistributionConfig . Aliases . Quantity =
425
+ params . DistributionConfig . Aliases . Items . length ;
426
+
416
427
params . DistributionConfig . ViewerCertificate = {
417
428
ACMCertificateArn : certificateArn ,
418
429
SSLSupportMethod : "sni-only" ,
@@ -422,6 +433,11 @@ const addDomainToCloudfrontDistribution = async (
422
433
...defaultCloudfrontInputs . viewerCertificate
423
434
} ;
424
435
436
+ context . debug (
437
+ "Updating CloudFront distribution with parameters:\n" +
438
+ JSON . stringify ( params , null , 2 )
439
+ ) ;
440
+
425
441
// 6. then finally update!
426
442
const res = await cf . updateDistribution ( params ) . promise ( ) ;
427
443
@@ -432,7 +448,11 @@ const addDomainToCloudfrontDistribution = async (
432
448
} ;
433
449
} ;
434
450
435
- const removeDomainFromCloudFrontDistribution = async ( cf , subdomain ) => {
451
+ const removeDomainFromCloudFrontDistribution = async (
452
+ cf ,
453
+ subdomain ,
454
+ context
455
+ ) => {
436
456
const params = await cf
437
457
. getDistributionConfig ( { Id : subdomain . distributionId } )
438
458
. promise ( ) ;
@@ -453,6 +473,11 @@ const removeDomainFromCloudFrontDistribution = async (cf, subdomain) => {
453
473
MinimumProtocolVersion : DEFAULT_MINIMUM_PROTOCOL_VERSION
454
474
} ;
455
475
476
+ context . debug (
477
+ "Updating CloudFront distribution with parameters:\n" +
478
+ JSON . stringify ( params , null , 2 )
479
+ ) ;
480
+
456
481
const res = await cf . updateDistribution ( params ) . promise ( ) ;
457
482
458
483
return {
0 commit comments