Skip to content

Instantly share code, notes, and snippets.

@markhuge
Last active March 25, 2016 12:57
Show Gist options
  • Save markhuge/8491479 to your computer and use it in GitHub Desktop.
Save markhuge/8491479 to your computer and use it in GitHub Desktop.
Fix failing node deployments on AWS Elastic Beanstalk

Fix failing node deployments on AWS Elastic Beanstalk

Elastic beanstalk runs npm install with a system user that has no homedir. During the npm install step, it's expecting a $HOME env variable for the npm cache (which doesn't exist). add this file to your project's .ebextensions directory to have it use root's homedir as a temporary path.

This workaround was provided by AWS support, but it doesn't appear to be documented anywhere. Determining root cause on this was a massive pain in the ass. Sharing this so others don't need to feel the pain.

files:
"/tmp/fixnpm.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
FILE="/etc/hook-modified"
if [ ! -f "$FILE" ]
then
sed -i 's/function error_exit/export HOME=\/root\n\nfunction error_exit/' /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh
touch $FILE
exit 0
else
exit 0
fi
commands:
fixnpm:
command: "sh /tmp/fixnpm.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment