function Invoke-StopServers { <# .SYNOPSIS This wraps the APIGateway/Lambda for scaling environments. Helper for the MinimizeDesignation/MaximizeDesignation functions. .DESCRIPTION Sends Shutdown command to all EC2 instances where the alk:hostname tag value = parameter HostnamesCSV. .PARAMETER Fqdn Fully Qualified Domain Name of the API Gateway. Each environment/account has a unique API Gateway endpoint. .PARAMETER HostnamesCSV alk:hostname tag to filter which instances to stop. Comma-seperated list. Case sensitive. .PARAMETER ApiGatewayKey Unique key for authenticating to the API Gateway. .EXAMPLE Invoke-StartServers -fqdn "vyq7hqcx55.execute-api.us-east-1.amazonaws.com" -hostnamesCsv "web27425" -apiGatewayKey "123456789" 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] $ApiGatewayKey, [Parameter(Mandatory = $true)] [string] $HostnamesCSV ) [System.Net.ServicePointManager]::SecurityProtocol = "Tls12" $HostnamesCSV = $HostnamesCSV.Replace(',', '","') $jsonBody = '{"Hostnames":["' + $HostnamesCSV + '"]}' $response = Invoke-RestMethod -Uri "https://$Fqdn/Prod/StopServers" -Headers @{"x-api-key"="$ApiGatewayKey"} -Method POST -body $jsonBody -ContentType "application/json" return $response }