Search code examples
amazon-web-servicesamazon-ec2autoscalingaws-code-deploy

Amazon Codedeploy + Elastic Load Balancer - Windows support


Are there any bat scripts (for Windows Server) to handle Elastic Load Balancer when deploying through CodeDeploy? I've found only scripts for linux:

https://github.com/awslabs/aws-codedeploy-samples/tree/master/load-balancing/elb

Unfortunately, they even don't mention in docs about Windows Server support:

http://docs.aws.amazon.com/codedeploy/latest/userguide/elastic-load-balancing-integ.html


Solution

  • The official answer from Amazon linked back to this topic and they said "someone" is using Cygwin and I should try it also...

    Unfortunately, having no other possibility, I've installed Cygwin and in appspec.yml I've put:

    version: 0.0
    os: windows
    files:
      - source: \xxx\
        destination: C:\xxx\
    hooks:
      ApplicationStop:
        - location: \deregister_from_elb.bat
          timeout: 900
    
    <next steps here>
    
      ApplicationStart:
        - location: \register_with_elb.bat
          timeout: 900
    

    In the deregister_from_elb.bat file, I run the .sh file with Cygwin, as follows:

    @echo off
    
    SET mypath=%~dp0
    SET mypath=%mypath:~3%
    
    C:\cygwin64\bin\bash.exe -l -c "'/cygdrive/c/%mypath%deregister_from_elb.sh'"
    

    You can imagine how register_with_elb.bat looks like.

    This solution works in production now, without any major problems for ~6 months.