-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from guardian/update-scale-in-protection
Add/remove scale in protection for worker instances
- Loading branch information
Showing
8 changed files
with
555 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
AutoScalingClient, | ||
SetInstanceProtectionCommand, | ||
} from '@aws-sdk/client-auto-scaling'; | ||
import { readFile } from './util'; | ||
|
||
export const updateScaleInProtection = async ( | ||
region: string, | ||
stage: string, | ||
value: boolean, | ||
) => { | ||
const clientConfig = { | ||
region, | ||
}; | ||
try { | ||
if (stage !== 'DEV') { | ||
const instanceId = readFile('/var/lib/cloud/data/instance-id'); | ||
console.log(`instanceId: ${instanceId}`); | ||
const autoScalingClient = new AutoScalingClient(clientConfig); | ||
const input = { | ||
InstanceIds: [instanceId.trim()], | ||
AutoScalingGroupName: `transcription-service-workers-${stage}`, | ||
ProtectedFromScaleIn: value, | ||
}; | ||
const command = new SetInstanceProtectionCommand(input); | ||
await autoScalingClient.send(command); | ||
console.log( | ||
`Updated scale-in protection to value ${value} for instance ${instanceId}`, | ||
); | ||
} | ||
} catch (error) { | ||
console.log(`Could not remove scale-in protection`, error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as fs from 'fs'; | ||
|
||
export const readFile = (filePath: string): string => { | ||
const file = fs.readFileSync(filePath, 'utf8'); | ||
return file; | ||
}; |