Skip to main content

Posts

Showing posts from 2021

Python - FAQ

How to find the version of Python installed in Ubuntu? python --version - Ho to upgrade python version? sudo apt update sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update sudo apt install python3.10 python3.10 --version // Python 3.10.1 - python version is not installed but python3. How to change python3 to python rm /usr/bin/python3 ln -s /usr/bin/python3.10 /usr/bin/python python --version // Python 3.10.1 - How to install pip in Ubuntu? sudo apt-get install python3-pip - How to fix the error 'ModuleNotFoundError: No module named 'distutils.util'' while installing pip? sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt install python3.10-distutils pip --version // pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10) - How to install PyCharm in Ubuntu? sudo snap install pycharm-community --classic

How to RDP an EC2 instance in a private subnet?

The answer is Bastion Host . Create a VPC Create two subnets (they can be in same AZ or different) Name them public-subnet and private-subnet. Technically, both are private now. Linking them with an Internet Gateway via a Route table makes them public Associate a Route table with public-subnet with the following routes That means, if a request is made from an instance in this subnet to an IP in the CIDR range of 172.31.0.0/16, the traffic should be redirected to VPC's default route i.e., it is a complete local communication within VPC. If the request destination is Anywhere (0.0.0.0/0), the traffic should be redirected to the Internet Gateway. Now, the public-subnet is PUBLIC in all senses (as it is connected to Internet Gateway) Add Web servers (EC2 instances) in this public-subnet (recommended) Add a NAT Gateway in this public-subnet Associate a Route table with private-subnet with the following routes That means, if a request is made from an instance in this subnet to an IP in t...

How to install/upgrade/downgrade kubectl in Linux (Ubuntu)?

To install the latest version: curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256" echo "$(<kubectl.sha256) kubectl" | sha256sum --check sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl kubectl version --client kubectl version To install a specific (v1.19.0) version: curl -LO "https://dl.k8s.io/release/v1.19.0/bin/linux/amd64/kubectl" curl -LO "https://dl.k8s.io/v1.19.0/bin/linux/amd64/kubectl.sha256" echo "$(<kubectl.sha256) kubectl" | sha256sum --check sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl kubectl version --client kubectl version This will install kubectl client. Run minikube start to install kubectl server.

How to install/upgrade/downgrade minikube in Linux (Ubuntu)?

To install the latest version: wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo cp minikube-linux-amd64 /usr/local/bin/minikube sudo chmod 755 /usr/local/bin/minikube minikube version To install a specific (v1.11.0) version: wget https://storage.googleapis.com/minikube/releases/v1.11.0/minikube-linux-amd64 sudo cp minikube-linux-amd64 /usr/local/bin/minikube sudo chmod 755 /usr/local/bin/minikube minikube version

AWS CloudFormation error: Webhook could not be registered with GitHub. Error cause: Maximum number of login attempts exceeded

Error: Webhook could not be registered with GitHub. Error cause: Maximum number of login attempts exceeded [StatusCode: 403, Body: {"message":"Resource protected by organization SAML enforcement. You must grant your Personal Access token access to this organization.","documentation_url":"https://docs.github.com/articles/authenticating-to-a-github-organization-with-saml-single-sign-on/"}] Service: AWSCodePipeline; Status Code: 400; Error Code: ValidationException; Steps to fix: Create a new GitHub PAT with required accesses and enable SSO as described here . Use this PAT as an OAuthToken for the Source action of CodePipeline.

Adapter design pattern

Run the following code in Linqpad: void Main() { IBowler bowler = new Bowler(); IBatter allRounder = new AllRounderAdapter(bowler); allRounder.Bat(); } // IBowler and IBatter are incompatible interfaces internal interface IBowler { void Bowl(); } internal interface IBatter { void Bat(); } // Adapter internal class AllRounderAdapter : IBatter { private IBowler bowler; public AllRounderAdapter(IBowler bowler) { this.bowler = bowler; } public void Bat() { Console.WriteLine("Batting..."); } } // Adaptee internal class Bowler : IBowler { public void Bowl() { Console.WriteLine("Bowling..."); } } Output: Batting...

