I am working on migrating a project from Heroku to AWS. I keep getting an error after deployment saying: 'invalid ELF header'. I have found posts with similar issues when using AWS Lambda, but I do not understand why I would have an issue with binary packages in Elastic Beanstalk.
Doesn't Elastic Beanstalk provide a configured environment to run my code similar to Docker? I feel like this problem must be more complex as I cannot find anyone else with this issue in Elastic Beanstalk.
Here is the exact error I am getting:
Error: /var/app/current/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/var/app/current/node_modules/bcrypt/bcrypt.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! beer#0.1.0 start: `node server/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the beer#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/.npm/_logs/2019-04-15T00_54_06_983Z-debug.log
I am working on a Mac, my code contains both client and server code written in React, node.js, and SQL. I am uploading my code via a ZIP file containing multiple folders, including node_modules/.
Some libraries are sensitive to the operating system and / or CPU architecture on which they are built. This is especially true of modules implemented in low-level languages, or that link to system libraries. In this case, you appear to be using bcrypt which is largely written in C++.
This is one reason that the zip file you upload to Elastic Beanstalk shouldn't include your node_modules/ folder (or anything else that Git is ignoring). The easiest way to create a zip for uploading to Elastic Beanstalk is probably to use git archive:
git archive -v -o myapp.zip --format=zip HEAD
This will respect your ignores, whereas manually zipping will include them.
Your archive should include package.json and package-lock.json in its root. Elastic Beanstalk will install its own node_modules/ from these files if they are present. This should ensure that all libraries are compatible with its operating system.
Related
I'm trying to circumvent the well-known issue with the latest versions of NPM and AWS Elastic Beanstalk where npm install fails because it can't find node_modules. I'm using platform hooks with my NUXTJS application.
It fails when AWS Code Pipeline runs a deploy and returns with this warning:
[ERROR] An error occurred during execution of command [app-
deploy] - [Use NPM to install dependencies]. Stop running the
command. Error: Command /bin/sh -c npm --production install
failed with error signal: killed. Stderr:npm WARN config
production Use `--omit=dev` instead.
So, I've added platform hooks at the app root but it's still failing. Also, I have added an environment variable to the EBS environment of:
NODE_ENV=production
Here's what my platform hooks look like. I thought this would work but something is obviously wrong. Can anyone spot it? Thanks for any helpful tips.
The custom-prebuild-script.sh looks like this:
#!/bin/bash
mkdir node_modules
I am trying to deploy backend serverless resources with CDK in AWS cloud but getting errors while deploying things via GitLab build.
trying with a local visual studio it works fine.
error is below :
$ npm run deploy-backend
> ui-dashboard-infra#0.0.0 deploy-backend /builds/project/control-panel/infra
> cdk deploy --app 'ts-node stacks/backend' --all --require-approval never
Bundling asset dashboard-A/restFunctionFallbackus-east-1/Code/Stage...
/builds/project/control-panel/infra/node_modules/#aws-cdk/core/lib/asset-staging.ts:398
throw new Error(`Failed to bundle asset ${this.node.path}, bundle output is located at ${bundleErrorDir}: ${err}`);
^
Error: Failed to bundle asset dashboard-A/restFunctionFallbackus-east-1/Code/Stage, bundle output is located at /builds/project/control-panel/infra/cdk.out/bundling-temp-4607286efdd890681baca6f8a5d9b9b32929fa84e9947500fbe203e5b5d06a0f-error: Error: spawnSync bash ENOENT
at AssetStaging.bundle (/builds/project/control-panel/infra/node_modules/#aws-cdk/core/lib/asset-staging.ts:398:13)
at AssetStaging.stageByBundling (/builds/project/control-panel/infra/node_modules/#aws-cdk/core/lib/asset-staging.ts:246:10)
at stageThisAsset (/builds/project/control-panel/infra/node_modules/#aws-cdk/core/lib/asset-staging.ts:137:35)
at Cache.obtain (/builds/project/control-panel/infra/node_modules/#aws-cdk/core/lib/private/cache.ts:24:13)
at new AssetStaging (/builds/project/control-panel/infra/node_modules/#aws-cdk/core/lib/asset-staging.ts:162:44)
at new Asset (/builds/project/control-panel/infra/node_modules/#aws-cdk/aws-s3-assets/lib/asset.ts:68:21)
at AssetCode.bind (/builds/project/control-panel/infra/node_modules/#aws-cdk/aws-lambda/lib/code.ts:180:20)
Subprocess exited with error 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ui-dashboard-infra#0.0.0 deploy-backend: `cdk deploy --app 'ts-node stacks/backend' --all --require-approval never`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ui-dashboard-infra#0.0.0 deploy-backend script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-08-10T08_29_17_449Z-debug.log
I have faced a similar kind of issue, and the problem is that there is a bug in cdk versions prior to the once released before 25th Feb 2021.
For that, please make sure either you are using the latest version of cdk, or you DO NOT HAVE ANY WHITE SPACES IN YOUR FILE PATHNAME (any directory name having space or your username that has a space might cause this problem). Once I removed the white spaces from the pathname, everything started to work as expected.
I got the same error as you. In my case, the issue was that I had esbuild installed as a dependency in the CDK folder, but not in the folder of my Lambda function.
I was able to fix the issue by installing esbuild as a dev dependency in my Lambda function folder. If you don't want to do that, you can also install it globally in your pipeline by adding the command npm i -g esbuild to your pipeline (consider pinning it to a particular version ie. npm i -g esbuild#x.y.z).
No idea why it was working locally without esbuild installed in the function folder, but then broke when doing the same thing in a Gitlab pipeline… I didn't have esbuild installed globally on my local machine or anything.
I am getting the following error after the .tgz command runs. Has anyone seen this?
npm WARN saveError ENOENT: no such file or directory, open '/tmp/scratchXEFHVJ.scratch/test-packageptX7bd/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/tmp/scratchXEFHVJ.scratch/test-packageptX7bd/package.json
This will later cause the wdio to not be found, as the node_modules never install I believe.
Running Appium v1.17.0
webdriverio
any help would be much appreciated
It might be due to missing files
Try
npm init -y // intializing for the package JSON
Add Webdriver CLI tool
npm install --save webdriverio #wdio/cli
Update the config file
npx wdio config
// after upadting
npx wdio ./wdio.conf.js
npm install
then create the bundle
npm install -g npm-bundle
Then create a zip
zip -r MyTest.zip *.tgz
then start testing part on AWS
I have been working on migrating a project from Heroku to AWS. I have been able to successfully upload the project onto AWS without any errors, however the applications health is listed as 'Degraded'. I have been reviewing my application logs and believe the issue has something to do with me writing the code on a Mac and then Elastic Beanstalk using a Linux AMI.
"invalid ELF header" when using the nodejs "ref" module on AWS Lambda
However, this post only diagnoses the issue. There is no solution provided. I am aware that there is an architectural mismatch when moving the code from Mac to Linux. I am looking for a solution to that problem.
Here are the error messages in my applications logs:
Error: /var/app/current/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/var/app/current/node_modules/bcrypt/bcrypt.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! beer#0.1.0 start: `node server/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the beer#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/.npm/_logs/2019-04-15T00_54_06_983Z-debug.log
I'm rather new to AWS. I'm running a Node.JS app on Elastic Beanstalk, and everything was working fine. However, because I need to do some image processing I decided to add Puppeteer and Sharp.
However, the installation on AWS fails and the application crashes. The log says the following:
sharp#0.21.3 install /tmp/deployment/application/node_modules/sharp
(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
ERR! sharp EACCES: permission denied, mkdir '/tmp/.npm/_libvips'
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/sharp/build'
gyp ERR! System Linux 4.14.97-74.72.amzn1.x86_64
gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v10.15.1-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v10.15.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /tmp/deployment/application/node_modules/sharp
gyp ERR! node -v v10.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp#0.21.3 install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sharp#0.21.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I'm really not familiar with Elastic Beanstalk, but that seems like an access restriction error. After searching for a bit, I found a possible solution: Adding the following code as an .extension file.
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/00_set_tmp_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
chown -R nodejs:nodejs /tmp/.npm
However, that didn't seem to do anything. Does anybody know where the error could be? Or where I should look for a solution? I'm not usually at home with this kind of stuff, but I'm forced to work with it for a while. Any help and advice would be greatly appreciated!
This is permission issues with AWS.
To solve this you have to follow the next steps:
Create a new file .npmrc
Add the following unsafe-perm=true
This will let to write files.
unsafe-perm=true is not working anymore with Node 16 and Amazon Linux 2, because it can't install the Sharp package. I was trying to install Strapi v4 on Elastic Beanstalk.
You need to perform permission updates in platform hooks according to this answer: https://github.com/lovell/sharp/issues/3221#issuecomment-1126528844
You can find additonal information to platform hooks here:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
You don't need to do anything about the execute permissions when your Amazon Linux 2 was released after April 29, 2022.
Solution:
Step 1: Create the following Platform Hooks paths in the root directory of your application bundle.
- .platform/hooks/prebuild
- .platform/confighooks/prebuild
The Platform Hook (.platform/hooks/prebuild) will execute the commands found in the bash script after the application is extracted but before the application configuration and proxy server process initiates.
The Platform Hook (.platform/confighooks/prebuild) will execute the commands found in the bash script during a configuration deployment/environment update.
Step 2: Once the above Platform Hooks paths have been created in your application bundle, the following bash script (00_npm_install.sh) will need to be created and placed under the "Prebuild" directory:
The bash script (00_npm_install.sh) will include the following:
#!/bin/bash
cd /var/app/staging
sudo -u webapp npm install sharp
Step 3: Validate the Application Bundle Structure
Sample project structure:
~/my-app/
├── app.js
├── index.html
├── .npmrc_bkp
├── package.json
├── package-lock.json
├── .platform
│ ├── confighooks
│ │ └── prebuild
│ │ └── 00_npm_install.sh
│ └── hooks
│ └── prebuild
│ └── 00_npm_install.sh
└── Procfile
Step 4: Deploy the Application!
Summary:
During the application deployment process, the application bundle is initially extracted and deployed within the /var/app/staging folder. In this same first step, all Node.js dependencies found in your (package.json) file will also be installed here but exist under /var/app/staging/node_modules/....
As mentioned in your comment, the /var/app/staging folder is owned by the webapp user but the npm install command is executed by root user. Therefore, the bash script workaround solution goes to the /var/app/staging/ directory and install the Sharp dependency by executing the sudo -u webapp npm install sharp command as the webapp user. All of this is done before the application and proxy server configuration process initiates as shown in "Instance deployment workflow".
As a result, the workaround solution will make the Elastic Beanstalk deployment process skip installing the Sharp dependency all together as it already exists! Afterwards, the application deployment process continues to the final provisioning step which moves all files/content from the /var/app/staging/ folder to the final /var/app/current/ directory location.
Lastly, the second Platform Hook (.platform/confighooks/prebuild) was implemented to avoid running into the same permissions error when performing a configuration deployment. A configuration deployment occurs when you make configuration changes that only update environment instances without recreating them!
Hope the following solution helps!