Skip to content

Instantly share code, notes, and snippets.

@ferrao
Last active September 27, 2019 07:59
Show Gist options
  • Save ferrao/c7f1e9ea0b41af7fa31d39885aed9ae8 to your computer and use it in GitHub Desktop.
Save ferrao/c7f1e9ea0b41af7fa31d39885aed9ae8 to your computer and use it in GitHub Desktop.
AWS beenstalk

AWS BeenStalk and Node.JS

Create new ebs application

eb init

Rename EBS environment name

eb config save my-env-name --cfg my-config-name # save the environment config
eb terminate # terminate the environment
eb create my-new-env-name --cfg my-config-name # Create a new cloned environment with a new name

Deploy

Use eb deploy to package the latest git commited revision to eb.

Prevent permission denied errors during npm install

echo "unsafe-perm=true" > .npmrc

EBS EC2 Instance

Connect

Use eb ssh to connect to the ebs EC2 instance

App Location

  • Initially deployed to : /tmp/deployment/application
  • Moved afterwords to : /var/app/current

Logs in /var/log/eb-activity.log and /var/log/nodejs/nodejs.log

Restart node process

sudo python /opt/elasticbeanstalk/containerfiles/ebnode.py --action stop-all
sudo python /opt/elasticbeanstalk/containerfiles/ebnode.py --action start-all

Access to node and npm binaries

export PATH=$PATH:/opt/elasticbeanstalk/node-install/node-v8.11.1-linux-x64/bin/

Manually Install dependencies

/opt/elasticbeanstalk/containerfiles/ebnode.py --app-path /var/app/current --action npm-install

The --app-path argument was not working, following changes on ebnode.py to make it work:

def run_npm_install(self, app_path):
        bin_path = self.get_node_bin_path()
        #self.npm_install(bin_path, self.config_manager.get_container_config('app_staging_dir'))
        self.npm_install(bin_path, app_path);

Change user to nodejs

sudo su - nodejs -s /bin/bash

Get environment variables for a running process

sudo cat /proc/<pid>/environ | tr '\0' '\n'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment