This guide walks you through the steps to get Node-RED running in an AWS environment.
There are two methods:
Running on AWS Elastic Beanstalk Service (EB)
Running on Elastic Beanstalk with high availability
Running under Ubuntu image on AWS EC2
Running on AWS EBS
prerequisites
Make sure you have an AWS account with Elastic Beanstalk, SQS, and S3 enabled
Download EB command line and install on your local machine – see link
Create AWS credentials and save them in a local file (~/.aws/config or Usersusername.awsconfig) as shown below
[profile eb-cli]
aws_access_key_id = key id
aws_secret_access_key = access key
Create EB environment
Create a new directory (e.g. demoapp)
cd to that directory
Run eb init to create a new elastic beanstalk project. Choose your preferred region and use node.js as the platform. You will be asked if you want to use ssh. If you do this, make sure you have ssh installed on your computer if you want to generate a new key pair.
Sign in to the AWS console on a browser, choose Identity and Access Management (IAM) and add the AmazonS3FullAccess policy to aws-elasticbeanstalk-ec2-role.NOTE: This provides full access from EBS to S3, you may wish to adjust this policy to meet your own security needs
Create a Node-RED environment
Create a package.json file with the following content (replace “demoapp” with your app name)
{
“name”: “demoapp”,
“version”: “1.0.0”,
“description”: “node-red demo app”,
“main”: “”,
“scripts”: {
“start”: “./node_modules/.bin/node-red -s ./settings.js”
},
“engines”: {
“node”: “10.x”
},
“dependencies”: {
“node-red”: “1.1.x”,
“aws-sdk”: “2.4.x”,
“node-red-contrib-storage-s3”: “0.0.x”,
“when”: “3.7.x”
},
“author”: “”,
“license”: “ISC”
}
Copy the default Node-RED settings.js file to the demoapp directory
Edit the settings.js file to add the following entry to module.exports (set awsRegion to what is used in eb init and replace demoapp with your app name):
awsRegion: ‘eu-west-1’,
awsS3Appname: ‘demoapp’,
storageModule: require(‘node-red-contrib-storage-s3’),
At the command prompt, make sure you are in the application’s top-level directory and run the command eb create; you may want to specify a more unique application name. This will take a long time to run, but will eventually return successfully.
Configure Node-RED access
Node-RED can now be accessed directly from the application’s web url. However, this is insecure and doesn’t work well for logging. Instead, we will configure direct access to the node-red management port on the ec2 instance it uses.
In the AWS console, choose EC2, and then choose a security group. You will see a set of security groups. Select an option with the name of your environment and a description of “Security Group for ElasticBeanstalk Environment.” Once selected, click Actions and then Edit Inbound Settings. A dialog box with rules appears. Add new rule. Set type to “all traffic” and source to “my ip”. Save the rule.
Select the EC2 instance running the node red application.Copy its IP address
Enter the IP address in the browser and the port is 8081. This will provide direct access to the node-red management console.
Note: The public IP address also provides access to the node-red application, it is best to remove this access as well, namely the HTTP rule for port 80.
Your Node-RED instance is now running on EBS. Any streams you create will be saved to AWS S3 so that you can tear down the environment and have the streams accessible when you redeploy.
Running on Elastic Beanstalk with high availability
This deployment option gives you a multi-node Node-RED setup with a shared file system using Amazon Elastic File System (EFS). Because it runs multiple nodes behind a load balancer, you get high availability – if a node dies, Elastic Beanstalk will automatically replace it.
To get started, clone the repository here https://github.com/guysqr/node-red-ha-on-aws and follow the simple instructions. The infrastructure is created for you by CloudFormation templates, so you don’t need to know much about AWS to set it up.
Additionally, this deployment option enables you to run Node-RED under https and log in via Auth0 (or you can easily switch to built-in authentication or any Passport-compatible ID provider).
Running on AWS EC2 using Ubuntu
Create a base EC2 image
Log in to the AWS EC2 console
Click “Launch Instance”
In the Quick Start AMI list, select Ubuntu Server
Choose an instance type – t2.micro is a good place to start
On the Configure Security Group tab, add a new Custom TCP Rule for port 1880
In the final “Audit” step, click the “Start” button
The console will prompt you to configure a set of SSH keys. Select Create a new key pair and click Download key pair. Your browser will save the .pem file – keeping it safe. Finally, click Start.
After a few minutes, your EC2 instance will be running. In the console, you can find the IP address of your instance.
Set Node-RED
The next task is to log into the instance and install node.js and Node-RED.
Follow AWS guidelines to connect to your instance.
Once logged in, you need to install node.js and Node-RED
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash –
sudo apt-get install -y nodejs build-essential
sudo npm install -g -unsafe-perm node-red
At this point, you can test your instance by running node-red. NOTE: You may receive some errors regarding serial nodes – this is expected and can be ignored.
Once started, you can log in at http://
To have Node-RED start automatically when your instance restarts, you can use pm2:
sudo npm install -g –unsafe-perm pm2
pm2 start `which node-red` — -v
pm2 save
pm2 startup
NOTE: This last command will prompt you to run another command – make sure you do what it says.
Next step
This guide only scratches the surface of how you can choose to configure your instances to run in EC2. Node-RED is “just” a node.js application that exposes an HTTP server – in this principle there are many online guides available to learn about other possible approaches.
Schlüsselwörter: LoRa-Gateway