How do you add chmod +x permission to an AWS Elastic Beanstalk platform hook?
Asked Answered
C

3

25

Context

I am using Elastic Beanstalk to deploy a very simple test application. I have several packages I want to install using apt. I have included a 01_installations.sh script with the installations in the .platform/hooks/prebuild directory. When I zip my application and deploy to Elastic Beanstalk, the logs confirm that the prebuild script runs, but it does not have permissions.

2020/08/12 21:03:46.674234 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2020/08/12 21:03:46.674256 [INFO] Executing platform hooks in .platform/hooks/prebuild/
2020/08/12 21:03:46.674296 [INFO] Following platform hooks will be executed in order: [01_installations.sh]
2020/08/12 21:03:46.674302 [INFO] Running platform hook: .platform/hooks/prebuild/01_installations.sh
2020/08/12 21:03:46.674482 [ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/01_installations.sh failed with error fork/exec .platform/hooks/prebuild/01_installations.sh: permission denied  

Question

My understanding is that permissions were denied because I did not add chmod +x to make the .sh file executable. As the AWS documentation on platform hooks states: "Use chmod +x to set execute permission on your hook files." (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html). My question is: how do I do this?

I simply have the .sh file in a directory. I do not call it from anywhere else. Is there a simple step I'm missing? The AWS documentation makes it seem like it should be straightforward.

Previous Attempts

Things I have tried:

  1. Adding .ebextensions
    • Attempt: Create a .config file in the .ebextensions directory with the below command which should execute the .sh file with chmod +x permissions.
    • Result: The same error occurs. The Elastic Beanstalk logs do not indicate that the .config was processed at all.
container_commands:
    01_chmod1:
        command: "chmod +x .platform/hooks/prebuild/01_installations.sh"
  1. Changing the name of the .sh file
    • Attempt: Change the .sh file to be named "chmod +x 01_installations.sh" as suggested by an AWS user (forums link below). Remove the .ebextensions
    • Result: The same error occurs.
[RunAppDeployPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/chmod +x 01_installations.sh failed with error fork/exec .platform/hooks/prebuild/chmod +x 01_installations.sh: permission denied 

I have reviewed the ideas here, but none of them actually include complete enough examples to follow:

Coranto answered 13/8, 2020 at 16:18 Comment(0)
S
13

Normally you set the permissions on your local workstation, when before you zip your deployment package.

However, if you want to do this on EB instance, then you can't use container_commands for that. The reason is that container_commands execute after prebuild. Instead you should try using commands:

The prebuild files run after running commands found in the commands section of any configuration file and before running Buildfile commands.

Scandian answered 13/8, 2020 at 21:38 Comment(2)
Thank you for the clarification. Changing the container_commands to commands did allow it to run, though the script failed again.Coranto
"commands" are execute before the application is unzipped, so if you are trying to access one of this prebuild scripts, it would not work. It may work in the past, as it has 14 upvotes, but right now as this comment is written I can assure this no longer works.Olsen
D
18

Make sure to make your file executable in git

chmod +x path/to/file
git update-index --chmod=+x path/to/file

reference from How to add chmod permissions to file in GIT?

Dobsonfly answered 1/9, 2020 at 18:39 Comment(4)
does not work for me using Git Bash on Windows 10. not sure how it works for others. maybe they are using WSL instead of Git Bash.Malodorous
@Malodorous I didn't try it on windowsDobsonfly
I don't follow. WHere are you putting this chmod? I have same scenario with a permission denied error on post deploy script in .platform/hooks/postdeploy/Alcott
@Alcott just do it in the repo folder locally -> commit -> push the changesDobsonfly
S
13

Normally you set the permissions on your local workstation, when before you zip your deployment package.

However, if you want to do this on EB instance, then you can't use container_commands for that. The reason is that container_commands execute after prebuild. Instead you should try using commands:

The prebuild files run after running commands found in the commands section of any configuration file and before running Buildfile commands.

Scandian answered 13/8, 2020 at 21:38 Comment(2)
Thank you for the clarification. Changing the container_commands to commands did allow it to run, though the script failed again.Coranto
"commands" are execute before the application is unzipped, so if you are trying to access one of this prebuild scripts, it would not work. It may work in the past, as it has 14 upvotes, but right now as this comment is written I can assure this no longer works.Olsen
M
0

This worked for me after updating the permission commit the changes.

Also the commands in .config file will not work as those commands will run pre-deployment and hence will not be able to find the path to .sh file.

Messmate answered 1/9, 2021 at 17:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.