Tech Junkie Blog - Real World Tutorials, Happy Coding!: 2020

Monday, November 23, 2020

 In the previous post we went over how to create a Classic Load Balancer, in this post we are going to create one of types of load balancer AWS offers.  We are going to create a Network Load Balancer, this balancer  is for websites that require high performance and low latency websites, think of streaming data.  If your website needs real time streaming data, this is probably the load balancer for you. It supports layer 4 protocols such as UDP, TLS and TCP protocols. If you need a static IP or Elastic IP assigned to your load balancer this is your only choice because the other two load balancer does not give you the option to assign Elastic IPs.

Before we create the load balancer we need to create more than one instances with a web server because we need to test that the load balancer is able to switch.

1. Create two instances with the user data to create Apache Web Servers with these commands in the User Data for instance, if you need the full instruction on how to create instances with User Data you can read this post

#cloud-boothook
#!/bin/bash
#Use this for your user data (script without newlines)
# install httpd (Linux 2 version)

yum update -y 
yum install -y httpd.x86_64 
systemctl start httpd.service 
systemctl enable httpd.service 
echo "Hello world from $(hostname -f)" > /var/www/html/index.html

We just created an index.html file to write out the hostname for testing later on


Monday, November 16, 2020

 In the previous post we went over what a load balancer is, in this post we are going to create one of types of load balancer AWS offers.  We are going to create a Classic Load Balancer, this balancer is not recommended by Amazon, you should only create this if you have to support EC2-Classic instances.

Before we create the load balancer we need to create more than one instances with a web server because we need to test that the load balancer is able to switch.

1. Create two instances with the user data to create Apache Web Servers with these commands in the User Data for instance, if you need the full instruction on how to create instances with User Data you can read this post

#cloud-boothook
#!/bin/bash
#Use this for your user data (script without newlines)
# install httpd (Linux 2 version)

yum update -y 
yum install -y httpd.x86_64 
systemctl start httpd.service 
systemctl enable httpd.service 
echo "Hello world from $(hostname -f)" > /var/www/html/index.html

We just created an index.html file to write out the hostname for testing later on


Monday, November 9, 2020

 If your website starts to become popular, especially if it's not static you might noticed that the performance is starting to degrade.  The most logical step is to scale your architecture with a load balancer.  AWS offers three types of load balancers, there are:

  • Application Load Balancer
    • Protocols (HTTP, HTTPS)
    • Specializes in web applications, deals with traffic at the request level (layer 7)
      • Supports query strings, path routing, parameter routing, IP routing
    • Supports IP addresses, Lamda Functions (serverless, microservices), and containers
  • Network Load Balancer
    • Protocols(TCP, TLS, UDP, TCP_UDP) - Layer 4
    • When high performance and low latency is required
    • TLS offloading
    • Elastic IPs can be assigned
  • Classic Load Balancer
    • Protocols (TCP, SSL, HTTP, HTTPS) - Layer 4, 7
      • Old generation, not recommended unless you are running EC2-Classic instance

    In a nutshell a load balancer distributes the client's traffic among the many instances that are available in your architecture to offload the traffic so that more than one instance can share the burden of the traffic.  A health check is setup so that only the health instances can serve up traffic.




    Monday, November 2, 2020

     In the world of AWS you have to be familiar with the different features and what they are called.  Well two very important building blocks of all the services that AWS offers are the S3 and the IAM Role.  S3 is basically an object storage repository that are called buckets, but it is more than just a storage, you can turn to the storage into a static website. We'll get into that later. It's public facing, so you can access it over the internet. 

    IAM Role is an identity that you can assign policies to and that role assumes the permission.  Therefore only instances with a role that has a policy to access S3 can assume that role and have access to the S3.


    So let's start creating the assets on the diagram above:

    Monday, October 26, 2020

     In the previous post  we created a public and private subnet in our VPC.  In this post we are going to create a NAT gateway so that our private instances can access the internet.  That's useful when there's a need to update the instance.  For example if we ping google.com right now there will be 100% package lost in our private instance because we cannot get to the internet.  After we attach the instance to the NAT gateway we will be able to ping google.

    It would go on for a while but eventually it would say the package is lost.

    Now let's create our NAT Gateway, it is important that we delete the NAT Gateway if it's not in use because you have to pay for it.

    Monday, October 19, 2020

     In most scenarios you don't want to expose all of your servers to be public facing.  You probably want to configure your network so that only the server that is hosting your web application is public facing.  What you want to do is put your web application on the public subnet and your backend servers on the private subnet.  This private subnet can access the internet through a NAT gateway for software updates and other functions that require internet access.  However, the outside world cannot establish a connection to servers in the private subnet.  The NAT gateway resides in the public subnet, acting as a bridge between the public subnet and private subnet.


    Wednesday, October 14, 2020

     In the previous post we associated our Elastic IP with an instance directly.  In this post we are going to take another approach to assign our Elastic IP to our instance.  In this approach we will create an Elastic Network Interface and associate it with our instance instead.  In the first approach the Elastic IP replaces the public IP because we associate it directly to the instance. But if we create an Elastic Network Interface we are essentially adding a second interface in our instance with two IPs, eth0 is the main network interface and eth1 will be the second interface.  It's like having two network interface in the physical world but this time it's virtualized in AWS.


    Here are the steps to create a network interface:

    1. Create an Elastic IP, follow this post if you don't know how.

    If you look at the instance description you will see that there's no Elastic IP address assignment, so if you stop and start the instance you will get a new public IP, and there's only one network interface (eth0). By the time we are finish with this post the instance will have tow network interfaces and an Elastic IP.


    Tuesday, October 13, 2020

     In the last post we created our ACME Bank database in MySQL, the next step is to get the values from the Values table in the Asp.Net Core WebApi controller.  

    Let's create some test data so that we could retrieve the values from the database.  The Values table could contain anything.  So I am going to store famous philosophers throughout history.  These philosophers are so famous that they only have one name: 

    You can run the SQL insert statement below to seed the data in MySQL:

     

    INSERT INTO acmebank.Values (
        Name
    )
    VALUES
        (
            'Socrate'
        ),
        (
            'Plato'
        ),
        (
            'Spock'
        ),
        (
    	'Thanos'
        );
    

    So your Values table should look like this when you executed the insert query










    Monday, October 12, 2020

     When an instance is created in AWS a public and private IP is assigned to the instance.  The private IP does not change, but the public IP address changes each time the instance reboot or is stopped.  On reboot you might be lucky enough to grab the same public IP, but it's not guaranteed.  But on stoppage you will definitely be assigned a new public IP.

    That's probably not a good thing a real world situation, that's where an Elastic IP comes into play.  An Elastic IP is a static IP that when assigned does not change.  However, there's no free lunch so you will be charged for it.  So only create one if you really need it.  I would recommend that you use the public DNS instead when you are not in production.  Say the development and test environment.  You might want to spend some money on the staging environment to mirror production as close as possible.

    In the following section I will show you how to create an Elastic IP and assign it to an instance.  You probably want to delete it after you create it if you do not want to pay.  Only keep it if you want to use it.

    Tuesday, October 6, 2020

     In this post we are going to create our first Entity Framework migration and creating an actual database in MySQL. 

    In order to do that we need to add a few NuGet packages to our Asp.Net Core project including the Entity Framework Core package.  But, before we do that we want to find out what what version of .NET Core we are running.  Obviously I have it memorized, but for the rest of you, you can type the command dotnet --version to figure out what the version is :)  It's always a good idea to try and match the package version with the .NET Core runtime you have.  It's one of the more annoying thing with Angular and Asp.Net Core, it's changing constantly. So as you can see my version 3.1.xxx so I should try to install packages that are made for 3.1.x.

    The first package we are going to install is the Microsoft.EntityFrameworkCore.  So open the ACMEBank.API project with Visual Studio Code.  Press Ctrl+Shift+P and type NuGet and select

    Monday, October 5, 2020

     CloudWatch is a service on AWS that is used to monitor services on AWS via metrics.  In addition to monitoring resources.  CloudWatch can be used to set alarms and perform some actions on the instance when a certain condition is met.  In this post we are going to set an alarm on our instance if CPU utilization gets to a certain threshold.  Which is a typical safeguard that most environments have, there are several actions that you can take when the threshold is met, in our case we are going to terminate the instance if the CPU utilization reaches 75%. 

    The following shows you how to set a CloudWatch alarm on our Linux instance:

    1. Click on "Monitoring" tab in the "Instances" page, then click on the "Create Alarm" button

    Tuesday, September 29, 2020

     In this post we are going to install MySQL Workbench on Fedora.  MySQL Workbench is a great GUI database management tool for MySQL.  Even though we can do everything we need with MySQL on the terminal it's nice sometime to see the tables and data visually.

    Here are the steps to install MySQL Workbench:

    1, Go to the yum repository for MySQL at https://dev.mysql.com/downloads/repo/yum/ select the Fedora repository, and click "Download"

    Monday, September 28, 2020

     User Data in an instance allows you run commands while your instance boots up.  In the previous posts we just plain vanilla instances so far.  But in this post we are going to install the Apache Httpd service when we create our instance using User Data.

    Here are the steps to create an instance with User Data:

    In this blog we are going to start our journey into AWS infrastructure with the creation of an EC2 instance which is probably the most common task you'll ever do. 

     Here are the steps to create an EC2 instance on AWS:

    1. Log into AWS and on the "Find Services" search box type EC2 and press enter 

    2. You will be taken to EC2 screen, then click on "Instances"

    2. Click on "Launch Instance"

    An instance metadata is data about your instance that you can use to configure your instances.  They are divided into categories.  Anyone who have access to the instance can view the metadata, therefore you should not store anything sensitive that could be accessed such as "User Data"

    You can get more information here at Amazon's website:

    https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html

    You can access your metadata with this URL http://169.254.169.254/latest/meta-data/

    Here are the steps to retrieve your instance data:

     1.  Connect to your AWS Linux instance and type curl http://169.254.169.254/latest/meta-data/


    Tuesday, September 22, 2020

     In this post we are going to circle back to MySQL and continue setting up our MySQL database, so that we can use it in our application.  Since we don't want to use our root for log in and we turned off root login for remote connection.  We have to create a dedicated user for our application.  Here are the steps to create a dedicated dev use in MySQL

    1. Log into MySQL with root using this command mysql -u root -p

    2.  In the MySQL prompt type CREATE User 'devuser'@'localhost' IDENTIFIED BY 'P@ssw0rd'; to create the user, obviously if this is your production environment you would want to use a more secure password

    3. Then type GRANT ALL PRIVILEGES ON *.* TO 'devuser'@'localhost' WITH GRANT OPTION; to grant the user all the privileges on all the objects

    4. Now type FLUSH PRIVILEGES; to update and apply the privileges

    Monday, September 21, 2020

     In this post we are going to connect to a Windows instance using RDP.  In order for us to connect to the Windows instance we need to get the password for the server using the key pair that we downloaded from the last post when we created the instance, the .pem file.

    Here are the steps to connect to the Windows instance using RDP:

    1.  Navigate the EC2 "Instances" page, check the instance and click "Connect"







    2. On the next screen click on "Get Password"

    Wednesday, September 16, 2020

     A Blockchain is a distributed network of containers with data, a hash, and a pointer to the previous hash.  A hash is a text that consists of an input of all the parts of the block, and it will generate the same hash every time the input is the same.  So if the block has been tampered with the hash will be different. On top of this there's a global record of the transaction that's distributed to everyone in the ecosystem.  Making it almost impossible to to tamper with because if a hash has been tampered with there needs to be a consensus of the change before it is deemed valid.  A consensus consists of 50% of the users.



    If the hash, data, or anything of block 1 changes, the block 2 becomes invalid because block 1 will have a new hash and block 2 will be pointing to the wrong previous hash, making everything after it invalid, therefore it is in everybody's interest that changes are made very difficult because it would greatly impact the integrity of the blockchain.  There are many checks and balances that must be met before a new block is accepted in the blockchain. Obviously there needs to be something that will correct a bad new block chain, else if a new block chain is bad then nobody can add a new chain to the blockchain anymore.

     

    Tuesday, September 15, 2020

    Before we run our Asp.Net Core application for the first time we are going to copy a controller from Asp.Net Core 2.2 to help us create the skeleton for our application.  A skeleton are the plumbings we do at the beginning of our application to make sure all the mechanisms work.  It's called the ValuesController which has been replaced with a more complicated WeatherForecastController.  The ValuesController is just a lot easier to work with to get things set up.


    Just create a new controller in the "Controllers" and call it "ValuesController.cs" Here is the code for it.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    
    namespace DatingApp.API.Controllers
    {
        [Route("api/[controller]")]
        [ApiController]
        public class ValuesController : ControllerBase
        {
            // GET api/values
            [HttpGet]
            public ActionResult> Get()
            {
                return new string[] { "value1", "value2" };
            }
    
            // GET api/values/5
            [HttpGet("{id}")]
            public ActionResult Get(int id)
            {
                return "value";
            }
    
            // POST api/values
            [HttpPost]
            public void Post([FromBody] string value)
            {
            }
    
            // PUT api/values/5
            [HttpPut("{id}")]
            public void Put(int id, [FromBody] string value)
            {
            }
    
            // DELETE api/values/5
            [HttpDelete("{id}")]
            public void Delete(int id)
            {
            }
        }
    }
    
    

    Monday, September 14, 2020

    In this blog we are going to start our journey into AWS infrastructure with the creation of an EC2 instance which is probably the most common task you'll ever do. 

     Here are the steps to create an EC2 instance on AWS:

    1. Log into AWS and on the "Find Services" search box type EC2 and press enter 

    2. You will be taken to EC2 screen, then click on "Instances"

    2. Click on "Launch Instance"

    Wednesday, September 9, 2020

     The first thing you want to do in Python is to install the latest version of Python.  Even though most Linux and MAC distribution has Python installed by default, you still want to install the latest version of Python.  The latest stable version of Python at the time of this writing is version 3.8.5 in this post we are going to install version 3.6.5 on our Linux instance.  

    1. Open up the terminal and type the following commands

    sudo su

    mkdir /opt/python

    cd /opt/python/

    wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz

    tar xzf Python-3.8.5.tgz

    What we did was basically was create a new folder called python to hold our files and then download the python version 3.8.5 and then unpack the file with the tar xzf command



    Tuesday, September 8, 2020

     For those of you who works with Visual Studio, working with C# comes out of the box, but with Visual Studio Code you need to install some extensions from the Marketplace to make it suitable for C# development.  

    Here are the extensions you need to install:

    • C#: This extension by Microsoft gives us IntelliSense, references, code editing and highlighting and debugging support

    • C# Extensions: This extension let's you create C# files, like classes and interfaces also some keyboard shortcuts like creating.  This one seems to be no longer in development for a long time, but it works fine.

    • NuGet Package Manager: This extension let's us install new NuGet packages which we will need from time to time.

    Monday, September 7, 2020

     AWS has a very generous free tier account, but there will be times when you forget to clean up your work and are stuck with the bill.  There's a setting in AWS that allows to set the limits on your account so that you won't get charged for resources or get a surprise on your bill.  

    Here are the steps to set a billing alarm:

    1. First thing you have to do is sign in as the root user

















    Tuesday, September 1, 2020

     In this post we are going to use the .NET Core CLI to create a web api application for our app.  The first thing to do is create an a folder to hold our files.  Since we are using Linux you want to sudo su into the terminal and create the following folder /opt/app/ACMEBank.  Once that's done cd into it and you are ready to type in the command to create the Web Api.

    Here are the steps:

    1. What you want to do first is to make sure that you have .NET Core install by typing in dotnet --info, there should be information on your .NET Core install.  If you don't have .NET install you can follow the directions in this post.

    Monday, August 31, 2020

     So far we have connected to our EC2 instance with the terminal on Linux and Putty on Windows.  There is another option that you can perform and it only requires that you have a browser.  You must have an Amazon Linux Version 2 instance for this to work, at least that's what I think.

    On the instances page on the AWS console click on the "Connect" button while the instance is selected


    Select "EC2 Instance Connect (browser-based SSH connection)" radio button, and accept the defaults. User name "ec2-user" should be selected for you, then click "Connect"

    Tuesday, August 25, 2020

    The most important thing for most modern dynamic application these day is choosing a database to store your data.  If you are on a Windows environment then you use SQL Server database that is a fine choice. But if you are on Linux MySQL is a great choice also.  In this post we are going to go through how to install MySQL server on our Fedora development machine.

    Here are the steps to install MySQL on Fedora Linux:

    1. First we need to add the MySQL repository to our machine by tying in the following command in the terminal

    sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-fc32-1.noarch


    Monday, August 24, 2020

     On the previous post we connect to our EC2 instance using SSH on Linux now I will show you how to connect to the EC2 instance using Putty on Windows

    Here are the steps to connect to our EC2 instance on Windows:

    1. Download and install Putty from here 

    2. Open PuttyGen from the start menu, and select your .pem file and convert it to a .pkk file






    Once it's open select "File", then "Load private key", then select your .pem file






    Tuesday, August 18, 2020

    In this post we going to get our development environment with NodeJS, VSCode and Postman

    The Urls are the following, if you are developing in Linux you should install the Linux version.  All these tools are cross platform so you can develop in either Windows, Linux or MacOS:

    .NET Core: https://dotnet.microsoft.com/download

    Node.JS: https://nodejs.org/en/

    Visual Studio Code: https://code.visualstudio.com/#alt-downloads

    Postman: https://www.postman.com/downloads/

    For .NET Core make sure you download the "recommended" version and not the preview version. Also with NodeJS, usually it has LTS status.

    Installing .NET Core SDK and NodeJS On Fedora

    In order to install .NET Core SDK on Fedora open the terminal and type in the following

    sudo dnf install dotnet-sdk-3.1 -y

    The -y tells Fedora to skip the y/N prompt and just go on with the install

    Once the SDK is installed you can verify the install with the command dotnet --version



















    Monday, August 17, 2020

     In the previous post we created an EC2 instance in AWS in this post we are going to connect to that instance on a Linux workstation or server with SSH.

    Here are the steps to connect to the EC2 instance using SSH on Linux, this will also work on a Mac as well:

    1. Navigate to the folder that contains the key pair file that you've downloaded in the previous post, I store it in the folder /aws/EC2/KeyPair/ folder , so I would type cd /aws/EC2/KeyPair then type ls to see the file in the folder

    Thursday, August 13, 2020

    The first thing we want to do is set up the Google Chrome browser on a Linux instance, I've decided to use a virtualized Fedora workstation as my development machine.  You can use Windows if you want, it would be a lot easier.  It doesn't really matter because Asp.Net Core works on Linux as well.  Google Chrome has the best development tools and it also has an extension call Postman.  Although you want to install the standalone version of Postman.  Here are the steps to install Google Chrome on Linux

    I wrote a post on how to set Fedora as your development machine here

    1. Navigate to the URL https://www.google.com/chrome/

    2. Click on "Download Chrome"


     In the next month or so I will start a series of blog posts that will take you from scratch on how to deploy an Angular application that makes API calls from an Asp.Net Core web api backend using Entity Framework Core as it's ORM and MySQL as the database.  Most tutorials would end there, but I will take it further and deploy the application on AWS so that it lives on the world wide web.  Since I don't want to start from scratch I will be modernizing the ACME bank application that I've started with AngularJS.  If you are working with AngularJS you know that it's time to update and upgrade because it's at its' last legs and Angular is the future.  Some say the journey is more rewarding than the destination.  I hope, you will join me on this journey.  Thank you, here is a diagram of what's to come

    Next: Set Up Chrome Browser On Linux

    Monday, August 10, 2020

    In this blog we are going to start our journey into AWS infrastructure with the creation of an EC2 instance which is probably the most common task you'll ever do. 

     Here are the steps to create an EC2 instance on AWS:

    1. Log into AWS and on the "Find Services" search box type EC2 and press enter 

    2. You will be taken to EC2 screen, then click on "Instances"

    2. Click on "Launch Instance"

    Monday, January 20, 2020

    Now that we have our virtual network and subnet setup in Azure, the next thing we want to do is create a Windows Server virtual machine.  A virtual machine is a great way to learn Azure because it's a fixed cost.  You can try different things without paying anything extra, also most of the promotional deals that Microsoft gives you should be more than enough to cover your costs for the virtual machine.

    The following steps is how you would create a Windows 2016 Server in the Azure Portal:

    1. Log into Azure Portal, and mouse over "Virtual Machines", click on "Create"

















    Monday, January 13, 2020

    In the previous blog post we created a "Resource Group", in this post we are going to create a "Virtual Network" in that resource group so that we have more control over four Azure network settings.  Azure actually creates a virtual network for us automatically, but we want to have more control over our Azure infrastructure.

    The following is how you would create a "Virtual Network" in Azure.

    1. Search for "Virtual Network" and click on "Virtual Network", mouse over and click on "Create"

































    Monday, January 6, 2020


    The first thing you want to create after you have an Azure account is to create a "Resource Group"  as "Resource Group" as the name implies is an Azure Resource Group, groups all of your resources in a single group so that it's easily managed.

    The following steps is how you would create a "Resource Group" in the Azure Portal.

    1. Log into Azure portal, and click on "Resource Group" or "More Services" depending on your UI

























    Search This Blog