AWS EC2 Launch configuration user data - command not found

Viewed 1679

For AWS EC2 (Amazon Linux) launch configuration, I have set some userdata having some sequence of commands which looks like below.

#!/bin/bash -exv \n", 
"#Execute Init resource\n", 
"whoami\n", 
"pwd\n", 
"npm -v\n",

Upon instance startup, user data is executing fine and native commands like "whoami" are giving correct output in cloud-init-output.log but it is giving error for npm command with error message like "npm command not found".

But, when I ssh to the instance and try executing some npm commands, it is working fine.

Could some one please guide me in solving this?

Thanks

2 Answers
Related