2 個答案
- 最新
- 最多得票
- 最多評論
2
The user-data is ran as root
-user so the NVM is now installed under root
only. So when you run the curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
-script it gets installed under /root/.nvm/
. Your code then assumes it's installed under /home/ec2-user/.nvm
which is not true, so your nvm commands after that fail.
So you would need to either install the nvm and node system wide. Or just run commands as ec2-user in the script via "sudo -u ec2-user <command>" For example:
sudo -u ec2-user sh -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash'
sudo -u ec2-user sh -c '. ~/.nvm/nvm.sh && nvm install --lts'
Other option would be to wrap all the commands you want to run as ec2-user
into shell script that you download from S3 or that you create the file inside user-data
.
Also I don't see you running nvm install
that would install Node on the machine.
相關內容
- 已提問 6 個月前
- AWS 官方已更新 9 個月前
- AWS 官方已更新 2 年前
- AWS 官方已更新 1 年前