Node AWS command not found in Jenkins script - node.js

I'm trying to push my React App build to an S3 bucket from Jenkins/BlueOcean plugin.
But the aws command doesn't work inside of the Jenkins script.
This is what my script is doing:
#!/usr/bin/env sh
set -x
npm install -g aws-sdk
set +x
set -x
aws
echo $PATH
set +x
Here's the output:
The npm install works just fine, even npm start (to start my react server on localhost). In my development environment I can type aws without any errors.
I'm guessing it's an issue with the PATH? I've only been able to find issues regarding npm not working, but that works fine for me.
Why can't the script find aws as a command? How do I fix that?

Related

Why can't install npm to create package.json on AWS EC2?

I'm trying use EC2 to execute command npm install will get bellow error.
(Node.js had already install)
Dose anybody know why?
Is that the reason that I execute this command chmod 400 before login EC2 by ssh?
chmod 400 seems only could read, isn't it?
npm install only works if there is an existing package.json file. Your ls command shows that the directory is empty.
If you want to create your initial package.json file, you want to use the command npm init and answer the questions.

Laradock - add custom npm package

It's a kind of not normal thing, but this is something, that temporarily is a solution.
I have laradock installed in a system and laravel app.
All that I'm using from laradock provides me command below
docker-compose up -d nginx mysql php-worker workspace redis
I need to add node package (https://www.npmjs.com/package/tiktok-scraper) installed globally in my docker, so I can get results by executing php code like below
exec('tiktok-scraper user username-n 3 -t json');
This needs to be available for php-fpm and php-worker level, as I need this in jobs and for endpoints, that should invoke scrape.
I know, that I'm doing wrong, but I have tried to install it within workspace like using
docker-compose exec workspace bash
npm i -g tiktok-scraper
and after this it's available in my workspace (I can run for instance tiktok-scraper --help) and it will show me the different options.
But this doesn't solve the issue, as I'm getting nothing by exec('tiktok-scraper user username-n 3 -t json'); in my laravel app.
I'm not so familiar with docker and not sure, in which dockerfile should I put something like
RUN npm i -g tiktok-scraper
Any help will be appreciated
Thanks
To execute the npm package from inside your php-worker you would need to install it in the php-worker container. But for the php exec() to have an effect on your workspace this workspace would need to be in the same container as your php-worker.

AWS CLI command not run when executed via npm run command

System specification -
node version - v10.15.0
npm version - 6.4.1
aws-cli version - aws-cli/1.16.81 Python/3.6.0 Windows/10 botocore/1.12.71
sam-cli version - SAM CLI, version 0.41.0
Running on a windows machine.
So I have a node project, which would be deployed to aws-sam. I have scripts for sam-validate, prepare, package. But when I run this script via npm run <package-name>, commands don't run. For example If I run npm run package, I get the following -
aws --region <region-name> s3api head-bucket --bucket <bucket-name>
Command not run
Command executed in 0 msec
aws --region <<region-name>> cloudformation package --template-file template.yaml --s3-bucket <bucket-name> --output-template-file template-deploy.yaml
Command not run
Command executed in 0 msec
But surprisingly If I run those commands from powershell individually, then it works fine. Which made me come to the realization that scripts are okay, as the generated commands do work when I run them individually.
I checked my environment variables. All the things(node path, aws cli path etc.) are there.
What am I missing here? Simply put the problem is - Do I need to do anything else to run aws-cli or sam-cli commands through node scripts?
There might be an issue with your scripts i think,
Consider writing the script in python like
import subprocesses
commandToBeExecutedOnShell='any command'
subprocess.check_call(commandToBeExecutedOnShell, shell=True)
You can then either run the scripts from python itself or
create a separate node app which calls python functions
Reference This
and then run that node app using npm run

npm: command not found on amazon ec2 (even though its installed)

We installed NPM and created an AMI
The elastic beanstalk uses that AMI to create an EC2
The Procfile calls a shell script with the content pasted below.
I am getting the error - npm : command not found (when i use the command npm manually, it works, only fails during beanstalk deploy)
Also used the full path for npm(home/ec2-user/.nvm/versions/node/v11.6.0/bin/npm), which results in permission denied
I know its just a minor thing I am missing here, already spent few hours on this.
I tried sourcing my bash profile, which also results in permission denied.
#!/usr/bin/env bash
npm install
npm install -g serve
npm run build
nohup serve -s build > orgweb.log &
Not sure if it is just a typo or did you use this exact full path
home/ec2-user/.nvm/versions/node/v11.6.0/bin/npm
But if you did, there needs to be a slash before home, as in
/home/ec2-user/.nvm/versions/node/v11.6.0/bin/npm

Running node apps with CodeDeploy

I am using Codeship as my CI tool, I integrate it with AWS CodeDeploy service. The procedure is perfect until my appspec.yml file calls my script to run the node app. Even though I have npm, node, bower and grunt installed I get command not found errors.
I would try editing your start_server.sh and adding npm and node to the $PATH environment variable or put that path directly in the command itself.
So instead of
npm install
Try
/usr/local/bin/npm install
That might not be where your npm lives but if you need to find out just do which npm
Perform the below steps:
which node
sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/node (output of above step) /usr/bin/node
which npm
sudo ln -s /home/ubuntu/.nvm/versions/node/v12.13.1/bin/npm (output of above step) /usr/bin/npm
and try to use it via /usr/bin/npm install
I hope this will help you!!
For people who still might run into the same problem.
Check your appspec.yml file and look at the destination, it should contain something like /home/ec2-user....
in this case we need to make sure code deploy agent runs with that user profile (ec2-user). Check this link for steps to to make code deploy to run with your user profile

Resources