AWS CodeDeploy Powershell Script fail to create website & Pool in IIS server

4

I have an app that I am deploying using AWS Codedeploy to an EC2 instance running Windows Server 2012 R2 with code deploy agent installed.

The code revision was successfully downloaded from S3 bucket to EC2 instance but PowerShell script throws error.

Just to inform, when executing the script in EC2 instance manually it is running successfully.

Here are the my appspec.yml & before-install.bat

  • appspec.yml

    version: 0.0 os: windows files: - source: \index.html destination: C:\DemoApp\MySite hooks: BeforeInstall: - location: \before-install.bat timeout: 900

  • before-install.bat

    C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Command "& {Import-Module WebAdministration; New-Item iis:\Sites\MySite -bindings @{protocol=\"http\";bindingInformation=\":80:\"} -physicalPath c:\DemoApp\MySite; New-Item IIS:\AppPools\MyPool; Set-ItemProperty IIS:\Sites\MySite -name applicationPool -value MyPool;}"

codedeploy-agent-deployments.log

Script - \before-install.bat C:\Windows\system32>C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Command "& {Set-ExecutionPolicy Unrestricted; Import-Module WebAdministration; New-Item iis:\Sites\MySite -bindings @{protocol=\"http\";bindingInformation=\":80:\"} -physicalPath c:\DemoApp\MySite; New-Item IIS:\AppPools\MyPool; Set-ItemProperty IIS:\Sites\MySite -name applicationPool -value MyPool;}" New-Item : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). At line:1 char:71 + & {Set-ExecutionPolicy Unrestricted; Import-Module WebAdministration; New-Item i ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : InvalidArgument: (:) [New-Item], ParameterBindin gException + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShe ll.Commands.NewItemCommand

powershell
amazon-web-services
iis
windows-server-2012-r2
aws-code-deploy
asked on Stack Overflow May 8, 2017 by Neel Shah

1 Answer

5

Try this script:

if ($PSHOME -like "*SysWOW64*")
{
  Write-Warning "Restarting this script under 64-bit Windows PowerShell."

  & (Join-Path ($PSHOME -replace "SysWOW64", "SysNative") powershell.exe) -File `
    (Join-Path $PSScriptRoot $MyInvocation.MyCommand) @args

  Exit $LastExitCode
}

Import-Module WebAdministration; 
New-Item IIS:\AppPools\MyPool;
New-Item iis:\Sites\MySite -bindings @{protocol='http';bindingInformation=':80:'} -physicalPath c:\DemoApp\MySite;
Set-ItemProperty IIS:\Sites\MySite -name applicationPool -value MyPool

Refer to http://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-deployments.html.

answered on Stack Overflow May 9, 2017 by Parth Kantaria • edited Oct 28, 2019 by Ben Smith

User contributions licensed under CC BY-SA 3.0