75 lines
2.5 KiB
PowerShell
75 lines
2.5 KiB
PowerShell
function Invoke-MinimizeDesignation {
|
|
<#
|
|
.SYNOPSIS
|
|
This wraps the APIGateway/Lambda for scaling environments. Scales the environment down to a 1x1x1.
|
|
|
|
.DESCRIPTION
|
|
Sends shutdown commands to EC2 instances where the alk:designation tag value = parameter Designation, keeping 1 each of App, Mic and Web running. 1x1x1.
|
|
|
|
.PARAMETER Fqdn
|
|
Fully Qualified Domain Name of the API Gateway. Each environment/account has a unique API Gateway endpoint.
|
|
|
|
.PARAMETER Designation
|
|
alk:designation tag to filter which instances to query. Case sensitive.
|
|
|
|
.PARAMETER ApiGatewayKey
|
|
Unique key for authenticating to the API Gateway.
|
|
|
|
.PARAMETER IsTest
|
|
Switch to determine if it should actually send the commands to the EC2 instances, or just report back what it will do, without actually sending instance commands.
|
|
|
|
.PARAMETER ExclusionListCSV
|
|
Comma-seperated list of alk:hostname strings to exclude from the shutdown command. Case sensitive.
|
|
|
|
.EXAMPLE
|
|
Invoke-MinimizeDesignation -fqdn "vyq7hqcx55.execute-api.us-east-1.amazonaws.com" -designation "ci1" -apiGatewayKey "123456789" -isTest $true -exclusionList "app2778144"
|
|
|
|
returns JSON:
|
|
[
|
|
{
|
|
"IsExcluded": false,
|
|
"IsApp": false,
|
|
"IsMic": false,
|
|
"IsWeb": true,
|
|
"IsRunning": false,
|
|
"IsStopped": true,
|
|
"InstanceId": "i-0fa21749b4e4b81ea",
|
|
"Designation": "ci1",
|
|
"HostName": "web27425",
|
|
"Environment": "dev",
|
|
"Service": "orb"
|
|
}
|
|
]
|
|
|
|
.NOTES
|
|
Dev FQDN : vyq7hqcx55.execute-api.us-east-1.amazonaws.com
|
|
Staging FQDN : cox3133b67.execute-api.us-east-1.amazonaws.com
|
|
Qa FQDN :
|
|
#>
|
|
[CmdletBinding()]
|
|
|
|
Param (
|
|
[Parameter(Mandatory = $true)]
|
|
[string] $Fqdn,
|
|
[Parameter(Mandatory = $true)]
|
|
[string] $Designation,
|
|
[Parameter(Mandatory = $true)]
|
|
[string] $ApiGatewayKey,
|
|
[Parameter(Mandatory = $true)]
|
|
[string] $IsTest,
|
|
[Parameter(Mandatory = $false)]
|
|
[AllowEmptyString()]
|
|
[string] $ExclusionListCSV
|
|
)
|
|
|
|
[System.Net.ServicePointManager]::SecurityProtocol = "Tls12"
|
|
|
|
$ExclusionListCSV = $ExclusionListCSV.Replace(',', '","')
|
|
|
|
|
|
$jsonBody = '{"Designation":"' + $Designation + '","ExclusionList":["' + $ExclusionListCSV + '"],"IsTest":"' + $IsTest + '"}'
|
|
#Write-Host "Calling Invoke-MinimizeEnvironment with: $jsonBody"
|
|
$response = Invoke-RestMethod -Uri "https://$Fqdn/Prod/MinimizeDesignation" -Headers @{"x-api-key" = $ApiGatewayKey} -Method POST -body $jsonBody -ContentType "application/json"
|
|
|
|
return $response
|
|
} |