Question:
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
Answer:
Try this script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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.