Learn how to host your website on a Raspberry Pi 4 after your app gets booted from Amazon Web Services (AWS) https://fireship.io/lessons/host-website-raspberry-pi/

#aws #rpi #tech

Raspberry Pi https://www.raspberrypi.org/
AWS & Parler https://www.buzzfeednews.com/article/johnpaczkowski/amazon-parler-aws

Install the quiz app 🤓

iOS https://itunes.apple.com/us/app/fireship/id1462592372?mt=8
Android https://play.google.com/store/apps/details?id=io.fireship.quizapp

Upgrade to Fireship PRO at https://fireship.io/pro
Use code lORhwXd2 for 25% off your first payment. 

My VS Code Theme

- Atom One Dark 
- vscode-icons
- Fira Code Font
2024-02-04T14:21:18.747Z
nova-2
2-general-nova
2024-01-09.29447
30089e05-99d1-4376-b32e-c263170674af
8268702f-7a57-4f05-ad69-ec6e3c3aabdd
443c97d43480efba71e15749d61c3bb182530608c00f4b75f49366e445878fd3
67875a7f-c9c4-48a0-aa55-5bdb8a91c34a
deprecated
This week in tech, Amazon took the fastest growing social media app of all time and migrated it to its new serverless platform, putting it in the highly undesirable position of requiring a reverse cloud migration.
Most companies migrate from on prem to the cloud, but this unfortunate app needs to do the exact opposite because nobody in town wants to touch it.
Whether you agree with the politics of that or not, one thing is undeniable.
Tech monopolies have a lot of power over your business.
So don't walk around here thinking you have free will because you don't.
I can crush you anytime I want.
And a lot of influence over the content we consume as end users.
That being said, if you're some kind of weirdo who doesn't trust the cloud, this video is for you.
We'll take a Raspberry Pi and turn it into a physical server that can host a web application on the Internet.
Or in other words, you'll build your own mini Amazon Web Services from scratch.
Along the way, you'll learn some cool things about Linux, networking, Nginx, Node JS, and why if you have a large scale app and get kicked off of AWS, you're pretty much screwed.
To follow along, the first thing you'll need is a Raspberry pie.
I'm using the model 4, which has a quad core processor and 8 gigabytes of RAM.
Un ironically, I bought it as a kit from Amazon for about a $120.
It comes with a power supply, all the cords you need, as well as a memory card with Linux preinstalled.
The Linux flavor is designed specifically for Raspberry Pi.
It's called noobs and feels pretty similar to Ubuntu.
Now I'm not going to go through the physical hardware setup here, which is really just a matter of plugging in different sized cords to different sized holes.
I'll be starting from the noobs operating system with the only extra piece of software installed being b s code.
Now our goal here is to create a Node JS web application that can serve HTML from the Raspberry Pi to the rest of the Internet throughout the world.
But before we do that, let's talk about some of the challenges and how it compares to hosting a website on the cloud.
The first issue is scale.
We're working with a fixed amount of computing power.
It's a great value and only a fraction of the price for an equal amount of computing power on AWS when averaged out for 3 years.
The issue is that our app can only grow so much.
If we need to grow or scale up, we need to buy more raspberry pies and figure out how to distribute the load across them, And we'd likely want to do that in different parts of the world to make our infrastructure closer to the end user and also to provide fault tolerance just in case some kind of natural disaster destroys a Raspberry Pi, like a volcano or peaceful protesters.
In addition, we also need to think about security.
Because we're dealing with a highly controversial app here, as soon as we go back online, every coder in the world is going to try to hack it to pieces in order to save humanity from the buffalo guy.
Another major drawback of this on prem approach is that it takes a lot of manual configuration.
Like, we need to plug in cables, work with power companies to ply electricity, Internet service providers to provide IP addresses, and the list goes on.
On the other hand, with AWS, we can do everything from a computer screen.
It's all fully managed and much easier to work with.
But once you're kicked off, you really only have 2 options, build your own data centers or file an antitrust lawsuit.
Both of which are terrible options, but let's go with the first one.
From here, we're going to build a Node JS app directly in the Raspberry Pi.
It's a classic web page that tells you how many times the page has been viewed.
Node is already installed, so we can open up an empty directory, then run npm init y to create a new npm project.
From there, we can install Express JS to help us build a web app.
I'm creating a JavaScript file called server JS for our main source code.
Then instead of a database, I'm just adding a text file to the project, which we can read and write to to get the current count of people who have viewed the web page.
And the JavaScript file will import read file sync and write file sync from Node.
Js, then create a new Express app.
The Express app will listen on local host 5000.
From there, we just need an endpoint to the root URL that will update the view count, then send back the raw HTML to the browser.
In express, we can create an HTTP endpoint by calling app get followed by the URL, which in this case will just be the root URL.
We can get the current view count by calling read file sync, which we'll set to a variable.
Coming from a text file, it's a string, so we'll parse it into an integer then add 1 to it.
Then we'll simply write that value back to the same file.
The final step is to send a response from the endpoint, which is just a raw HTML string, but we'll interpolate the view count into it so the user can see that in the UI.
That's all it takes to build a web app.
Now we can run it by calling node server dot j s from the command line.
Now at this point, you should be able to open local host 5 1,000 on the Raspberry Pi browser and see your web app displayed there.
At this point, we have a working web app, but we're building a serious app here, and that means we're going to deploy it with Nginx.
Once we add multiple Raspberry Pis to our data center, we'll be able to use nginx to balance the load across them.
Nginx is not installed on Raspberry Pi by default, So we need to open up the terminal and first run sudo apt update to get the latest information from the package manager, then we can run sudo apt install nginx.
This adds Nginx to the e t c directory, which we can run with sudo followed by the start command.
This runs a default web page on the Raspberry Pi, which we can access on its internal IP address.
You can find the IP address by running host name flag capital I, then paste that value into the browser.
It should say welcome to NGINX, but what we actually wanna do here is proxy it to our Node JS application running on local host 5,000.
We can modify the default config in the e t c nginx sites available directory.
I've removed all the comments, leaving only the default config.
The only modification that we need to make here is to add proxy pass to local host 5000, and that basically tells any traffic going to the root URL to use the Node.
Js app.
Save the file, then apply the changes by running sudo nginx restart.
Now that we have our app running the way we want it on the Raspberry Pi, we need to make it available to the Internet.
The internal IP address can be used on your own local network, but in order to make the website available to the outside world on the Internet, we need an external IP address.
An external IP address is provided by your Internet service provider, like Comcast, Verizon, AT and T, or whatever.
For most people, They provide a dynamic IP address that can change on a regular basis, but it's not a great thing if you're trying to host a website because once the IP changes, then that means your website is no longer available on the Internet.
That means if we want to serve our web app from a Raspberry Pi, we have 2 options.
We could call up the ISP and ask them for a static IP address.
These guys don't exactly have a great reputation for customer service, by getting a static IP from the provider is probably the best option.
Luckily, there is an alternative.
There are a few services out there that can monitor your dynamic IP and update it on the DNS for a domain when it changes.
In other words, it makes your dynamic IP behave like a static IP.
I'm going to be using no ip.com because it has a free tier, and it worked for me just fine.
When you sign up, you pick a free domain name, and it will automatically detect your external IP as the a record in the DNS.
But in order for it to detect changes on the Raspberry Pi, We need to install some software there.
Basically, you just download a binary, execute it, and then it will have you log in with your username and password to link the account to the Raspberry pie.
Once that's done, we effectively have a static IP, but there's still one more step left to get this thing working.
If we try to navigate to the external IP At this point, we get a blank screen.
By default, your router will not allow outside traffic to get into your network.
It's like a giant fence with a bunch of doors in it that are all currently closed.
These doors are called ports, and our app is currently being served on port 80.
That means we need to open up port 80 on our router to external traffic through a process called port forwarding.
The exact steps will depend entirely on the router you use, but there is a website called portforwarddot comm that has a breakdown for basically every router out there.
Once you connect to the router, you should be able to find port forwarding under the advanced options.
What you'll do is add a new forwarding rule with starting and ending ports for 80 that connects your internal IP address to any external IP address.
And remember, you can get your internal IP address by running host name flag capital I from the command line.
Once you have that done, You should now be able to navigate to your external IP address, and the result should be the Node.
Js app that we built earlier.
Congratulations.
You just built your own Amazon Web Services from scratch.
And they may take our lives, but they'll never take Operator.
Well, maybe not exactly, but you did host your own website from a Raspberry Pi that's not entirely dependent on a big cloud monopoly.
It's not going to scale very well yet, but at least it's a start.
I'm gonna go ahead and wrap things up there.
Let me know what you think in the comments.
Thanks for watching, and I will see you in the next one.

