Installing MongoDB or other packages with Node JS using "ebextensions"

Recently wanted to install a NodeJS application on Elastic Beanstalk. That was easy :).
One can use AWS EB Console to upload a zipped nodejs application and be done with it.

However wanted to install and run MongoDB in the beanstalk image that gets created when the application get deployed.
So the easiest way to get this done is to use CLI for AWS EB.
Using Elastic Beanstalk  CLI ( Command Line Interface ) simplifies so many things


In short you would need, Python 2.7 with PIP and once you have pip EB CLI can be installed with "pip install awsebcli"

One would have to either create a new EB environment or configure an existing nodeJs application source code folder to an EB environment.

On my AWS environment, I have few glitches that can be avoided ( network configurations are slightly restrictive) only when the EB applications is created from AWS Web Console, hence I would not be using "eb create", but I create an empty EB NodeJs application environment and on my local machine map the application using "eb init"

Moving on, assuming you have everything on the folder on your local computer  and ready to test EB CLI and container customization, create a folder ".ebextensions". To customize the EB container , you can include one or more configuration files with your source bundle. Configuration files must be named with the extension .config (for example, myapp.config) and placed in an .ebextensions top-level directory in your source bundle. Configuration files are executed in alphabetical order.

One can read about it here for linux and here for windwos

For Installing Mongo , Here is the config file

files:
  "/etc/yum.repos.d/mongodb.repo":
    mode: "000644"
    content: |
      [MongoDB]
      name=MongoDB Repository
      baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
      gpgcheck=0
      enabled=1
container_commands:
  01_enable_rootaccess:
    command: echo Defaults:root \!requiretty >> /etc/sudoers
  02_install_mongo:
    command:  sudo yum --disablerepo="*" --enablerepo="MongoDB" install -y mongo-10gen-server
    ignoreErrors: true
  03_turn_mongod_on:
    command: sudo mkdir /var/data ; sudo mongod --fork --logpath /var/log/mongodb.log --dbpath=/var/data;
  04_disable_mongo_service:
    command: sudo chkconfig mongod off

Popular posts from this blog

Open source grid computing software

TYK API Gateway to AWS API Execute Gateway + Lambda

Effective CPU Utilizing with Parallel Extensions for .NET 3.5