Bedrock/Sage combination on AWS Elastic Beanstalk

Hello,

I set up bedrock on AWS Beanstalk. I would like to discuss what I did with you and find some improvements, or help other people bringing their Bedrock project to Elastic Beanstalk.

What I did:

  1. I used WP Offload S3 Lite to handle my assets

  2. I Installed EB CLI

  3. I executed eb init. This makes the folder ready to a deploy on elasticbeanstalk. You have to choose PHP5.6 (PHP 7 is not yet available on AWS Beanstalk)

  4. Now comes the intersting part: I created the folder .ebextensions and added the file bedrock.config in it, with the following content:

    commands:
    01_install_nodejs:
    cwd: /tmp
    test: '[ ! -f /usr/bin/node ] && echo “node not installed”'
    command: 'yum install -y nodejs --enablerepo=epel’
    02_install_npm:
    cwd: /tmp
    command: 'yum install -y npm --enablerepo=epel’
    03_install_php_composer:
    command: "sudo curl -sS https://getcomposer.org/installer | sudo php – --install-dir=/usr/local/bin --filename=composer"
    04_install_gulp_and_bower:
    command: “sudo npm install -g inherits bower gulp”

    container_commands:
    01_install_composer_packages:
    command: "composer update"
    env:
    “COMPOSER_HOME”: "/tmp"
    02_remove_node_packages:
    command: "sudo rm -rf web/app/themes/mytheme/node_modules"
    03_install_node_packages:
    command: "cd web/app/themes/mytheme && sudo npm install"
    04_install_bower_packages:
    command: "cd web/app/themes/mytheme && bower update --allow-root"
    env:
    “PATH”: "/usr/bin"
    05_run_gulp:
    command: “cd web/app/themes/mytheme && gulp --production”

    option_settings:

    • namespace: 'aws:elasticbeanstalk:container:php:phpini’
      option_name: document_root
      value: /web
  5. I executed eb deploy to deploy the project to Beanstalk

  6. After that, you have to set your configuration with the environment variables for you beanstalk environment.

4 Likes

Because I was asked for it: Here my new configuration with PHP7:

commands:
  01_node_install:
    cwd: /tmp
    test: '[ ! -f /usr/bin/node ] && echo "node not installed"'
    command: 'yum install -y nodejs --enablerepo=epel'
  02_npm_install:
    cwd: /tmp
    test: '[ ! -f /usr/bin/npm ] && echo "npm not installed"'
    command: 'curl -L http://npmjs.org/install.sh | sh'
  03_node_update:
    cwd: /tmp
    test: '[ ! -f /usr/bin/n ] && echo "node not updated"'
    command: 'npm install -g n && n stable'
  07_install_php_zip:
    cwd: /tmp
    command: 'yum install -y zip unzip php70-zip --enablerepo=epel'
  08_install_php_composer:
    command: "sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer"
  09_install_gulp_and_bower:
    command: "sudo npm install -g inherits bower gulp"

container_commands:
  01_install_composer_packages:
    command: "composer update"
    env: 
      "COMPOSER_HOME": "/tmp"
  02_remove_node_packages:
    command: "sudo rm -rf web/app/themes/mytheme/node_modules"      
  03_install_node_packages:
    command: "cd web/app/themes/mytheme && sudo npm install" 
  04_install_bower_packages:
    command: "cd web/app/themes/mytheme && bower update --allow-root"
    env:
      "PATH": "/usr/bin"
  05_run_gulp:
    command: "cd web/app/themes/mytheme && gulp --production"

option_settings:
  - namespace: 'aws:elasticbeanstalk:container:php:phpini'
    option_name: document_root
    value: /web

And here is another version with constant node version. The node 8.0 update crashed my npm package installation, so I decided to make a fixed version. Should work with newer node versions, too. But I run an older sage, so I need version 0.10.47.

commands:
  01_install_node_and_npm:
    cwd: /tmp
    command: 'curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash && . /.nvm/nvm.sh && nvm install 0.10.47'
  02_make_node_available:
    cwd: /tmp
    command: 'rm -f /usr/bin/node && ln -s /.nvm/v0.10.47/bin/node /usr/bin/node'    
  07_install_php_zip:
    cwd: /tmp
    command: 'yum install -y zip unzip php70-zip --enablerepo=epel'
  08_install_php_composer:
    command: "sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer"
  09_install_gulp_and_bower:
    command: "sudo /.nvm/v0.10.47/bin/npm install -g inherits bower gulp"

container_commands:
  01_install_composer_packages:
    command: "composer update"
    env: 
      "COMPOSER_HOME": "/tmp"
  02_remove_node_packages:
    command: "sudo rm -rf web/app/themes/mytheme/node_modules"      
  03_install_node_packages:
    command: "cd web/app/themes/mytheme && sudo /.nvm/v0.10.47/bin/npm install" 
  04_install_bower_packages:
    command: "cd web/app/themes/mytheme && /.nvm/v0.10.47/bin/bower update --allow-root"
    env:
      "PATH": "/usr/bin"
  05_run_gulp:
    command: "cd web/app/themes/mytheme && /.nvm/v0.10.47/bin/gulp --production"

option_settings:
  - namespace: 'aws:elasticbeanstalk:container:php:phpini'
    option_name: document_root
    value: /web

And another hint: Don`t do it like me :slight_smile:
It works like this, but next time, I would try to use a Docker container configuration. This configuration file I have to change sometimes is not really the best option on getting Sage running on AWS I think.

Just came to say thanks for posting this - about to give this a try. Will update with any gotchas I learn along the way for anyone else who comes across this

1 Like

One more hint: Use npm shrinkwrap (https://docs.npmjs.com/cli/shrinkwrap) to fix the versions of your node packages and their requirements.
Otherwise, an update in a node package requirement can crash the setup.