Skip to content

Instantly share code, notes, and snippets.

@bboerst
Created June 16, 2016 13:50
Show Gist options
  • Save bboerst/b410dd14f24fea1dc6f0e9cf7ff444e3 to your computer and use it in GitHub Desktop.
Save bboerst/b410dd14f24fea1dc6f0e9cf7ff444e3 to your computer and use it in GitHub Desktop.
Powershell script that could be included within a CI solution that waits for an ElasticBeanstalk deployment to complete and alerts if there are errors.
$applicationname = "ElasticBeanstalkApplicationName"
$environmentname = "EnivornmetName-staging"
$region = "us-west-2"
$delayseconds = 15
$timeoutminutes = 30
$successfulmessage = "Environment update completed successfully."
$scriptstart = Get-Date
do
{
$events = Get-EBEvent -ApplicationName $applicationname -EnvironmentName $environmentname -StartTime $scriptstart.ToString() -Region $region
if($events -ne $null `
-and ($events.Severity -eq "ERROR" `
-or $events.Message.ToLower().Contains("failed") `
-or $events.Message.ToLower().Contains("unsuccessful") `
-or $events.Message.ToLower().Contains("error")))
{
Write-Output("Failure found! Failing the build. Elastic Beanstalk events for this build:")
Write-Output($events)
Exit 1
}
Write-Output("Waiting {0} seconds for Elastic Beanstalk to complete." -f $delayseconds)
Start-Sleep -s $delayseconds
} until ((Get-EBEvent -ApplicationName $applicationname -EnvironmentName $environmentname -StartTime $scriptstart.ToString() -Region $region) -ne $null `
-and (Get-EBEvent -ApplicationName $applicationname -EnvironmentName $environmentname -StartTime $scriptstart.ToString() -Region $region).Message.Contains($successfulmessage) `
-or ($scriptstart -gt $scriptstart.AddMinutes($timeoutminutes)))
Exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment