Skip to content

Commit

Permalink
Release SSH keys sequentially
Browse files Browse the repository at this point in the history
When you hit the 5k key limit, starting 5k threads is ok for Java,
but not ok for AWS. We get immediately throttled.
It's actually faster to do it sequentially. And AWS is quick to delete.
  • Loading branch information
dagguh committed Jan 4, 2024
1 parent 970680d commit d639f45
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ class ConcurrentHousekeeping(
val amis = Ec2(aws.ec2).listExpiredAmis()
waitUntilReleased(amis, amiTimeout)

val keys = aws.ec2.describeKeyPairs().keyPairs.map { key ->
RemoteSshKey(SshKeyName(key.keyName), aws.ec2)
}.filter { it.isExpired() }
aws.ec2.describeKeyPairs().keyPairs
.map { key -> RemoteSshKey(SshKeyName(key.keyName), aws.ec2) }
.filter { it.isExpired() }
.forEach { it.release().get() }

val securityGroups = aws.ec2.describeSecurityGroups().securityGroups.map { securityGroup ->
Ec2SecurityGroup(securityGroup, aws.ec2)
}.filter { it.isExpired() }

waitUntilReleased(keys)
waitUntilReleased(securityGroups)

Cloudformation(aws, aws.cloudformation).consumeExpiredStacks(Consumer { stacks ->
Expand Down

0 comments on commit d639f45

Please sign in to comment.