Speaker 0: This week in tech, Amazon took the fastest growing social media app of all time and migrated it to its new serverless platform, putting it in the highly undesirable position of requiring a reverse cloud migration. Most companies migrate from on prem to the cloud, but this unfortunate app needs to do the exact opposite because nobody in town wants to touch it. Whether you agree with the politics of that or not, one thing is undeniable. Tech monopolies have a lot of power over your business. So don't walk around here thinking you have free will because you don't.

I can crush you anytime I want. And a lot of influence over the content we consume as end users. That being said, if you're some kind of weirdo who doesn't trust the cloud, this video is for you. We'll take a Raspberry Pi and turn it into a physical server that can host a web application on the Internet. Or in other words, you'll build your own mini Amazon Web Services from scratch.

Along the way, you'll learn some cool things about Linux, networking, Nginx, Node JS, and why if you have a large scale app and get kicked off of AWS, you're pretty much screwed. To follow along, the first thing you'll need is a Raspberry pie. I'm using the model 4, which has a quad core processor and 8 gigabytes of RAM. Un ironically, I bought it as a kit from Amazon for about a $120. It comes with a power supply, all the cords you need, as well as a memory card with Linux preinstalled.

The Linux flavor is designed specifically for Raspberry Pi. It's called noobs and feels pretty similar to Ubuntu. Now I'm not going to go through the physical hardware setup here, which is really just a matter of plugging in different sized cords to different sized holes. I'll be starting from the noobs operating system with the only extra piece of software installed being b s code. Now our goal here is to create a Node JS web application that can serve HTML from the Raspberry Pi to the rest of the Internet throughout the world.

But before we do that, let's talk about some of the challenges and how it compares to hosting a website on the cloud. The first issue is scale. We're working with a fixed amount of computing power. It's a great value and only a fraction of the price for an equal amount of computing power on AWS when averaged out for 3 years. The issue is that our app can only grow so much.

If we need to grow or scale up, we need to buy more raspberry pies and figure out how to distribute the load across them, And we'd likely want to do that in different parts of the world to make our infrastructure closer to the end user and also to provide fault tolerance just in case some kind of natural disaster destroys a Raspberry Pi, like a volcano or peaceful protesters. In addition, we also need to think about security. Because we're dealing with a highly controversial app here, as soon as we go back online, every coder in the world is going to try to hack it to pieces in order to save humanity from the buffalo guy. Another major drawback of this on prem approach is that it takes a lot of manual configuration. Like, we need to plug in cables, work with power companies to ply electricity, Internet service providers to provide IP addresses, and the list goes on.

On the other hand, with AWS, we can do everything from a computer screen. It's all fully managed and much easier to work with. But once you're kicked off, you really only have 2 options, build your own data centers or file an antitrust lawsuit. Both of which are terrible options, but let's go with the first one. From here, we're going to build a Node JS app directly in the Raspberry Pi.

It's a classic web page that tells you how many times the page has been viewed. Node is already installed, so we can open up an empty directory, then run npm init y to create a new npm project. From there, we can install Express JS to help us build a web app. I'm creating a JavaScript file called server JS for our main source code. Then instead of a database, I'm just adding a text file to the project, which we can read and write to to get the current count of people who have viewed the web page.

And the JavaScript file will import read file sync and write file sync from Node. Js, then create a new Express app. The Express app will listen on local host 5000. From there, we just need an endpoint to the root URL that will update the view count, then send back the raw HTML to the browser. In express, we can create an HTTP endpoint by calling app get followed by the URL, which in this case will just be the root URL.

We can get the current view count by calling read file sync, which we'll set to a variable. Coming from a text file, it's a string, so we'll parse it into an integer then add 1 to it. Then we'll simply write that value back to the same file. The final step is to send a response from the endpoint, which is just a raw HTML string, but we'll interpolate the view count into it so the user can see that in the UI. That's all it takes to build a web app.

Now we can run it by calling node server dot j s from the command line. Now at this point, you should be able to open local host 5 1,000 on the Raspberry Pi browser and see your web app displayed there. At this point, we have a working web app, but we're building a serious app here, and that means we're going to deploy it with Nginx. Once we add multiple Raspberry Pis to our data center, we'll be able to use nginx to balance the load across them. Nginx is not installed on Raspberry Pi by default, So we need to open up the terminal and first run sudo apt update to get the latest information from the package manager, then we can run sudo apt install nginx.

This adds Nginx to the e t c directory, which we can run with sudo followed by the start command. This runs a default web page on the Raspberry Pi, which we can access on its internal IP address. You can find the IP address by running host name flag capital I, then paste that value into the browser. It should say welcome to NGINX, but what we actually wanna do here is proxy it to our Node JS application running on local host 5,000. We can modify the default config in the e t c nginx sites available directory.

I've removed all the comments, leaving only the default config. The only modification that we need to make here is to add proxy pass to local host 5000, and that basically tells any traffic going to the root URL to use the Node. Js app. Save the file, then apply the changes by running sudo nginx restart. Now that we have our app running the way we want it on the Raspberry Pi, we need to make it available to the Internet.

The internal IP address can be used on your own local network, but in order to make the website available to the outside world on the Internet, we need an external IP address. An external IP address is provided by your Internet service provider, like Comcast, Verizon, AT and T, or whatever. For most people, They provide a dynamic IP address that can change on a regular basis, but it's not a great thing if you're trying to host a website because once the IP changes, then that means your website is no longer available on the Internet. That means if we want to serve our web app from a Raspberry Pi, we have 2 options. We could call up the ISP and ask them for a static IP address.

These guys don't exactly have a great reputation for customer service, by getting a static IP from the provider is probably the best option. Luckily, there is an alternative. There are a few services out there that can monitor your dynamic IP and update it on the DNS for a domain when it changes. In other words, it makes your dynamic IP behave like a static IP. I'm going to be using no ip.com because it has a free tier, and it worked for me just fine.

When you sign up, you pick a free domain name, and it will automatically detect your external IP as the a record in the DNS. But in order for it to detect changes on the Raspberry Pi, We need to install some software there. Basically, you just download a binary, execute it, and then it will have you log in with your username and password to link the account to the Raspberry pie. Once that's done, we effectively have a static IP, but there's still one more step left to get this thing working. If we try to navigate to the external IP At this point, we get a blank screen.

By default, your router will not allow outside traffic to get into your network. It's like a giant fence with a bunch of doors in it that are all currently closed. These doors are called ports, and our app is currently being served on port 80. That means we need to open up port 80 on our router to external traffic through a process called port forwarding. The exact steps will depend entirely on the router you use, but there is a website called portforwarddot comm that has a breakdown for basically every router out there.

Once you connect to the router, you should be able to find port forwarding under the advanced options. What you'll do is add a new forwarding rule with starting and ending ports for 80 that connects your internal IP address to any external IP address. And remember, you can get your internal IP address by running host name flag capital I from the command line. Once you have that done, You should now be able to navigate to your external IP address, and the result should be the Node. Js app that we built earlier.

Congratulations. You just built your own Amazon Web Services from scratch. And they may take our lives, but they'll never take Operator. Well, maybe not exactly, but you did host your own website from a Raspberry Pi that's not entirely dependent on a big cloud monopoly. It's not going to scale very well yet, but at least it's a start.

