@@ -61,8 +61,6 @@ export interface DescribeInstancesResultRegion {
61
61
describeInstanceResult : PromiseResult < EC2 . Types . DescribeInstancesResult , AWS . AWSError > ;
62
62
}
63
63
64
- const SHOULD_NOT_TRY_LIST_SSM = 'SHOULD_NOT_TRY_LIST_SSM' ;
65
-
66
64
// Keep the cache as long as half of minimum time, this should reduce calls to AWS API
67
65
const ssmParametersCache = new LRU ( { maxAge : ( Config . Instance . minimumRunningTimeInMinutes * 60 * 1000 ) / 2 } ) ;
68
66
@@ -357,7 +355,6 @@ export async function terminateRunners(runners: RunnerInfo[], metrics: Metrics):
357
355
358
356
async function terminateRunnersInRegion ( runners : RunnerInfo [ ] , metrics : Metrics , region : string ) : Promise < void > {
359
357
const ec2 = new EC2 ( { region } ) ;
360
- const ssm = new SSM ( { region } ) ;
361
358
362
359
// Keep track of runners that were successfully terminated so we can clean up their SSM parameters even
363
360
// if a later batch fails.
@@ -411,87 +408,6 @@ async function terminateRunnersInRegion(runners: RunnerInfo[], metrics: Metrics,
411
408
}
412
409
}
413
410
414
- async function cleanupSSMParametersForRunners (
415
- runners : RunnerInfo [ ] ,
416
- metrics : Metrics ,
417
- region : string ,
418
- ssm : SSM ,
419
- ) : Promise < void > {
420
- const paramNames = runners . map ( ( runner ) =>
421
- getParameterNameForRunner ( runner . environment || Config . Instance . environment , runner . instanceId ) ,
422
- ) ;
423
-
424
- const cacheName = `${ SHOULD_NOT_TRY_LIST_SSM } _${ region } ` ;
425
-
426
- if ( ssmParametersCache . has ( cacheName ) ) {
427
- // If we've had recent failures listing parameters, just try to delete them directly
428
- await deleteSSMParametersInBatches ( paramNames , metrics , region , ssm ) ;
429
- } else {
430
- try {
431
- const existingParams = await listSSMParameters ( metrics , region ) ;
432
- const paramsToDelete = paramNames . filter ( ( paramName ) => existingParams . has ( paramName ) ) ;
433
-
434
- if ( paramsToDelete . length > 0 ) {
435
- await deleteSSMParametersInBatches ( paramsToDelete , metrics , region , ssm ) ;
436
- } else {
437
- console . info ( `[${ region } ] No SSM parameters found to delete for ${ paramNames . length } runners` ) ;
438
- }
439
- } catch ( e ) {
440
- ssmParametersCache . set ( cacheName , 1 , 60 * 1000 ) ;
441
- console . error (
442
- `[terminateRunnersInRegion - listSSMParameters] [${ region } ] ` +
443
- `Failed to list parameters, attempting direct deletion: ${ e } ` ,
444
- ) ;
445
- await deleteSSMParametersInBatches ( paramNames , metrics , region , ssm ) ;
446
- }
447
- }
448
- }
449
-
450
- async function deleteSSMParametersInBatches (
451
- paramNames : string [ ] ,
452
- metrics : Metrics ,
453
- region : string ,
454
- ssm : SSM ,
455
- ) : Promise < void > {
456
- const batches = chunkArray ( paramNames , 10 ) ;
457
-
458
- console . info ( `[${ region } ] Processing ${ paramNames . length } SSM parameters in ${ batches . length } batch(es)` ) ;
459
-
460
- for ( const [ batchIndex , batch ] of batches . entries ( ) ) {
461
- console . info (
462
- `[${ region } ] Processing SSM batch ${ batchIndex + 1 } /${ batches . length } with ${
463
- batch . length
464
- } parameters: ${ batch . join ( ', ' ) } `,
465
- ) ;
466
-
467
- try {
468
- await Promise . all (
469
- batch . map ( ( paramName ) =>
470
- expBackOff ( ( ) => {
471
- return metrics . trackRequestRegion (
472
- region ,
473
- metrics . ssmdeleteParameterAWSCallSuccess ,
474
- metrics . ssmdeleteParameterAWSCallFailure ,
475
- ( ) => {
476
- return ssm . deleteParameter ( { Name : paramName } ) . promise ( ) ;
477
- } ,
478
- ) ;
479
- } ) ,
480
- ) ,
481
- ) ;
482
-
483
- console . info (
484
- `[${ region } ] Successfully deleted SSM batch ${ batchIndex + 1 } /${ batches . length } : ${ batch . join ( ', ' ) } ` ,
485
- ) ;
486
- } catch ( e ) {
487
- console . error (
488
- `[${ region } ] Failed to delete SSM batch ${ batchIndex + 1 } /${ batches . length } : ${ batch . join ( ', ' ) } - ${ e } ` ,
489
- ) ;
490
- // Continue with other batches even if one fails
491
- }
492
- }
493
- }
494
-
495
411
function chunkArray < T > ( array : T [ ] , chunkSize : number ) : T [ ] [ ] {
496
412
const chunks : T [ ] [ ] = [ ] ;
497
413
for ( let i = 0 ; i < array . length ; i += chunkSize ) {
@@ -537,13 +453,15 @@ async function addSSMParameterRunnerConfig(
537
453
// NOTE: This does need to be a string, check docs at:
538
454
// https://docs.aws.amazon.com/systems-manager/latest/userguide/example_ssm_PutParameter_section.html
539
455
// Policies must be an array, even for a single policy
540
- Policies : JSON . stringify ( [ {
541
- Type : 'Expiration' ,
542
- Version : '1.0' ,
543
- Attributes : {
544
- Timestamp : new Date ( Date . now ( ) + 30 * 60 * 1000 ) . toISOString ( ) ,
456
+ Policies : JSON . stringify ( [
457
+ {
458
+ Type : 'Expiration' ,
459
+ Version : '1.0' ,
460
+ Attributes : {
461
+ Timestamp : new Date ( Date . now ( ) + 30 * 60 * 1000 ) . toISOString ( ) ,
462
+ } ,
545
463
} ,
546
- } ] ) ,
464
+ ] ) ,
547
465
} )
548
466
. promise ( ) ;
549
467
return parameterName ;
0 commit comments