Home > Enterprise >  Azure DevOps deploying .NET 6 app to AWS Elastic Beanstalk throwing "Command hooks failed"
Azure DevOps deploying .NET 6 app to AWS Elastic Beanstalk throwing "Command hooks failed"

Time:12-06

My prior Azure DevOps Pipeline quit working with dotnet 6 deployment to AWS Elastic Beanstalk.

I have found this guide --> https://docs.aws.amazon.com/vsts/latest/userguide/tutorial-eb.html

Following these steps which use msbuild instead of dotnet build seem to work but deployment to elastic beanstalk fails with a new error I have not seen before: Error occurred during build: Command hooks failed

YAML for the deployment tasks looks like this...

  - task: NuGetToolInstaller@1
    displayName: Use NuGet 5.x
    inputs:
      versionSpec: 5.x
      checkLatest: true
  - task: NuGetCommand@2
    displayName: NuGet restore
    inputs:
      noCache: true
  - task: VSBuild@1
    displayName: Build Project
    inputs:
      solution: AppName/AppName/AppName.csproj
      msbuildArgs: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp_$(build.BuildId).zip" /p:DeployIisAppPath="Default Web Site"
      platform: x64
      configuration: release
      clean: true
      msbuildArchitecture: x64
  - task: BeanstalkDeployApplication@1
    displayName: 'Deploy to Elastic Beanstalk: AppName'
    inputs:
      awsCredentials: 63ff2436-14ff-4391-836c-c14f27af9473
      regionName: us-east-1
      applicationName: AppName
      environmentName: appname-dev
      webDeploymentArchive: $(build.artifactstagingdirectory)\WebApp_$(build.BuildId).zip
      dotnetPublishPath: $(build.artifactstagingdirectory)\WebApp_$(build.BuildId).zip
      versionLabel: 'Azure DevOps Build Id: $(build.buildid)'
      description: $(Build.SourceVersionMessage)

i'm using the following...

Azure DevOps
Elastic Beanstalk: IIS 10.0 running on 64bit Windows Server Core 2019/2.10.6
Region: us-east-1
Code: dotnet 6

here is the relevant portion of the cfn-init.log

2022-12-02 10:39:38,488 [INFO] -----------------------Starting build-----------------------
2022-12-02 10:39:38,520 [INFO] Running configSets: Infra-WriteRuntimeConfig, Infra-EmbeddedPreBuild, Hook-PreAppDeploy, Infra-EmbeddedPostBuild, Hook-EnactAppDeploy, Hook-PostAppDeploy
2022-12-02 10:39:38,520 [INFO] Running configSet Infra-WriteRuntimeConfig
2022-12-02 10:39:38,535 [INFO] Running config Infra-WriteRuntimeConfig
2022-12-02 10:39:38,582 [INFO] Command 01mkdir succeeded
2022-12-02 10:39:38,832 [DEBUG] CloudFormation client initialized with endpoint https://cloudformation.us-east-1.amazonaws.com
2022-12-02 10:39:38,832 [DEBUG] Describing resource AWSEBAutoScalingGroup in stack arn:aws:cloudformation:us-east-1:265786937427:stack/awseb-e-eqhz5scteh-stack/590b1f30-71af-11ed-bc49-0af991946407
2022-12-02 10:39:38,988 [INFO] Command 02writeappsource succeeded
2022-12-02 10:39:38,988 [INFO] Waiting 5 seconds for reboot
2022-12-02 10:39:44,473 [DEBUG] CloudFormation client initialized with endpoint https://cloudformation.us-east-1.amazonaws.com
2022-12-02 10:39:44,473 [DEBUG] Describing resource AWSEBAutoScalingGroup in stack arn:aws:cloudformation:us-east-1:265786937427:stack/awseb-e-eqhz5scteh-stack/590b1f30-71af-11ed-bc49-0af991946407
2022-12-02 10:39:44,598 [INFO] Command 03writeconfig succeeded
2022-12-02 10:39:44,613 [INFO] Running configSet Infra-EmbeddedPreBuild
2022-12-02 10:39:44,613 [INFO] Running configSet Hook-PreAppDeploy
2022-12-02 10:39:44,629 [INFO] Running config Hook-PreAppDeploy
2022-12-02 10:40:45,402 [INFO] Command hooks succeeded
2022-12-02 10:40:45,449 [INFO] Running configSet Infra-EmbeddedPostBuild
2022-12-02 10:40:45,464 [INFO] Running configSet Hook-EnactAppDeploy
2022-12-02 10:40:45,480 [INFO] Running config Hook-EnactAppDeploy
2022-12-02 10:41:07,089 [ERROR] Command hooks (HooksExecutor.exe appdeploy\enact) failed
2022-12-02 10:41:07,089 [ERROR] Error encountered during build of Hook-EnactAppDeploy: Command hooks failed
Traceback (most recent call last):
  File "cfnbootstrap\construction.pyc", line 578, in run_config
  File "cfnbootstrap\construction.pyc", line 146, in run_commands
  File "cfnbootstrap\command_tool.pyc", line 127, in apply
cfnbootstrap.construction_errors.ToolError: Command hooks failed
2022-12-02 10:41:07,089 [ERROR] -----------------------BUILD FAILED!------------------------
2022-12-02 10:41:07,089 [ERROR] Unhandled exception during build: Command hooks failed
Traceback (most recent call last):
  File "cfn-init", line 176, in <module>
  File "cfnbootstrap\construction.pyc", line 137, in build
  File "cfnbootstrap\construction.pyc", line 564, in build
  File "cfnbootstrap\construction.pyc", line 578, in run_config
  File "cfnbootstrap\construction.pyc", line 146, in run_commands
  File "cfnbootstrap\command_tool.pyc", line 127, in apply
cfnbootstrap.construction_errors.ToolError: Command hooks failed
2022-12-02 11:05:58,862 [DEBUG] CloudFormation client initialized with endpoint https://cloudformation.us-east-1.amazonaws.com
2022-12-02 11:05:58,862 [DEBUG] Describing resource AWSEBAutoScalingGroup in stack arn:aws:cloudformation:us-east-1:265786937427:stack/awseb-e-eqhz5scteh-stack/590b1f30-71af-11ed-bc49-0af991946407

Deploying directly from Visual Studio, either via Publish to AWS or Publish to AWS Elastic Beanstalk (Legacy) both work fine, even though they are the exact same code and going to the exact same environment.

Ao this does not appear to be a code or environment issue.

Also, the build and publish processes complete without issue as well, only failing once deployed to AWS Elastic Beanstalk.

Any help is greatly appreciated...

CodePudding user response:

During the reference and investigations, I have two workarounds for you.

1.Switching to an immutable deployment in the ElasticBeanstalk settings.

2.This issue could also be resulted from high volume of instance utilizing, and you could try to upgrade the EC2 instance size.

  • Related