AWS Server Migration Service (SMS)

used to migrate 1000s of on-premises workloads to AWS used to migrate Hyper-V machines to AWS cloud used to migrate VMs (virtual machines) to AWS cloud we can automate/schedule/track incremental replications of live server volumes used for large scale server migrations

Amazon RedShift enhanced VPC routing

When Amazon RedShift enhanced VPC routing is enabled --> RedShift forces all COPY and UNLOAD traffic b/w cluster and data repositories via VPC When Amazon RedShift enhanced VPC routing is NOT enabled --> RedShift routes the traffic via internet (including traffic to other AWS services within AWS network)

AWS - Route53 routing policies

Multi-value answer - Use when you want to use ALL web servers randomly Geolocation - Use web servers based on user location Latency - Use when you want to route traffic to a region which provides the best latency Weighted - Use when you want to route traffic to multiple web servers in proportions

ERROR: Support for the experimental syntax 'jsx' isn't currently enabled

When will this error occur? You may get this error while you're running unit tests in  React (TypeScript) . Fix? - Run,  > npm i webpack > npm i --save-dev  @babel/preset-env @babel/preset-react @babel/preset-typescript  @babel/plugin-proposal-class-properties - Create a .babelrc file in root folder (next to package.json ) - Update the .babelrc file as follows: { "presets": [ "@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript" ], "plugins": [ "@babel/plugin-proposal-class-properties" ] } - Run,  > jest The tests will run without errors Courtesy

CentOS commands

CentOS commands: 1) To view the list of packages installed > yum list installed 2) To view the count of packages installed > yum list installed | wc -l 3) To refresh package database and install updates if any > yum update -y  (-y is added so that you need not respond with y or yes when prompted) 4) To check if package is installed > rpm -qa | grep <package-name> e.g., rpm -qa | grep docker 5) To install docker > yum install -y https://download.docker.com/linux/centos/8/x86_64/stable/Packages/containerd.io-1.4.3-3.1.el8.x86_64.rpm > curl -fsSL https://get.docker.com/ | sh > rpm -qa | grep docker docker-ce-20.10.3-3.el8.x86_64 docker-ce-rootless-extras-20.10.3-3.el8.x86_64 docker-ce-cli-20.10.3-3.el8.x86_64 COURTESY: https://vexpose.blog/2020/04/02/installation-of-docker-fails-on-centos-8-with-error-package-containerd-io-1-2-10-3-2-el7-x86-64-is-excluded/ 6) To start, stop and view status of docker > systemctl start docker > ...

AWS Application Load Balancer (ALB)

AWS Auto-scaling Instance profile

AWS - Custom metric

What is a Custom metric? You can create a custom metric (script) from your EC2 instance and monitor that metric by pushing it to CloudWatch. How to push your metric to CloudWatch? $ crontab -e $ crontab -e Add the following line to execute your script every minute: */1 * * * * /home/ec2-user/mem.sh Save and exit.

NAT Gateway vs. NAT Instance

NAT Gateways are more suitable for higher bandwidth requirements than NAT Instance (scales up to 45Gbps). Whereas, NAT Instances depend on bandwidth of instance types Zone independent architecture - Create NAT Gateways in each AZ. This ensures high availability. Whereas in NAT Instances, we have to manage failover between instances using scripts Can we replace NAT Gateways/NAT Instances with a VPN connection? No. VPNs are used to connect to route traffic in a private network (skipping Internet). NAT Gateways/NAT Instances are used to route traffic from EC2 instances in the private subnet to Internet.

Elasticity

You would have heard the word elasticity multiple times in AWS. What does it mean? Suppose you have an EC2 instance. After the load increases, it would be better if there is another EC2 instance to share the load. So, you launch another instance through Auto-Scaling. Now, the load is shared by these two instances. The EC2 instances, since one can do the same work of the other, are elastic . This is called as elasticity .