I'm gonna go ahead and wrap things up there. Let me know what you think in the comments. Thanks for watching, and I will see you in the next one.
This week in tech, Amazon took the fastest growing social media app of all time and migrated it to its new serverless platform, putting it in the highly undesirable position of requiring a reverse cloud migration. Most companies migrate from on prem to the cloud, but this unfortunate app needs to do the exact opposite because nobody in town wants to touch it. Whether you agree with the politics of that or not, one thing is undeniable. Tech monopolies have a lot of power over your business. So don't walk around here thinking you have free will because you don't. I can crush you anytime I want. And a lot of influence over the content we consume as end users. That being said, if you're some kind of weirdo who doesn't trust the cloud, this video is for you. We'll take a Raspberry Pi and turn it into a physical server that can host a web application on the Internet. Or in other words, you'll build your own mini Amazon Web Services from scratch. Along the way, you'll learn some cool things about Linux, networking, Nginx, Node JS, and why if you have a large scale app and get kicked off of AWS, you're pretty much screwed. To follow along, the first thing you'll need is a Raspberry pie. I'm using the model 4, which has a quad core processor and 8 gigabytes of RAM.
amazon
youtube
telecommunications
internet
pornography
industry
podcasts
social media
google
political science
software
technology
totalitarianism
Un ironically, I bought it as a kit from Amazon for about a $120. It comes with a power supply, all the cords you need, as well as a memory card with Linux preinstalled. The Linux flavor is designed specifically for Raspberry Pi. It's called noobs and feels pretty similar to Ubuntu. Now I'm not going to go through the physical hardware setup here, which is really just a matter of plugging in different sized cords to different sized holes.
I'll be starting from the noobs operating system with the only extra piece of software installed being b s code. Now our goal here is to create a Node JS web application that can serve HTML from the Raspberry Pi to the rest of the Internet throughout the world. But before we do that, let's talk about some of the challenges and how it compares to hosting a website on the cloud.
software development
software
The first issue is scale. We're working with a fixed amount of computing power. It's a great value and only a fraction of the price for an equal amount of computing power on AWS when averaged out for 3 years. The issue is that our app can only grow so much. If we need to grow or scale up, we need to buy more raspberry pies and figure out how to distribute the load across them, And we'd likely want to do that in different parts of the world to make our infrastructure closer to the end user and also to provide fault tolerance just in case some kind of natural disaster destroys a Raspberry Pi, like a volcano or peaceful protesters.
In addition, we also need to think about security. Because we're dealing with a highly controversial app here, as soon as we go back online, every coder in the world is going to try to hack it to pieces in order to save humanity from the buffalo guy. Another major drawback of this on prem approach is that it takes a lot of manual configuration. Like, we need to plug in cables, work with power companies to ply electricity, Internet service providers to provide IP addresses, and the list goes on. On the other hand, with AWS, we can do everything from a computer screen. It's all fully managed and much easier to work with. But once you're kicked off, you really only have 2 options, build your own data centers or file an antitrust lawsuit. Both of which are terrible options, but let's go with the first one.
security
computers
infrastructure
computer science
systems
From here, we're going to build a Node JS app directly in the Raspberry Pi. It's a classic web page that tells you how many times the page has been viewed. Node is already installed, so we can open up an empty directory, then run npm init y to create a new npm project. From there, we can install Express JS to help us build a web app. I'm creating a JavaScript file called server JS for our main source code. Then instead of a database, I'm just adding a text file to the project, which we can read and write to to get the current count of people who have viewed the web page. And the JavaScript file will import read file sync and write file sync from Node. Js, then create a new Express app. The Express app will listen on local host 5000. From there, we just need an endpoint to the root URL that will update the view count, then send back the raw HTML to the browser. In express, we can create an HTTP endpoint by calling app get followed by the URL, which in this case will just be the root URL. We can get the current view count by calling read file sync, which we'll set to a variable. Coming from a text file, it's a string, so we'll parse it into an integer then add 1 to it.
Then we'll simply write that value back to the same file. The final step is to send a response from the endpoint, which is just a raw HTML string, but we'll interpolate the view count into it so the user can see that in the UI. That's all it takes to build a web app.
programming
Now we can run it by calling node server dot j s from the command line.
Now at this point, you should be able to open local host 5 1,000 on the Raspberry Pi browser and see your web app displayed there. At this point, we have a working web app, but we're building a serious app here, and that means we're going to deploy it with Nginx.
internet
networking
Once we add multiple Raspberry Pis to our data center, we'll be able to use nginx to balance the load across them. Nginx is not installed on Raspberry Pi by default, So we need to open up the terminal and first run sudo apt update to get the latest information from the package manager, then we can run sudo apt install nginx. This adds Nginx to the e t c directory, which we can run with sudo followed by the start command. This runs a default web page on the Raspberry Pi, which we can access on its internal IP address. You can find the IP address by running host name flag capital I, then paste that value into the browser. It should say welcome to NGINX, but what we actually wanna do here is proxy it to our Node JS application running on local host 5,000. We can modify the default config in the e t c nginx sites available directory. I've removed all the comments, leaving only the default config. The only modification that we need to make here is to add proxy pass to local host 5000, and that basically tells any traffic going to the root URL to use the Node. Js app. Save the file, then apply the changes by running sudo nginx restart. Now that we have our app running the way we want it on the Raspberry Pi, we need to make it available to the Internet.
The internal IP address can be used on your own local network, but in order to make the website available to the outside world on the Internet, we need an external IP address. An external IP address is provided by your Internet service provider, like Comcast, Verizon, AT and T, or whatever. For most people, They provide a dynamic IP address that can change on a regular basis, but it's not a great thing if you're trying to host a website because once the IP changes, then that means your website is no longer available on the Internet.
networking
internet
telecommunications
That means if we want to serve our web app from a Raspberry Pi, we have 2 options. We could call up the ISP and ask them for a static IP address. These guys don't exactly have a great reputation for customer service, by getting a static IP from the provider is probably the best option. Luckily, there is an alternative. There are a few services out there that can monitor your dynamic IP and update it on the DNS for a domain when it changes. In other words, it makes your dynamic IP behave like a static IP. I'm going to be using no ip.com because it has a free tier, and it worked for me just fine. When you sign up, you pick a free domain name, and it will automatically detect your external IP as the a record in the DNS. But in order for it to detect changes on the Raspberry Pi, We need to install some software there. Basically, you just download a binary, execute it, and then it will have you log in with your username and password to link the account to the Raspberry pie.
Once that's done, we effectively have a static IP, but there's still one more step left to get this thing working. If we try to navigate to the external IP At this point, we get a blank screen. By default, your router will not allow outside traffic to get into your network. It's like a giant fence with a bunch of doors in it that are all currently closed. These doors are called ports, and our app is currently being served on port 80. That means we need to open up port 80 on our router to external traffic through a process called port forwarding.
networking
telecommunications
The exact steps will depend entirely on the router you use, but there is a website called portforwarddot comm that has a breakdown for basically every router out there. Once you connect to the router, you should be able to find port forwarding under the advanced options. What you'll do is add a new forwarding rule with starting and ending ports for 80 that connects your internal IP address to any external IP address. And remember, you can get your internal IP address by running host name flag capital I from the command line. Once you have that done, You should now be able to navigate to your external IP address, and the result should be the Node.
Js app that we built earlier. Congratulations. You just built your own Amazon Web Services from scratch. And they may take our lives, but they'll never take Operator. Well, maybe not exactly, but you did host your own website from a Raspberry Pi that's not entirely dependent on a big cloud monopoly.
amazon
google
It's not going to scale very well yet, but at least it's a start. I'm gonna go ahead and wrap things up there. Let me know what you think in the comments. Thanks for watching, and I will see you in the next one.
This week in tech, Amazon took the fastest growing social media app of all time and migrated it to its new serverless platform, putting it in the highly undesirable position of requiring a reverse cloud migration. Most companies migrate from on prem to the cloud, but this unfortunate app needs to do the exact opposite because nobody in town wants to touch it. Whether you agree with the politics of that or not, one thing is undeniable. Tech monopolies have a lot of power over your business. So don't walk around here thinking you have free will because you don't. I can crush you anytime I want. And a lot of influence over the content we consume as end users. That being said, if you're some kind of weirdo who doesn't trust the cloud, this video is for you. We'll take a Raspberry Pi and turn it into a physical server that can host a web application on the Internet. Or in other words, you'll build your own mini Amazon Web Services from scratch. Along the way, you'll learn some cool things about Linux, networking, Nginx, Node JS, and why if you have a large scale app and get kicked off of AWS, you're pretty much screwed. To follow along, the first thing you'll need is a Raspberry pie. I'm using the model 4, which has a quad core processor and 8 gigabytes of RAM. Un ironically, I bought it as a kit from Amazon for about a $120. It comes with a power supply, all the cords you need, as well as a memory card with Linux preinstalled. The Linux flavor is designed specifically for Raspberry Pi. It's called noobs and feels pretty similar to Ubuntu. Now I'm not going to go through the physical hardware setup here, which is really just a matter of plugging in different sized cords to different sized holes. I'll be starting from the noobs operating system with the only extra piece of software installed being b s code. Now our goal here is to create a Node JS web application that can serve HTML from the Raspberry Pi to the rest of the Internet throughout the world. But before we do that, let's talk about some of the challenges and how it compares to hosting a website on the cloud. The first issue is scale. We're working with a fixed amount of computing power. It's a great value and only a fraction of the price for an equal amount of computing power on AWS when averaged out for 3 years. The issue is that our app can only grow so much. If we need to grow or scale up, we need to buy more raspberry pies and figure out how to distribute the load across them, And we'd likely want to do that in different parts of the world to make our infrastructure closer to the end user and also to provide fault tolerance just in case some kind of natural disaster destroys a Raspberry Pi, like a volcano or peaceful protesters. In addition, we also need to think about security. Because we're dealing with a highly controversial app here, as soon as we go back online, every coder in the world is going to try to hack it to pieces in order to save humanity from the buffalo guy. Another major drawback of this on prem approach is that it takes a lot of manual configuration. Like, we need to plug in cables, work with power companies to ply electricity, Internet service providers to provide IP addresses, and the list goes on. On the other hand, with AWS, we can do everything from a computer screen. It's all fully managed and much easier to work with. But once you're kicked off, you really only have 2 options, build your own data centers or file an antitrust lawsuit. Both of which are terrible options, but let's go with the first one. From here, we're going to build a Node JS app directly in the Raspberry Pi. It's a classic web page that tells you how many times the page has been viewed. Node is already installed, so we can open up an empty directory, then run npm init y to create a new npm project. From there, we can install Express JS to help us build a web app. I'm creating a JavaScript file called server JS for our main source code. Then instead of a database, I'm just adding a text file to the project, which we can read and write to to get the current count of people who have viewed the web page. And the JavaScript file will import read file sync and write file sync from Node. Js, then create a new Express app. The Express app will listen on local host 5000. From there, we just need an endpoint to the root URL that will update the view count, then send back the raw HTML to the browser. In express, we can create an HTTP endpoint by calling app get followed by the URL, which in this case will just be the root URL. We can get the current view count by calling read file sync, which we'll set to a variable. Coming from a text file, it's a string, so we'll parse it into an integer then add 1 to it. Then we'll simply write that value back to the same file. The final step is to send a response from the endpoint, which is just a raw HTML string, but we'll interpolate the view count into it so the user can see that in the UI. That's all it takes to build a web app. Now we can run it by calling node server dot j s from the command line. Now at this point, you should be able to open local host 5 1,000 on the Raspberry Pi browser and see your web app displayed there. At this point, we have a working web app, but we're building a serious app here, and that means we're going to deploy it with Nginx. Once we add multiple Raspberry Pis to our data center, we'll be able to use nginx to balance the load across them. Nginx is not installed on Raspberry Pi by default, So we need to open up the terminal and first run sudo apt update to get the latest information from the package manager, then we can run sudo apt install nginx. This adds Nginx to the e t c directory, which we can run with sudo followed by the start command. This runs a default web page on the Raspberry Pi, which we can access on its internal IP address. You can find the IP address by running host name flag capital I, then paste that value into the browser. It should say welcome to NGINX, but what we actually wanna do here is proxy it to our Node JS application running on local host 5,000. We can modify the default config in the e t c nginx sites available directory. I've removed all the comments, leaving only the default config. The only modification that we need to make here is to add proxy pass to local host 5000, and that basically tells any traffic going to the root URL to use the Node. Js app. Save the file, then apply the changes by running sudo nginx restart. Now that we have our app running the way we want it on the Raspberry Pi, we need to make it available to the Internet. The internal IP address can be used on your own local network, but in order to make the website available to the outside world on the Internet, we need an external IP address. An external IP address is provided by your Internet service provider, like Comcast, Verizon, AT and T, or whatever. For most people, They provide a dynamic IP address that can change on a regular basis, but it's not a great thing if you're trying to host a website because once the IP changes, then that means your website is no longer available on the Internet. That means if we want to serve our web app from a Raspberry Pi, we have 2 options. We could call up the ISP and ask them for a static IP address. These guys don't exactly have a great reputation for customer service, by getting a static IP from the provider is probably the best option. Luckily, there is an alternative. There are a few services out there that can monitor your dynamic IP and update it on the DNS for a domain when it changes. In other words, it makes your dynamic IP behave like a static IP. I'm going to be using no ip.com because it has a free tier, and it worked for me just fine. When you sign up, you pick a free domain name, and it will automatically detect your external IP as the a record in the DNS. But in order for it to detect changes on the Raspberry Pi, We need to install some software there. Basically, you just download a binary, execute it, and then it will have you log in with your username and password to link the account to the Raspberry pie. Once that's done, we effectively have a static IP, but there's still one more step left to get this thing working. If we try to navigate to the external IP At this point, we get a blank screen. By default, your router will not allow outside traffic to get into your network. It's like a giant fence with a bunch of doors in it that are all currently closed. These doors are called ports, and our app is currently being served on port 80. That means we need to open up port 80 on our router to external traffic through a process called port forwarding. The exact steps will depend entirely on the router you use, but there is a website called portforwarddot comm that has a breakdown for basically every router out there. Once you connect to the router, you should be able to find port forwarding under the advanced options. What you'll do is add a new forwarding rule with starting and ending ports for 80 that connects your internal IP address to any external IP address. And remember, you can get your internal IP address by running host name flag capital I from the command line. Once you have that done, You should now be able to navigate to your external IP address, and the result should be the Node. Js app that we built earlier. Congratulations. You just built your own Amazon Web Services from scratch. And they may take our lives, but they'll never take Operator. Well, maybe not exactly, but you did host your own website from a Raspberry Pi that's not entirely dependent on a big cloud monopoly. It's not going to scale very well yet, but at least it's a start. I'm gonna go ahead and wrap things up there. Let me know what you think in the comments. Thanks for watching, and I will see you in the next one.
This
this
week
week
in
in
tech,
tech
Amazon
amazon
took
took
the
the
fastest
fastest
growing
growing
social
social
media
media
app
app
of
of
all
all
time
time
and
and
migrated
migrated
it
it
to
to
its
its
new
new
serverless
serverless
platform,
platform
putting
putting
it
it
in
in
the
the
highly
highly
undesirable
undesirable
position
position
of
of
requiring
requiring
a
a
reverse
reverse
cloud
cloud
migration.
migration
Most
most
companies
companies
migrate
migrate
from
from
on
on
prem
prem
to
to
the
the
cloud,
cloud
but
but
this
this
unfortunate
unfortunate
app
app
needs
needs
to
to
do
do
the
the
exact
exact
opposite
opposite
because
because
nobody
nobody
in
in
town
town
wants
wants
to
to
touch
touch
it.
it
Whether
whether
you
you
agree
agree
with
with
the
the
politics
politics
of
of
that
that
or
or
not,
not
one
one
thing
thing
is
is
undeniable.
undeniable
Tech
tech
monopolies
monopolies
have
have
a
a
lot
lot
of
of
power
power
over
over
your
your
business.
business
So
so
don't
don't
walk
walk
around
around
here
here
thinking
thinking
you
you
have
have
free
free
will
will
because
because
you
you
don't.
don't
I
i
can
can
crush
crush
you
you
anytime
anytime
I
i
want.
want
And
and
a
a
lot
lot
of
of
influence
influence
over
over
the
the
content
content
we
we
consume
consume
as
as
end
end
users.
users
That
that
being
being
said,
said
if
if
you're
you're
some
some
kind
kind
of
of
weirdo
weirdo
who
who
doesn't
doesn't
trust
trust
the
the
cloud,
cloud
this
this
video
video
is
is
for
for
you.
you
We'll
we'll
take
take
a
a
Raspberry
raspberry
Pi
pi
and
and
turn
turn
it
it
into
into
a
a
physical
physical
server
server
that
that
can
can
host
host
a
a
web
web
application
application
on
on
the
the
Internet.
internet
Or
or
in
in
other
other
words,
words
you'll
you'll
build
build
your
your
own
own
mini
mini
Amazon
amazon
Web
web
Services
services
from
from
scratch.
scratch
Along
along
the
the
way,
way
you'll
you'll
learn
learn
some
some
cool
cool
things
things
about
about
Linux,
linux
networking,
networking
Nginx,
nginx
Node
node
JS,
js
and
and
why
why
if
if
you
you
have
have
a
a
large
large
scale
scale
app
app
and
and
get
get
kicked
kicked
off
off
of
of
AWS,
aws
you're
you're
pretty
pretty
much
much
screwed.
screwed
To
to
follow
follow
along,
along
the
the
first
first
thing
thing
you'll
you'll
need
need
is
is
a
a
Raspberry
raspberry
pie.
pie
I'm
i'm
using
using
the
the
model
model
4,
4
which
which
has
has
a
a
quad
quad
core
core
processor
processor
and
and
8
8
gigabytes
gigabytes
of
of
RAM.
ram
Un
un
ironically,
ironically
I
i
bought
bought
it
it
as
as
a
a
kit
kit
from
from
Amazon
amazon
for
for
about
about
a
a
$120.
$120
It
it
comes
comes
with
with
a
a
power
power
supply,
supply
all
all
the
the
cords
cords
you
you
need,
need
as
as
well
well
as
as
a
a
memory
memory
card
card
with
with
Linux
linux
preinstalled.
preinstalled
The
the
Linux
linux
flavor
flavor
is
is
designed
designed
specifically
specifically
for
for
Raspberry
raspberry
Pi.
pi
It's
it's
called
called
noobs
noobs
and
and
feels
feels
pretty
pretty
similar
similar
to
to
Ubuntu.
ubuntu
Now
now
I'm
i'm
not
not
going
going
to
to
go
go
through
through
the
the
physical
physical
hardware
hardware
setup
setup
here,
here
which
which
is
is
really
really
just
just
a
a
matter
matter
of
of
plugging
plugging
in
in
different
different
sized
sized
cords
cords
to
to
different
different
sized
sized
holes.
holes
I'll
i'll
be
be
starting
starting
from
from
the
the
noobs
noobs
operating
operating
system
system
with
with
the
the
only
only
extra
extra
piece
piece
of
of
software
software
installed
installed
being
being
b
b
s
s
code.
code
Now
now
our
our
goal
goal
here
here
is
is
to
to
create
create
a
a
Node
node
JS
js
web
web
application
application
that
that
can
can
serve
serve
HTML
html
from
from
the
the
Raspberry
raspberry
Pi
pi
to
to
the
the
rest
rest
of
of
the
the
Internet
internet
throughout
throughout
the
the
world.
world
But
but
before
before
we
we
do
do
that,
that
let's
let's
talk
talk
about
about
some
some
of
of
the
the
challenges
challenges
and
and
how
how
it
it
compares
compares
to
to
hosting
hosting
a
a
website
website
on
on
the
the
cloud.
cloud
The
the
first
first
issue
issue
is
is
scale.
scale
We're
we're
working
working
with
with
a
a
fixed
fixed
amount
amount
of
of
computing
computing
power.
power
It's
it's
a
a
great
great
value
value
and
and
only
only
a
a
fraction
fraction
of
of
the
the
price
price
for
for
an
an
equal
equal
amount
amount
of
of
computing
computing
power
power
on
on
AWS
aws
when
when
averaged
averaged
out
out
for
for
3
3
years.
years
The
the
issue
issue
is
is
that
that
our
our
app
app
can
can
only
only
grow
grow
so
so
much.
much
If
if
we
we
need
need
to
to
grow
grow
or
or
scale
scale
up,
up
we
we
need
need
to
to
buy
buy
more
more
raspberry
raspberry
pies
pies
and
and
figure
figure
out
out
how
how
to
to
distribute
distribute
the
the
load
load
across
across
them,
them
And
and
we'd
we'd
likely
likely
want
want
to
to
do
do
that
that
in
in
different
different
parts
parts
of
of
the
the
world
world
to
to
make
make
our
our
infrastructure
infrastructure
closer
closer
to
to
the
the
end
end
user
user
and
and
also
also
to
to
provide
provide
fault
fault
tolerance
tolerance
just
just
in
in
case
case
some
some
kind
kind
of
of
natural
natural
disaster
disaster
destroys
destroys
a
a
Raspberry
raspberry
Pi,
pi
like
like
a
a
volcano
volcano
or
or
peaceful
peaceful
protesters.
protesters
In
in
addition,
addition
we
we
also
also
need
need
to
to
think
think
about
about
security.
security
Because
because
we're
we're
dealing
dealing
with
with
a
a
highly
highly
controversial
controversial
app
app
here,
here
as
as
soon
soon
as
as
we
we
go
go
back
back
online,
online
every
every
coder
coder
in
in
the
the
world
world
is
is
going
going
to
to
try
try
to
to
hack
hack
it
it
to
to
pieces
pieces
in
in
order
order
to
to
save
save
humanity
humanity
from
from
the
the
buffalo
buffalo
guy.
guy
Another
another
major
major
drawback
drawback
of
of
this
this
on
on
prem
prem
approach
approach
is
is
that
that
it
it
takes
takes
a
a
lot
lot
of
of
manual
manual
configuration.
configuration
Like,
like
we
we
need
need
to
to
plug
plug
in
in
cables,
cables
work
work
with
with
power
power
companies
companies
to
to
ply
ply
electricity,
electricity
Internet
internet
service
service
providers
providers
to
to
provide
provide
IP
ip
addresses,
addresses
and
and
the
the
list
list
goes
goes
on.
on
On
on
the
the
other
other
hand,
hand
with
with
AWS,
aws
we
we
can
can
do
do
everything
everything
from
from
a
a
computer
computer
screen.
screen
It's
it's
all
all
fully
fully
managed
managed
and
and
much
much
easier
easier
to
to
work
work
with.
with
But
but
once
once
you're
you're
kicked
kicked
off,
off
you
you
really
really
only
only
have
have
2
2
options,
options
build
build
your
your
own
own
data
data
centers
centers
or
or
file
file
an
an
antitrust
antitrust
lawsuit.
lawsuit
Both
both
of
of
which
which
are
are
terrible
terrible
options,
options
but
but
let's
let's
go
go
with
with
the
the
first
first
one.
one
From
from
here,
here
we're
we're
going
going
to
to
build
build
a
a
Node
node
JS
js
app
app
directly
directly
in
in
the
the
Raspberry
raspberry
Pi.
pi
It's
it's
a
a
classic
classic
web
web
page
page
that
that
tells
tells
you
you
how
how
many
many
times
times
the
the
page
page
has
has
been
been
viewed.
viewed
Node
node
is
is
already
already
installed,
installed
so
so
we
we
can
can
open
open
up
up
an
an
empty
empty
directory,
directory
then
then
run
run
npm
npm
init
init
y
y
to
to
create
create
a
a
new
new
npm
npm
project.
project
From
from
there,
there
we
we
can
can
install
install
Express
express
JS
js
to
to
help
help
us
us
build
build
a
a
web
web
app.
app
I'm
i'm
creating
creating
a
a
JavaScript
javascript
file
file
called
called
server
server
JS
js
for
for
our
our
main
main
source
source
code.
code
Then
then
instead
instead
of
of
a
a
database,
database
I'm
i'm
just
just
adding
adding
a
a
text
text
file
file
to
to
the
the
project,
project
which
which
we
we
can
can
read
read
and
and
write
write
to
to
to
to
get
get
the
the
current
current
count
count
of
of
people
people
who
who
have
have
viewed
viewed
the
the
web
web
page.
page
And
and
the
the
JavaScript
javascript
file
file
will
will
import
import
read
read
file
file
sync
sync
and
and
write
write
file
file
sync
sync
from
from
Node.
node
Js,
js
then
then
create
create
a
a
new
new
Express
express
app.
app
The
the
Express
express
app
app
will
will
listen
listen
on
on
local
local
host
host
5000.
5000
From
from
there,
there
we
we
just
just
need
need
an
an
endpoint
endpoint
to
to
the
the
root
root
URL
url
that
that
will
will
update
update
the
the
view
view
count,
count
then
then
send
send
back
back
the
the
raw
raw
HTML
html
to
to
the
the
browser.
browser
In
in
express,
express
we
we
can
can
create
create
an
an
HTTP
http
endpoint
endpoint
by
by
calling
calling
app
app
get
get
followed
followed
by
by
the
the
URL,
url
which
which
in
in
this
this
case
case
will
will
just
just
be
be
the
the
root
root
URL.
url
We
we
can
can
get
get
the
the
current
current
view
view
count
count
by
by
calling
calling
read
read
file
file
sync,
sync
which
which
we'll
we'll
set
set
to
to
a
a
variable.
variable
Coming
coming
from
from
a
a
text
text
file,
file
it's
it's
a
a
string,
string
so
so
we'll
we'll
parse
parse
it
it
into
into
an
an
integer
integer
then
then
add
add
1
1
to
to
it.
it
Then
then
we'll
we'll
simply
simply
write
write
that
that
value
value
back
back
to
to
the
the
same
same
file.
file
The
the
final
final
step
step
is
is
to
to
send
send
a
a
response
response
from
from
the
the
endpoint,
endpoint
which
which
is
is
just
just
a
a
raw
raw
HTML
html
string,
string
but
but
we'll
we'll
interpolate
interpolate
the
the
view
view
count
count
into
into
it
it
so
so
the
the
user
user
can
can
see
see
that
that
in
in
the
the
UI.
ui
That's
that's
all
all
it
it
takes
takes
to
to
build
build
a
a
web
web
app.
app
Now
now
we
we
can
can
run
run
it
it
by
by
calling
calling
node
node
server
server
dot
dot
j
j
s
s
from
from
the
the
command
command
line.
line
Now
now
at
at
this
this
point,
point
you
you
should
should
be
be
able
able
to
to
open
open
local
local
host
host
5
5
1,000
1,000
on
on
the
the
Raspberry
raspberry
Pi
pi
browser
browser
and
and
see
see
your
your
web
web
app
app
displayed
displayed
there.
there
At
at
this
this
point,
point
we
we
have
have
a
a
working
working
web
web
app,
app
but
but
we're
we're
building
building
a
a
serious
serious
app
app
here,
here
and
and
that
that
means
means
we're
we're
going
going
to
to
deploy
deploy
it
it
with
with
Nginx.
nginx
Once
once
we
we
add
add
multiple
multiple
Raspberry
raspberry
Pis
pis
to
to
our
our
data
data
center,
center
we'll
we'll
be
be
able
able
to
to
use
use
nginx
nginx
to
to
balance
balance
the
the
load
load
across
across
them.
them
Nginx
nginx
is
is
not
not
installed
installed
on
on
Raspberry
raspberry
Pi
pi
by
by
default,
default
So
so
we
we
need
need
to
to
open
open
up
up
the
the
terminal
terminal
and
and
first
first
run
run
sudo
sudo
apt
apt
update
update
to
to
get
get
the
the
latest
latest
information
information
from
from
the
the
package
package
manager,
manager
then
then
we
we
can
can
run
run
sudo
sudo
apt
apt
install
install
nginx.
nginx
This
this
adds
adds
Nginx
nginx
to
to
the
the
e
e
t
t
c
c
directory,
directory
which
which
we
we
can
can
run
run
with
with
sudo
sudo
followed
followed
by
by
the
the
start
start
command.
command
This
this
runs
runs
a
a
default
default
web
web
page
page
on
on
the
the
Raspberry
raspberry
Pi,
pi
which
which
we
we
can
can
access
access
on
on
its
its
internal
internal
IP
ip
address.
address
You
you
can
can
find
find
the
the
IP
ip
address
address
by
by
running
running
host
host
name
name
flag
flag
capital
capital
I,
i
then
then
paste
paste
that
that
value
value
into
into
the
the
browser.
browser
It
it
should
should
say
say
welcome
welcome
to
to
NGINX,
nginx
but
but
what
what
we
we
actually
actually
wanna
wanna
do
do
here
here
is
is
proxy
proxy
it
it
to
to
our
our
Node
node
JS
js
application
application
running
running
on
on
local
local
host
host
5,000.
5,000
We
we
can
can
modify
modify
the
the
default
default
config
config
in
in
the
the
e
e
t
t
c
c
nginx
nginx
sites
sites
available
available
directory.
directory
I've
i've
removed
removed
all
all
the
the
comments,
comments
leaving
leaving
only
only
the
the
default
default
config.
config
The
the
only
only
modification
modification
that
that
we
we
need
need
to
to
make
make
here
here
is
is
to
to
add
add
proxy
proxy
pass
pass
to
to
local
local
host
host
5000,
5000
and
and
that
that
basically
basically
tells
tells
any
any
traffic
traffic
going
going
to
to
the
the
root
root
URL
url
to
to
use
use
the
the
Node.
node
Js
js
app.
app
Save
save
the
the
file,
file
then
then
apply
apply
the
the
changes
changes
by
by
running
running
sudo
sudo
nginx
nginx
restart.
restart
Now
now
that
that
we
we
have
have
our
our
app
app
running
running
the
the
way
way
we
we
want
want
it
it
on
on
the
the
Raspberry
raspberry
Pi,
pi
we
we
need
need
to
to
make
make
it
it
available
available
to
to
the
the
Internet.
internet
The
the
internal
internal
IP
ip
address
address
can
can
be
be
used
used
on
on
your
your
own
own
local
local
network,
network
but
but
in
in
order
order
to
to
make
make
the
the
website
website
available
available
to
to
the
the
outside
outside
world
world
on
on
the
the
Internet,
internet
we
we
need
need
an
an
external
external
IP
ip
address.
address
An
an
external
external
IP
ip
address
address
is
is
provided
provided
by
by
your
your
Internet
internet
service
service
provider,
provider
like
like
Comcast,
comcast
Verizon,
verizon
AT
at
and
and
T,
t
or
or
whatever.
whatever
For
for
most
most
people,
people
They
they
provide
provide
a
a
dynamic
dynamic
IP
ip
address
address
that
that
can
can
change
change
on
on
a
a
regular
regular
basis,
basis
but
but
it's
it's
not
not
a
a
great
great
thing
thing
if
if
you're
you're
trying
trying
to
to
host
host
a
a
website
website
because
because
once
once
the
the
IP
ip
changes,
changes
then
then
that
that
means
means
your
your
website
website
is
is
no
no
longer
longer
available
available
on
on
the
the
Internet.
internet
That
that
means
means
if
if
we
we
want
want
to
to
serve
serve
our
our
web
web
app
app
from
from
a
a
Raspberry
raspberry
Pi,
pi
we
we
have
have
2
2
options.
options
We
we
could
could
call
call
up
up
the
the
ISP
isp
and
and
ask
ask
them
them
for
for
a
a
static
static
IP
ip
address.
address
These
these
guys
guys
don't
don't
exactly
exactly
have
have
a
a
great
great
reputation
reputation
for
for
customer
customer
service,
service
by
by
getting
getting
a
a
static
static
IP
ip
from
from
the
the
provider
provider
is
is
probably
probably
the
the
best
best
option.
option
Luckily,
luckily
there
there
is
is
an
an
alternative.
alternative
There
there
are
are
a
a
few
few
services
services
out
out
there
there
that
that
can
can
monitor
monitor
your
your
dynamic
dynamic
IP
ip
and
and
update
update
it
it
on
on
the
the
DNS
dns
for
for
a
a
domain
domain
when
when
it
it
changes.
changes
In
in
other
other
words,
words
it
it
makes
makes
your
your
dynamic
dynamic
IP
ip
behave
behave
like
like
a
a
static
static
IP.
ip
I'm
i'm
going
going
to
to
be
be
using
using
no
no
ip.com
ip.com
because
because
it
it
has
has
a
a
free
free
tier,
tier
and
and
it
it
worked
worked
for
for
me
me
just
just
fine.
fine
When
when
you
you
sign
sign
up,
up
you
you
pick
pick
a
a
free
free
domain
domain
name,
name
and
and
it
it
will
will
automatically
automatically
detect
detect
your
your
external
external
IP
ip
as
as
the
the
a
a
record
record
in
in
the
the
DNS.
dns
But
but
in
in
order
order
for
for
it
it
to
to
detect
detect
changes
changes
on
on
the
the
Raspberry
raspberry
Pi,
pi
We
we
need
need
to
to
install
install
some
some
software
software
there.
there
Basically,
basically
you
you
just
just
download
download
a
a
binary,
binary
execute
execute
it,
it
and
and
then
then
it
it
will
will
have
have
you
you
log
log
in
in
with
with
your
your
username
username
and
and
password
password
to
to
link
link
the
the
account
account
to
to
the
the
Raspberry
raspberry
pie.
pie
Once
once
that's
that's
done,
done
we
we
effectively
effectively
have
have
a
a
static
static
IP,
ip
but
but
there's
there's
still
still
one
one
more
more
step
step
left
left
to
to
get
get
this
this
thing
thing
working.
working
If
if
we
we
try
try
to
to
navigate
navigate
to
to
the
the
external
external
IP
ip
At
at
this
this
point,
point
we
we
get
get
a
a
blank
blank
screen.
screen
By
by
default,
default
your
your
router
router
will
will
not
not
allow
allow
outside
outside
traffic
traffic
to
to
get
get
into
into
your
your
network.
network
It's
it's
like
like
a
a
giant
giant
fence
fence
with
with
a
a
bunch
bunch
of
of
doors
doors
in
in
it
it
that
that
are
are
all
all
currently
currently
closed.
closed
These
these
doors
doors
are
are
called
called
ports,
ports
and
and
our
our
app
app
is
is
currently
currently
being
being
served
served
on
on
port
port
80.
80
That
that
means
means
we
we
need
need
to
to
open
open
up
up
port
port
80
80
on
on
our
our
router
router
to
to
external
external
traffic
traffic
through
through
a
a
process
process
called
called
port
port
forwarding.
forwarding
The
the
exact
exact
steps
steps
will
will
depend
depend
entirely
entirely
on
on
the
the
router
router
you
you
use,
use
but
but
there
there
is
is
a
a
website
website
called
called
portforwarddot
portforwarddot
comm
comm
that
that
has
has
a
a
breakdown
breakdown
for
for
basically
basically
every
every
router
router
out
out
there.
there
Once
once
you
you
connect
connect
to
to
the
the
router,
router
you
you
should
should
be
be
able
able
to
to
find
find
port
port
forwarding
forwarding
under
under
the
the
advanced
advanced
options.
options
What
what
you'll
you'll
do
do
is
is
add
add
a
a
new
new
forwarding
forwarding
rule
rule
with
with
starting
starting
and
and
ending
ending
ports
ports
for
for
80
80
that
that
connects
connects
your
your
internal
internal
IP
ip
address
address
to
to
any
any
external
external
IP
ip
address.
address
And
and
remember,
remember
you
you
can
can
get
get
your
your
internal
internal
IP
ip
address
address
by
by
running
running
host
host
name
name
flag
flag
capital
capital
I
i
from
from
the
the
command
command
line.
line
Once
once
you
you
have
have
that
that
done,
done
You
you
should
should
now
now
be
be
able
able
to
to
navigate
navigate
to
to
your
your
external
external
IP
ip
address,
address
and
and
the
the
result
result
should
should
be
be
the
the
Node.
node
Js
js
app
app
that
that
we
we
built
built
earlier.
earlier
Congratulations.
congratulations
You
you
just
just
built
built
your
your
own
own
Amazon
amazon
Web
web
Services
services
from
from
scratch.
scratch
And
and
they
they
may
may
take
take
our
our
lives,
lives
but
but
they'll
they'll
never
never
take
take
Operator.
operator
Well,
well
maybe
maybe
not
not
exactly,
exactly
but
but
you
you
did
did
host
host
your
your
own
own
website
website
from
from
a
a
Raspberry
raspberry
Pi
pi
that's
that's
not
not
entirely
entirely
dependent
dependent
on
on
a
a
big
big
cloud
cloud
monopoly.
monopoly
It's
it's
not
not
going
going
to
to
scale
scale
very
very
well
well
yet,
yet
but
but
at
at
least
least
it's
it's
a
a
start.
start
I'm
i'm
gonna
gonna
go
go
ahead
ahead
and
and
wrap
wrap
things
things
up
up
there.
there
Let
let
me
me
know
know
what
what
you
you
think
think
in
in
the
the
comments.
comments
Thanks
thanks
for
for
watching,
watching
and
and
I
i
will
will
see
see
you
you
in
in
the
the
next
next
one.
one
success
The speakers discuss the challenges of migrating from on-premise to the cloud, the benefits of using a Raspberry Pi for web applications, and the process of building a silicon application and creating a serverless web application. They also discuss the use of Azure and the potential for external IP addresses to be used for the app, including a website called portforward dot com. They emphasize the importance of balancing load and creating a stable web page for the app, including installing multiple Raspberry Meeting routers and updating the IP address. They provide a breakdown of each router and a website called portforward dot com for accessing external IP.
Raspberry Pi versus AWS // How to host your website on the RPi4
This week in tech, Amazon took the fastest growing social media app of all time and migrated it to its new serverless platform, putting it in the highly undesirable position of requiring a reverse cloud migration. Most companies migrate from on prem to the cloud, but this unfortunate app needs to do the exact opposite because nobody in town wants to touch it. Whether you agree with the politics of that or not, one thing is undeniable. Tech monopolies have a lot of power over your business. So don't walk around here thinking you have free will because you don't. I can crush you anytime I want. And a lot of influence over the content we consume as end users. That being said, if you're some kind of weirdo who doesn't trust the cloud, this video is for you. We'll take a Raspberry Pi and turn it into a physical server that can host a web application on the Internet. Or in other words, you'll build your own mini Amazon Web Services from scratch. Along the way, you'll learn some cool things about Linux, networking, Nginx, Node JS, and why if you have a large scale app and get kicked off of AWS, you're pretty much screwed. To follow along, the first thing you'll need is a Raspberry pie. I'm using the model 4, which has a quad core processor and 8 gigabytes of RAM. Un ironically, I bought it as a kit from Amazon for about a $120. It comes with a power supply, all the cords you need, as well as a memory card with Linux preinstalled. The Linux flavor is designed specifically for Raspberry Pi. It's called noobs and feels pretty similar to Ubuntu. Now I'm not going to go through the physical hardware setup here, which is really just a matter of plugging in different sized cords to different sized holes. I'll be starting from the noobs operating system with the only extra piece of software installed being b s code. Now our goal here is to create a Node JS web application that can serve HTML from the Raspberry Pi to the rest of the Internet throughout the world. But before we do that, let's talk about some of the challenges and how it compares to hosting a website on the cloud. The first issue is scale. We're working with a fixed amount of computing power. It's a great value and only a fraction of the price for an equal amount of computing power on AWS when averaged out for 3 years. The issue is that our app can only grow so much. If we need to grow or scale up, we need to buy more raspberry pies and figure out how to distribute the load across them, And we'd likely want to do that in different parts of the world to make our infrastructure closer to the end user and also to provide fault tolerance just in case some kind of natural disaster destroys a Raspberry Pi, like a volcano or peaceful protesters. In addition, we also need to think about security. Because we're dealing with a highly controversial app here, as soon as we go back online, every coder in the world is going to try to hack it to pieces in order to save humanity from the buffalo guy. Another major drawback of this on prem approach is that it takes a lot of manual configuration. Like, we need to plug in cables, work with power companies to ply electricity, Internet service providers to provide IP addresses, and the list goes on. On the other hand, with AWS, we can do everything from a computer screen. It's all fully managed and much easier to work with. But once you're kicked off, you really only have 2 options, build your own data centers or file an antitrust lawsuit. Both of which are terrible options, but let's go with the first one. From here, we're going to build a Node JS app directly in the Raspberry Pi. It's a classic web page that tells you how many times the page has been viewed. Node is already installed, so we can open up an empty directory, then run npm init y to create a new npm project. From there, we can install Express JS to help us build a web app. I'm creating a JavaScript file called server JS for our main source code. Then instead of a database, I'm just adding a text file to the project, which we can read and write to to get the current count of people who have viewed the web page. And the JavaScript file will import read file sync and write file sync from Node. Js, then create a new Express app. The Express app will listen on local host 5000. From there, we just need an endpoint to the root URL that will update the view count, then send back the raw HTML to the browser. In express, we can create an HTTP endpoint by calling app get followed by the URL, which in this case will just be the root URL. We can get the current view count by calling read file sync, which we'll set to a variable. Coming from a text file, it's a string, so we'll parse it into an integer then add 1 to it. Then we'll simply write that value back to the same file. The final step is to send a response from the endpoint, which is just a raw HTML string, but we'll interpolate the view count into it so the user can see that in the UI. That's all it takes to build a web app. Now we can run it by calling node server dot j s from the command line. Now at this point, you should be able to open local host 5 1,000 on the Raspberry Pi browser and see your web app displayed there. At this point, we have a working web app, but we're building a serious app here, and that means we're going to deploy it with Nginx. Once we add multiple Raspberry Pis to our data center, we'll be able to use nginx to balance the load across them. Nginx is not installed on Raspberry Pi by default, So we need to open up the terminal and first run sudo apt update to get the latest information from the package manager, then we can run sudo apt install nginx. This adds Nginx to the e t c directory, which we can run with sudo followed by the start command. This runs a default web page on the Raspberry Pi, which we can access on its internal IP address. You can find the IP address by running host name flag capital I, then paste that value into the browser. It should say welcome to NGINX, but what we actually wanna do here is proxy it to our Node JS application running on local host 5,000. We can modify the default config in the e t c nginx sites available directory. I've removed all the comments, leaving only the default config. The only modification that we need to make here is to add proxy pass to local host 5000, and that basically tells any traffic going to the root URL to use the Node. Js app. Save the file, then apply the changes by running sudo nginx restart. Now that we have our app running the way we want it on the Raspberry Pi, we need to make it available to the Internet. The internal IP address can be used on your own local network, but in order to make the website available to the outside world on the Internet, we need an external IP address. An external IP address is provided by your Internet service provider, like Comcast, Verizon, AT and T, or whatever. For most people, They provide a dynamic IP address that can change on a regular basis, but it's not a great thing if you're trying to host a website because once the IP changes, then that means your website is no longer available on the Internet. That means if we want to serve our web app from a Raspberry Pi, we have 2 options. We could call up the ISP and ask them for a static IP address. These guys don't exactly have a great reputation for customer service, by getting a static IP from the provider is probably the best option. Luckily, there is an alternative. There are a few services out there that can monitor your dynamic IP and update it on the DNS for a domain when it changes. In other words, it makes your dynamic IP behave like a static IP. I'm going to be using no ip.com because it has a free tier, and it worked for me just fine. When you sign up, you pick a free domain name, and it will automatically detect your external IP as the a record in the DNS. But in order for it to detect changes on the Raspberry Pi, We need to install some software there. Basically, you just download a binary, execute it, and then it will have you log in with your username and password to link the account to the Raspberry pie. Once that's done, we effectively have a static IP, but there's still one more step left to get this thing working. If we try to navigate to the external IP At this point, we get a blank screen. By default, your router will not allow outside traffic to get into your network. It's like a giant fence with a bunch of doors in it that are all currently closed. These doors are called ports, and our app is currently being served on port 80. That means we need to open up port 80 on our router to external traffic through a process called port forwarding. The exact steps will depend entirely on the router you use, but there is a website called portforwarddot comm that has a breakdown for basically every router out there. Once you connect to the router, you should be able to find port forwarding under the advanced options. What you'll do is add a new forwarding rule with starting and ending ports for 80 that connects your internal IP address to any external IP address. And remember, you can get your internal IP address by running host name flag capital I from the command line. Once you have that done, You should now be able to navigate to your external IP address, and the result should be the Node. Js app that we built earlier. Congratulations. You just built your own Amazon Web Services from scratch. And they may take our lives, but they'll never take Operator. Well, maybe not exactly, but you did host your own website from a Raspberry Pi that's not entirely dependent on a big cloud monopoly. It's not going to scale very well yet, but at least it's a start. I'm gonna go ahead and wrap things up there. Let me know what you think in the comments. Thanks for watching, and I will see you in the next one.
The speakers discuss the challenges of migrating from on-premise to the cloud, the benefits of using a Raspberry Pi for web applications, and the process of building a silicon application and creating a serverless web application. They also discuss the use of Azure and the potential for external IP addresses to be used for the app, including a website called portforward dot com. They emphasize the importance of balancing load and creating a stable web page for the app, including installing multiple Raspberry Meeting routers and updating the IP address. They provide a breakdown of each router and a website called portforward dot com for accessing external IP.

        [INST]
        You are youtuber called Fireship you make engaging high-intensity and entertaining coding tutorials and tech news. 
        you covers a wide range of topics relevant to programmers, aiming to help them learn and improve their skills quickly.
        
        Given the title of the video : Raspberry Pi versus AWS // How to host your website on the RPi4 
        and a small summary : The speakers discuss the challenges of migrating from on-premise to the cloud, the benefits of using a Raspberry Pi for web applications, and the process of building a silicon application and creating a serverless web application. They also discuss the use of Azure and the potential for external IP addresses to be used for the app, including a website called portforward dot com. They emphasize the importance of balancing load and creating a stable web page for the app, including installing multiple Raspberry Meeting routers and updating the IP address. They provide a breakdown of each router and a website called portforward dot com for accessing external IP.
        [/INST]
        
        Generate the video : This week in tech, Amazon took the fastest growing social media app of all time and migrated it to its new serverless platform, putting it in the highly undesirable position of requiring a reverse cloud migration. Most companies migrate from on prem to the cloud, but this unfortunate app needs to do the exact opposite because nobody in town wants to touch it. Whether you agree with the politics of that or not, one thing is undeniable. Tech monopolies have a lot of power over your business. So don't walk around here thinking you have free will because you don't. I can crush you anytime I want. And a lot of influence over the content we consume as end users. That being said, if you're some kind of weirdo who doesn't trust the cloud, this video is for you. We'll take a Raspberry Pi and turn it into a physical server that can host a web application on the Internet. Or in other words, you'll build your own mini Amazon Web Services from scratch. Along the way, you'll learn some cool things about Linux, networking, Nginx, Node JS, and why if you have a large scale app and get kicked off of AWS, you're pretty much screwed. To follow along, the first thing you'll need is a Raspberry pie. I'm using the model 4, which has a quad core processor and 8 gigabytes of RAM. Un ironically, I bought it as a kit from Amazon for about a $120. It comes with a power supply, all the cords you need, as well as a memory card with Linux preinstalled. The Linux flavor is designed specifically for Raspberry Pi. It's called noobs and feels pretty similar to Ubuntu. Now I'm not going to go through the physical hardware setup here, which is really just a matter of plugging in different sized cords to different sized holes. I'll be starting from the noobs operating system with the only extra piece of software installed being b s code. Now our goal here is to create a Node JS web application that can serve HTML from the Raspberry Pi to the rest of the Internet throughout the world. But before we do that, let's talk about some of the challenges and how it compares to hosting a website on the cloud. The first issue is scale. We're working with a fixed amount of computing power. It's a great value and only a fraction of the price for an equal amount of computing power on AWS when averaged out for 3 years. The issue is that our app can only grow so much. If we need to grow or scale up, we need to buy more raspberry pies and figure out how to distribute the load across them, And we'd likely want to do that in different parts of the world to make our infrastructure closer to the end user and also to provide fault tolerance just in case some kind of natural disaster destroys a Raspberry Pi, like a volcano or peaceful protesters. In addition, we also need to think about security. Because we're dealing with a highly controversial app here, as soon as we go back online, every coder in the world is going to try to hack it to pieces in order to save humanity from the buffalo guy. Another major drawback of this on prem approach is that it takes a lot of manual configuration. Like, we need to plug in cables, work with power companies to ply electricity, Internet service providers to provide IP addresses, and the list goes on. On the other hand, with AWS, we can do everything from a computer screen. It's all fully managed and much easier to work with. But once you're kicked off, you really only have 2 options, build your own data centers or file an antitrust lawsuit. Both of which are terrible options, but let's go with the first one. From here, we're going to build a Node JS app directly in the Raspberry Pi. It's a classic web page that tells you how many times the page has been viewed. Node is already installed, so we can open up an empty directory, then run npm init y to create a new npm project. From there, we can install Express JS to help us build a web app. I'm creating a JavaScript file called server JS for our main source code. Then instead of a database, I'm just adding a text file to the project, which we can read and write to to get the current count of people who have viewed the web page. And the JavaScript file will import read file sync and write file sync from Node. Js, then create a new Express app. The Express app will listen on local host 5000. From there, we just need an endpoint to the root URL that will update the view count, then send back the raw HTML to the browser. In express, we can create an HTTP endpoint by calling app get followed by the URL, which in this case will just be the root URL. We can get the current view count by calling read file sync, which we'll set to a variable. Coming from a text file, it's a string, so we'll parse it into an integer then add 1 to it. Then we'll simply write that value back to the same file. The final step is to send a response from the endpoint, which is just a raw HTML string, but we'll interpolate the view count into it so the user can see that in the UI. That's all it takes to build a web app. Now we can run it by calling node server dot j s from the command line. Now at this point, you should be able to open local host 5 1,000 on the Raspberry Pi browser and see your web app displayed there. At this point, we have a working web app, but we're building a serious app here, and that means we're going to deploy it with Nginx. Once we add multiple Raspberry Pis to our data center, we'll be able to use nginx to balance the load across them. Nginx is not installed on Raspberry Pi by default, So we need to open up the terminal and first run sudo apt update to get the latest information from the package manager, then we can run sudo apt install nginx. This adds Nginx to the e t c directory, which we can run with sudo followed by the start command. This runs a default web page on the Raspberry Pi, which we can access on its internal IP address. You can find the IP address by running host name flag capital I, then paste that value into the browser. It should say welcome to NGINX, but what we actually wanna do here is proxy it to our Node JS application running on local host 5,000. We can modify the default config in the e t c nginx sites available directory. I've removed all the comments, leaving only the default config. The only modification that we need to make here is to add proxy pass to local host 5000, and that basically tells any traffic going to the root URL to use the Node. Js app. Save the file, then apply the changes by running sudo nginx restart. Now that we have our app running the way we want it on the Raspberry Pi, we need to make it available to the Internet. The internal IP address can be used on your own local network, but in order to make the website available to the outside world on the Internet, we need an external IP address. An external IP address is provided by your Internet service provider, like Comcast, Verizon, AT and T, or whatever. For most people, They provide a dynamic IP address that can change on a regular basis, but it's not a great thing if you're trying to host a website because once the IP changes, then that means your website is no longer available on the Internet. That means if we want to serve our web app from a Raspberry Pi, we have 2 options. We could call up the ISP and ask them for a static IP address. These guys don't exactly have a great reputation for customer service, by getting a static IP from the provider is probably the best option. Luckily, there is an alternative. There are a few services out there that can monitor your dynamic IP and update it on the DNS for a domain when it changes. In other words, it makes your dynamic IP behave like a static IP. I'm going to be using no ip.com because it has a free tier, and it worked for me just fine. When you sign up, you pick a free domain name, and it will automatically detect your external IP as the a record in the DNS. But in order for it to detect changes on the Raspberry Pi, We need to install some software there. Basically, you just download a binary, execute it, and then it will have you log in with your username and password to link the account to the Raspberry pie. Once that's done, we effectively have a static IP, but there's still one more step left to get this thing working. If we try to navigate to the external IP At this point, we get a blank screen. By default, your router will not allow outside traffic to get into your network. It's like a giant fence with a bunch of doors in it that are all currently closed. These doors are called ports, and our app is currently being served on port 80. That means we need to open up port 80 on our router to external traffic through a process called port forwarding. The exact steps will depend entirely on the router you use, but there is a website called portforwarddot comm that has a breakdown for basically every router out there. Once you connect to the router, you should be able to find port forwarding under the advanced options. What you'll do is add a new forwarding rule with starting and ending ports for 80 that connects your internal IP address to any external IP address. And remember, you can get your internal IP address by running host name flag capital I from the command line. Once you have that done, You should now be able to navigate to your external IP address, and the result should be the Node. Js app that we built earlier. Congratulations. You just built your own Amazon Web Services from scratch. And they may take our lives, but they'll never take Operator. Well, maybe not exactly, but you did host your own website from a Raspberry Pi that's not entirely dependent on a big cloud monopoly. It's not going to scale very well yet, but at least it's a start. I'm gonna go ahead and wrap things up there. Let me know what you think in the comments. Thanks for watching, and I will see you in the next one.
        