- 最新
- 投票最多
- 评论最多
The nodejs package is not available in the default Amazon Linux 2 repositories. You may need to enable the Amazon Linux 2 Extra repository before installing nodejs. You can refer to this guide for detailed instructions: How to Install and Configure Node.js on EC2 Instance Amazon Linux 2
Hello.
I think it can be installed using the method described in the document below.
So I thought it would be a good idea to add the following command to the user data.
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts
node -e "console.log('Running Node.js ' + process.version)"
I tried this. I just get the output that node is not installed.
By the way, what kind of problem is displayed when executing "yum install"? For example, if there is a timeout error, there is a possibility that there is no network route to access the repository from EC2, resulting in an error. If you are running EC2 in a private subnet, I think you will need a communication route to the NAT Gateway. If it is a public subnet, you will need to check whether a public IP address is assigned to EC2.
In the respective test file, there is no content being printed. Above i have shown how i have created the EC2. I'm very new to this, I dont know how to set that up. How would I have to do that?
If you have not made any special subnet settings, EC2 is probably running in the default subnet. You can check the user data execution log using the following command to check if there are any errors.
cat /var/log/cloud-init-output.log
By the way, the first line of the user data looks like the following, but the correct name is "yum update".
update yum -y > test0.txt
User Data script will run as the root user anyway, so there should be no need to run it with sudo
.
Try dropping sudo
so it's just yum install nodejs npm -y > test1.txt 2>&1
and see if that gets you further.
There is still an issue then look at whether test1.txt gets created; and if it does get created are you able to post its contents here?
Your AMI ami-0c101f26f147fa7fd is Amazon Linux 2023 and both packages are definitely available https://docs.aws.amazon.com/linux/al2023/release-notes/all-packages-AL2023.3.html
I tried doing it without sudo too. It dint make any difference. Test1.txt is just the output the value i set to nano_Id. Yes both the packages is suppose to work but i dont understand why it is not working.
Test1.txt is just the output the value i set to nano_Id
It's test2.txt that is set to ${NANO_ID}, test1.txt should be the output of the
yum install
command, and should be copied to the bucket (if it exists).I'm wondering if the EC2 is able to reach the YUM repos that the nodejs & npm packages need to be retrieved from?
Yes sorry you are right. For the Test1.txt. thats where its stops adding files to my s3 bucket. I just see test0, test2, test3, i dont see the rest. So I dont know what the output is or what the issue is.
Sounds like the yum command is never completing.
When the EC2 is provisioned, does it have a public IP address, and is it provisioned in a public subnet (that is, a subnet whose route table has an entry for 0.0.0.0/0 destination Internet Gateway)? You should be able to tell this from the EC2 section of AWS Console.
Also its security group will need to allow (at least) 80/tcp and 443/tcp outbound.
The EC2 instance needs to be able to reach the YUM repositories on the internet and pull down the packages from there, and install them.
相关内容
- AWS 官方已更新 2 年前
- AWS 官方已更新 7 个月前
- AWS 官方已更新 1 年前
Thank you this was helpful, But on subsequent use it doesnt work.
I tried to implement it with below
UserData: Buffer.from(
#!/bin/bash yum update -y yum install gcc-c++ make -y curl -sL https://rpm.nodesource.com/setup_18.x | sudo bash - yum update -y yum install nodejs -y node -v > test.txt aws s3 cp ./test.txt s3://Justans3samplebucket/test.txt
).toString("base64")The first time i ran it, it work, if i run the lambda again it isnt working anymore. The first time in test.txt, it had output the node version.
The AMI on the second line of the script is AL2023
Both packages should be available https://docs.aws.amazon.com/linux/al2023/release-notes/all-packages-AL2023.3.html
This is the image-ids he is using
ami-0a699202e5027c10d
Well spotted!
The first code block has
ImageId: "ami-0c101f26f147fa7fd"
which is AL2023.The second code block has
ImageId: "ami-0a699202e5027c10d"
which is Amazon Linux 2.nodejs and npm are not available in the default repos on AL2 (you have to install the EPEL repo):
@ThatDevguy can you clarify the version of Amazon Linux please?
With this should work already: