6

We run our web application on Amazon EC2 with load-balanced, autoscaling web servers (IIS).

Before autoscaling, our deployment process was file-copy to a couple of big web servers.

Now with autoscaling we have anything from 5 to 12 webservers which appear and vanish at will, making the deployment process more difficult.

To address this, I wrote a powershell script that retrieves the IP of servers in an autoscaling group and uses MSDeploy to synchronise them with a designated deployment server (in load balancer, outside of autoscaling group). It then creates a new AMI and updates the autoscaling config.

All seemed to be good, until after rebuilding the deployment server, the sync script does not update the running state of the web sites. So I can put the site into maintenance mode.

I would like to know:

  • how other people approach the problem (specifically syncing iis servers in autoscaling ec2) (in the absence of WFF for IIS 8)

  • why the start/stop sync is failing

Code:

Set-AWSCredentials -AccessKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -SecretKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Set-DefaultAWSRegion "us-west-2"

$date = get-date
$dateString = $date.ToString("yyyyMMdd-HHmm")
$name = $dateString +  "Web"
$imageId = new-ec2image -InstanceId x-xxxxxxxx -Name $name -NoReboot 1

$launchConfiguration = New-ASLaunchConfiguration -LaunchConfigurationName $name -ImageId $imageId -InstanceType "m3.medium" -SecurityGroups @('Web') -InstanceMonitoring_Enabled $false

Update-AsAutoScalingGroup -AutoScalingGroupName "XxxxxxxxxxxxXxxxxxxxxx" -LaunchConfigurationName $name

$a = Get-ASAutoScalingInstance | select -expandproperty InstanceId | Get-EC2Instance | select -expandproperty RunningInstance | select -property PrivateIpAddress

foreach($ip in $a)
{
        $command = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
        $arg = "-dest:webServer,computerName=" + $ip.PrivateIpAddress;
        $args = @('-verb:sync', '-source:webServer', $arg)
        &$command $args
}
Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
sentece
  • 156
  • 1
  • 10

1 Answers1

5

Don't try and "sync" the web servers. Consider doing a one time install - and allowing a tool boot for deploying manage the syncing.

What I've done in the past is used CloudFormation to create the environment, and with a combination of cfn-init and cfn-hup to do the installation. The deployment process then becomes a case of reploying a new package to somewhere like S3, and then using CloudFormation to bump the version.

This triggers a cfn-hup update, whereby each server will pull down the package from S3 and reinstall.

Also - if your scaling group scales, it will automatically use the cfn-init to pull down and install the package completely before registering the instance with the load balancer.

A couple of similar StackOverflow questions here

Also I wrote two articles many moons ago about it

This should give you enough to get going.

Community
  • 1
  • 1
Pete - MSFT
  • 4,249
  • 1
  • 21
  • 38
  • I'm a bit scared now! I will find out what all this means and report back asap. but thank you! – sentece Apr 03 '14 at 20:31
  • The trick is to think about using the starting servers to *pull* the files from a central location (ie - S3). cfn-init is used to bootstrap the server with the necessary components to get started, and also to startup cfn-hup, which will monitor for changes. Once a change is detected, you do a new pull. – Pete - MSFT Apr 04 '14 at 17:53
  • thanks, great answer. I haven't implemented it but next time I do something like this I will. I have worked around my original problems for the mo – sentece Apr 25 '14 at 13:15