Cloud Bootcamp: Bash and Networking
Knowing bash scripting and networking are essential to learning more about cloud engineering. I started learning the fundamentals of how networking works in AWS and bash scripting. Mastering both skills will help me understand engineering more.
Bash
I created a script that asks a user for a folder and spell-checks every file in that folder.
Create text documents with misspelled words
Download aspell. Sudo apt-get install aspell
Start your script like this- #! /bin/bash
for f in *.txt; do aspell check $f ; done
This is a Bash script that performs a spell check using the aspell tool on all files with a ".txt" extension in the current directory.
The script starts with the shebang line "#! /bin/bash", which specifies that the script should be run using the Bash shell.The "for" loop iterates over all files in the current directory that end with ".txt", assigning each file to the variable "f" in turn. The body of the loop then calls the "aspell" command with the "check" option, passing in the filename stored in the "f" variable. This will perform a spell check on each file and print out any misspelled words to the console. So, overall, this script is a simple way to spell-check all text files in the current directory using the "aspell" command-line tool.
Here are some basic Linux and bash commands so you can create bash scripts too.
Help- help and man.
Navigate-pwd, cd, pushd, and popd.
List content- ls.
Find files- whereis, which, and find.
Directories- mkdir, touch, mv, rm, cp, and rmdir.
. View file contents- cat, head, tail, more, less, and grep.
Environment variables- env, and export.
Modify permissions- chown, chgrp, and chmod.
What are variables in bash? Taking you back to math class a variable is the value you give to an expression.
Hello_message=’Hello World!’
echo $hello_message
How to assign the output of a command to available in Bash Ex. Current_dir=$(pwd)
You must use double quotes “”
Constant: read-only variable_wont_change=”blue”
Conditional statements- let you write code that performs different tasks based on specified checks.
Case statements- The case statement simplifies complex conditions with multiple different choices.
Functions- a method used in shell scripts to group reusable code blocks.
Loops- a bash programming language statement which allows code to be repeatedly executed.
Use breaks
Different types of loops while, until and for
How to write a bash script.
Create a new file, hello.sh and open it with nano.
On the first line specify the interpreter to be used in the code. In this case it is Bash.The first part of the line, #!, is called the “shebang” and it indicates the start of a script.
Save the code by pressing CTRL + X, then press Y and Enter.
AWS Networking
AWS networking basics
CIDR- Classless Inter-Domain Routing (CIDR) is an IP address allocation method that improves data routing efficiency on the internet.
Subnets- a range of IP addresses in your VPC.
Internet gateway- a horizontally scaled, redundant, and highly available VPC component that allows communication between your VPC and the internet.
Route tables- contain a set of rules, called routes, that determine where network traffic from your subnet or gateway is directed.
Nat gateway- a highly available AWS-managed service that makes it easy to connect to the Internet from instances within a private subnet in an Amazon Virtual Private Cloud (Amazon VPC).
NACL- An optional layer of security that acts as a firewall for controlling traffic in and out of a subnet.
Security group- acts as a virtual firewall for your EC2 instances to control incoming and outgoing traffic.
API Gateway- helps it simple to create, publish, maintain, monitor, and secure APIs at scale.
CloudFront- delivers content faster including data, videos, applications, and APIs.
Route 53- Changes IP addresses to domain names and the other way around so computers can be connected with each other. For example, 192.0.7.1 into www.forexample.com.
VPC- gives you an isolated section of the AWS cloud.
App Mesh- monitors and controls microservices.
Cloud Map- With AWS Cloud Map, you can define custom names for your application resources, and it maintains the updated location of these dynamically changing resources.
Direct Connect- makes it easy to establish a dedicated network connection from your premises to AWS.
Global Accelerator- a networking service that improves the availability and performance of the applications that you offer to your global users.
Privatelink- simplifies the security of data shared with cloud-based applications by eliminating the exposure of data to the public Internet.
Private 5G- an easy way to use cellular technology to augment your current network.
Transit Gateway- a service that enables customers to connect their Amazon Virtual Private Clouds (VPCs) and their on-premises networks to a single gateway.
VPN- solutions establish secure connections between your on-premises networks, remote offices, client devices, and the AWS global network.
Elastic Load Balancing- automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, and IP addresses.
Integrated Private Wireless on AWS- designed to provide enterprises with managed and validated private wireless offerings from leading Communications Service Providers.
VPN architecture breakdown
VPC- the VPC can be used to host the VPN gateway and the private subnet.
Security Group- the security group can be used to control access to the VPN gateway.
Private subnet- private subnet can be used to host the resources that need to be accessed via the VPN.
Route table- a separate route table can be created for the private subnet that routes traffic through the VPN gateway.
VPN gateway- used to establish the VPN connection to the customer gateway.
VPN connection- VPN connection can be established over the internet.
Customer gateway- the customer gateway can be configured to establish the VPN connection to the VPN gateway hosted in the VPC.
Why would you use this diagram? This architecture can provide a secure and reliable way for customers to access their resources hosted in AWS using a VPN connection.
Secure web application breakdown
VPC- the VPC can be used to host the public subnet.
Public subnet- the public subnet can be used to host the web application.
Security group- the security group can be used to control access to the web application.
Route table- a separate route table can be created for the public subnet that routes traffic through the internet gateway.
Internet gateway- the internet gateway can be used to enable internet access to the web application.
Why would you use this diagram? - This architecture can provide a scalable and secure way for customers to host their web applications on AWS in a public subnet, which can be accessed over the internet. The security group can be used to control access to the web application, and the route table and internet gateway can be used to enable internet access to the web application.
I hope you enjoyed this blog post. Please see the two links below to learn more about AWS networking and bash scripting.