How to deploy Substrate node in AWS EC2.

In the Substrate official website they mentioned that “substrate enables developers to quickly and easily build future proof blockchains” – they’re lying! even deploying is not easy and we still have to prove that it is future proof but nevertheless we move forward. The technology is about 3 years old but the stack is still very much in its infancy. Normally, if we start with a new tech, we need to go throung the entire Devops to guarantee full execution from modification/coding to actual deployment process.

This is how you are going to deploy your Substrate blockchain node using AWS EC2 servers.

Create an instance in AWS EC2 (The minimum server specification to run the node is t2.small).

t2.small / Ubuntu

Clone the substrate-node-template

sudo git clone https://github.com/substrate-developer-hub/substrate-node-template.git

Install the necessary Rust dependencies and compile the project. You can find the instructions in the Git repository. https://github.com/substrate-developer-hub/substrate-node-template

After compiling, you can run the node using the command.

./target/release/node-template --tmp --dev --alice --port 30333
--ws-port 9944 --rpc-port 9933 --rpc-cors all --ws-external --rpc-external --rpc-methods=unsafe --validator

In the command above we’ve added three parameters to expose our node externally.

--rpc-cors all
--ws-external
--rpc-external

Even if we’ve already exposed our websocket ports externally we still couldn’t connect to our node. We still need to proxy a site through SSL/HTTPS to be able to connect to our WSS ports.

Install NGINX. Follow the instructions here: https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04. You don’t need two server blocks, you just need one to proxy the websocket.

You need to provide SSL. In my case I use Certbot. Follow the instructions here: https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04.

Now modify the server block to include the proxy settings:

....
        
location / {
          try_files $uri $uri/ =404;

          proxy_buffering off;
          proxy_pass http://localhost:9944;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
}

....

That’s it, you can now access your WSS in port 443. But first we need to run the node in the background. To do that we use the command below.

nohup ./substrate-run.sh >/dev/null 2>&1 &

The substrate-run.sh shell script contains the node-template run command shown above.

Also make sure that your firewall security inbound settings allows HTTPS:443 port

To test your connection, you can use the https://polkadot.js.org/ online dApp.

That’s it. Have fun with your own chain. Please don’t forget to donate if your find this blog helpful.

One response to “How to deploy Substrate node in AWS EC2.”

  1. Hey man Its an awesome guide how can we spin multiple nodes

Leave a comment

Blog at WordPress.com.