Search code examples
pythonamazon-web-servicesaws-code-deploy

CodeDeploy failing with error Errno::ENOEXEC with message Exec format error


I have a CodeDeploy which deploys application on Windows instances. I have a Python script which is running as part of ValidateService hooks. Below is the code I have in that script:

print("hello")

So, I have removed everything and just printing hello as part of this script. When this script is called by CodeDeploy I get below error:

error

My appspec.yml file:

  ...
  ValidateService:
    - location: scripts/verify_deployment.py
      timeout: 900

I tried getting some help on Google but got nothing. Can someone please help me here.

Thanks


Solution

  • After so much of investigations, I found my answer. The issue is little misleading, there is nothing to do with Code format or ENOEXEC. The issue was due to Python path. While executing my script, CodeDeploy was unable to find Python (Though I had already added python.exe in Environment variable path).

    Also, I found that CodeDeploy is unable to execute .py file due to Python path issue. So, I created a PowerShell script and invoking Python script from there. Like below:

    C:\Users\<username>\AppData\Local\Programs\Python\Python37-32\python.exe C:\Users\<username>\Documents\verify_deployment.py
    

    It executed Python script successfully and gave me below output:

    hello