James McCool commited on
Commit
7f942a8
·
1 Parent(s): ef06cec

Update score cutoff in chunk_name_matching function and add PowerShell scripts for instance management

Browse files
Files changed (3) hide show
  1. app.py +1 -1
  2. get-ips.ps1 +15 -0
  3. scale-instances.ps1 +51 -0
app.py CHANGED
@@ -117,7 +117,7 @@ def chunk_name_matching(portfolio_names, csv_names, chunk_size=1000):
117
  match = process.extractOne(
118
  portfolio_name,
119
  csv_names,
120
- score_cutoff=87
121
  )
122
  if match:
123
  portfolio_match_dict[portfolio_name] = match[0]
 
117
  match = process.extractOne(
118
  portfolio_name,
119
  csv_names,
120
+ score_cutoff=90
121
  )
122
  if match:
123
  portfolio_match_dict[portfolio_name] = match[0]
get-ips.ps1 ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Get instance IPs from Auto Scaling Group
2
+ $instanceIds = aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names portfolio-manager-asg --query 'AutoScalingGroups[0].Instances[?HealthStatus==`Healthy`].InstanceId' --output text
3
+
4
+ if (-not $instanceIds) { exit 1 }
5
+
6
+ $instanceIdArray = $instanceIds -split "`t"
7
+ $global:instances = @()
8
+ foreach ($id in $instanceIdArray) {
9
+ $ip = aws ec2 describe-instances --instance-ids $id --query 'Reservations[0].Instances[0].PublicIpAddress' --output text
10
+ if ($ip -and $ip -ne "None") {
11
+ $global:instances += $ip
12
+ }
13
+ }
14
+
15
+ $global:instances
scale-instances.ps1 ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ param(
2
+ [Parameter(Mandatory=$true)]
3
+ [string]$InstanceType
4
+ )
5
+
6
+ # Validate instance type format
7
+ if ($InstanceType -notmatch '^[a-z][0-9]+\.[a-z]+$') {
8
+ Write-Error "Invalid instance type format. Use format like: m5.large, m5.xlarge, c5.2xlarge"
9
+ exit 1
10
+ }
11
+
12
+ Write-Host "Scaling portfolio-manager instances to $InstanceType..." -ForegroundColor Green
13
+
14
+ # Step 1: Create new launch template version
15
+ Write-Host "Creating new launch template version..." -ForegroundColor Yellow
16
+ $templateResult = aws ec2 create-launch-template-version --launch-template-name portfolio-manager-template --source-version 1 --launch-template-data "{`"InstanceType`":`"$InstanceType`"}" --version-description "Scaled to $InstanceType" --output json | ConvertFrom-Json
17
+
18
+ if ($LASTEXITCODE -ne 0) {
19
+ Write-Error "Failed to create launch template version"
20
+ exit 1
21
+ }
22
+
23
+ $newVersion = $templateResult.LaunchTemplateVersion.VersionNumber
24
+ Write-Host "Created launch template version $newVersion" -ForegroundColor Green
25
+
26
+ # Step 2: Update Auto Scaling Group
27
+ Write-Host "Updating Auto Scaling Group..." -ForegroundColor Yellow
28
+ aws autoscaling update-auto-scaling-group --auto-scaling-group-name portfolio-manager-asg --launch-template LaunchTemplateName=portfolio-manager-template,Version='$Latest'
29
+
30
+ if ($LASTEXITCODE -ne 0) {
31
+ Write-Error "Failed to update Auto Scaling Group"
32
+ exit 1
33
+ }
34
+
35
+ Write-Host "Auto Scaling Group updated" -ForegroundColor Green
36
+
37
+ # Step 3: Start instance refresh
38
+ Write-Host "Starting instance refresh..." -ForegroundColor Yellow
39
+ $refreshResult = aws autoscaling start-instance-refresh --auto-scaling-group-name portfolio-manager-asg --preferences '{\"InstanceWarmup\":300,\"MinHealthyPercentage\":50}' --output json | ConvertFrom-Json
40
+
41
+ if ($LASTEXITCODE -ne 0) {
42
+ Write-Error "Failed to start instance refresh"
43
+ exit 1
44
+ }
45
+
46
+ $refreshId = $refreshResult.InstanceRefreshId
47
+ Write-Host "Instance refresh started with ID: $refreshId" -ForegroundColor Green
48
+
49
+ Write-Host "`nScaling process initiated successfully!" -ForegroundColor Green
50
+ Write-Host "Monitor progress with: aws autoscaling describe-instance-refreshes --auto-scaling-group-name portfolio-manager-asg --instance-refresh-ids $refreshId" -ForegroundColor Cyan
51
+ Write-Host "This process will take 5-10 minutes to complete." -ForegroundColor Yellow