'How to make Elastic Beanstalk uses Yarn instead of NPM in Amazon Linux 2

after researching a lot I still cannot make EB use Yarn to install packages. Below are some ways that I did try:

  • Install and run yarn via commands and container_commands in ./ebextensions/options.config (I got this error: Unhandled exception during build: Command 01_run_yarn failed in cfn-init.log)

    This is my ./ebextensions/options.config

        option_settings:
          aws:elasticbeanstalk:application:environment:
            NODE_ENV: production
    
        commands:
          01_install_node:
            command: |
              sudo curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -
              sudo yum -y install nodejs
          02_install_yarn:
            test: '[ ! -f /usr/bin/yarn ] && echo "Yarn not found, installing..."'
            command: |
              sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
              sudo yum -y install yarn
    
        container_commands:
          01_run_yarn:
            command: |
              yarn --production
    
  • Write script to install and run yarn in ./platform/hooks/prebuild/yarn.sh. I followed this article and got permission denied error in eb-engine.log



Solution 1:[1]

You can change permission on your local before pushing code:

git update-index --chmod=+x .platform/hooks/prebuild/yarn.sh

git commit -am 'message'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman