4

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

CK__
  • 1,252
  • 1
  • 11
  • 25

2 Answers2

4

As Marcin already answered in a comment, I don't think you can simply run python scripts in CodeDeploy. At least not natively.

The error you see means that Windows does not know how to execute the script you have provided. AFAIK Windows can't run python natively (like most linux distros can).

I am not very accustomed to CodeDeploy, but given the example at https://github.com/aws-samples/aws-codedeploy-samples/tree/master/applications/SampleApp_Windows, I think you have to install python first.

thetillhoff
  • 451
  • 4
  • 8
  • 1
    I can't find any documentation that explicitly states that it only uses shell, but it's implied in the samples above and it explains how to run other scripts here: https://docs.aws.amazon.com/codedeploy/latest/userguide/application-specification-files.html#appspec-files-on-server-compute-platform – Geoffrey Burdett Sep 29 '21 at 12:51
  • @thetillhoff I already have Python installed on servers and I have set Python in environment path as well. – CK__ Sep 30 '21 at 09:20
  • @GeoffreyBurdett you are right. The document says "You can run any type of script as long as it is supported by the operating system running on the instances" and I have Python installed so it should have worked for me. – CK__ Sep 30 '21 at 09:22
0

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
CK__
  • 1,252
  • 1
  • 11
  • 25