59 lines
2.0 KiB
PowerShell
59 lines
2.0 KiB
PowerShell
|
function Invoke-StopEnvironment {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
This wraps the APIGateway/Lambda for scaling environments. Stops all instances by environment name, eg. Dev,Qa,Staging.
|
|||
|
|
|||
|
.DESCRIPTION
|
|||
|
Will stop all instances by environment name except those that are configured to not be stopped.
|
|||
|
|
|||
|
.PARAMETER Fqdn
|
|||
|
Fully Qualified Domain Name of the API Gateway. Each environment/account has a unique API Gateway endpoint.
|
|||
|
|
|||
|
.PARAMETER EnvironmentName
|
|||
|
Environment name to get instances by. Examples are 'dev','staging','qa'. Case sensitive.
|
|||
|
|
|||
|
.PARAMETER ApiGatewayKey
|
|||
|
Unique key for authenticating to the API Gateway.
|
|||
|
|
|||
|
.EXAMPLE
|
|||
|
Invoke-StopEnvironment -fqdn "vyq7hqcx55.execute-api.us-east-1.amazonaws.com" -environmentName "dev" -apiGatewayKey "123456789"
|
|||
|
|
|||
|
returns JSON:
|
|||
|
[
|
|||
|
{
|
|||
|
"IsExcluded": false,
|
|||
|
"IsApp": false,
|
|||
|
"IsMic": false,
|
|||
|
"IsWeb": true,
|
|||
|
"IsRunning": true,
|
|||
|
"IsStopped": false,
|
|||
|
"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] $EnvironmentName,
|
|||
|
[Parameter(Mandatory = $true)]
|
|||
|
[string] $ApiGatewayKey
|
|||
|
)
|
|||
|
|
|||
|
[System.Net.ServicePointManager]::SecurityProtocol = "Tls12"
|
|||
|
|
|||
|
$jsonBody = '{"EnvironmentType":"' + $EnvironmentName + '"}'
|
|||
|
$response = Invoke-RestMethod -Uri "https://$Fqdn/Prod/StopEnvironment" -Headers @{"x-api-key"="$ApiGatewayKey"} -Method POST -body $jsonBody -ContentType "application/json"
|
|||
|
|
|||
|
return $response
|
|||
|
}
|