Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  • https://forums.aws.amazon.com/thread.jspa?messageID=942515
  • https://github.com/aws/elastic-beanstalk-roadmap/issues/15
like image 822
whoopscheckmate Avatar asked Aug 13 '20 16:08

whoopscheckmate


People also ask

Which service can be used to restrict access to AWS Elastic Beanstalk resources?

Short description. You can restrict the permissions of an IAM user or role by using an IAM policy. The policy can restrict access to a single environment or application.

Can an IAM user access the AWS Elastic Beanstalk console?

AWS Elastic Beanstalk provides two managed policies that enable you to assign full access or read-only access to all resources that Elastic Beanstalk manages. You can attach the policies to AWS Identity and Access Management (IAM) users or groups, or to roles assumed by your users.


2 Answers

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?

like image 198
Khaled AbuShqear Avatar answered Oct 13 '22 03:10

Khaled AbuShqear


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.

like image 14
Marcin Avatar answered Oct 13 '22 03:10

Marcin