tomislav_t
tomislav_t

Reputation: 527

How to get a postInstall PowerShell script working on an AWS Beanstalk Windows instance

I am trying to execute a PowerShell script after deployment to an AWS Beanstalk Windows IIS instance. For this, I have written a aws-windows-deployment-manifest.json file as follows:

{
  "manifestVersion": 1,
  "iisConfig": {
    "appPools": [
      {
        "name": "AppPoolName",
        "recycling": {
          "regularTimeInterval": 10
        }
      }
    ]
  },
  "deployments": {
    "msDeploy": [
      {
        "name": "app",
        "parameters": {
          "appBundle": "App.zip",
          "iisPath": "/",
          "iisWebSite": "Default Web Site",
          "appPool": "AppPoolName"
        },
        "scripts": {
          "postInstall": {
            "file": "PostInstallSetup.ps1"
          }
        }
      }
    ]
  }
}

My PostInstallSetup.ps1 script is super-simple, it contains just:

"Hello, World!"

Still, it does not work. In the log file of the deployment I get messages like these:

Info: Adding file (Default Web Site/Web.config).
---------- Executing command "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -NonInteractive -NoProfile -Command  "& { & \"C:\Staging\PostInstallSetup.ps1\"; exit $LastExitCode }" " ----------
Info: Adding file (Default Web Site/Readme.txt).
Error during deployment: The directory name is invalid
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at AWS.DeploymentCommands.Utilities.ExecuteCommand(String cwd, String command, String arguments, ILogger logger, Boolean throwOnError) in D:\Jenkins\jobs\aws.deploytools-build\workspace\src\AWS.DeploymentCommands\Utilities.cs:line 181
   at AWS.DeploymentCommands.Utilities.ExecutePowerShellScript(String cwd, String script, ILogger logger) in D:\Jenkins\jobs\aws.deploytools-build\workspace\src\AWS.DeploymentCommands\Utilities.cs:line 107
   at AWS.DeploymentCommands.Commands.BaseScriptableCommand.ExecuteScript(ScriptDeclaration script, String cwd) in D:\Jenkins\jobs\aws.deploytools-build\workspace\src\AWS.DeploymentCommands\Commands\BaseScriptableCommand.cs:line 84
   at AWS.DeploymentCommands.Commands.DeployMSDeployPackages.DoInstall() in D:\Jenkins\jobs\aws.deploytools-build\workspace\src\AWS.DeploymentCommands\Commands\DeployMSDeployPackages.cs:line 105
Info: Adding file (Default Web Site/WebC.Web.config).
---------- Executing command "C:\Windows\system32\iisreset.exe /start" ----------

The end result is that the deployment has completed, the web app is working, but the PostInstallSetup.ps1 script has not been executed.

Do I have an error in the manifest file? Or do I need to place the PostInstallSetup.ps1 script somewhere else?

I have reduced the PostInstallSetup.ps1 script to "Hello World" just to rule out that issues in the script are breaking the deploy.

Upvotes: 0

Views: 878

Answers (1)

tomislav_t
tomislav_t

Reputation: 527

It turned out that the scripts / postInstall method does not work well in combination with msDeploy. It did work with the .NET Core type deploy, so as a workaround I added a dummy .NET Core package placed my postInstall code in there.

Upvotes: 2

Related Questions