Making .sh file in AWS CloudShell

What is AWS CloudShell?

AWS CloudShell is an easy-to-use cloud computing service to deploy and manage your other cloud services inside of a CLI (Command Line Interface). It is an effective way to manage your AWS cloud applications and infrastructure in a large-scale environment. CloudShell helps to streamline the process of setting up and configuring the cloud infrastructure, reducing manual steps and overall time. It provides a unified experience for users to manage all of their services from one centralized portal. This makes it easier to keep track of your services and monitor their performance. The way we do is with bash scripts.

Bash scripts are scripts that can be run inside of a command line interface, often the driving force in quick automation in a corporate IT setting.

Why make the script in the CLI?

The main reason is to making the script is to eliminate operating misalignment between the AWS CloudShelland your local machine

How to make the script? We are going to use nano.

nano is a simple text editor for Linux and is oftentimes the default text editor for the command line interface. It allows you to edit files directly in the terminal. Yet, it does not come installed in AWS CloudShell, so we have to download it. To do so, we need to navigate to the AWS CloudShell shell in our browser, and then enter the following commands:

# Install basic developer tools and dependencies
sudo yum -y groupinstall "Development Tools"
sudo yum -y install git-core zlib zlib-devel gcc-c++ patch readline readline-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel xz

# Download and compile nano
cd ~
mkdir ~/bin
wget https://www.nano-editor.org/dist/v5/nano-5.4.tar.xz
tar xf nano-5.4.tar.xz
cd nano-5.4
./configure --prefix=$HOME
make && make install

# Clean up and add ~/bin to PATH
cd ..
rm -rf nano-5.4
rm nano-5.4.tar.xz
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

Now to test this, enter the following commands in the terminal:

nano test.sh

This will create a file `test.sh` in the AWS CloudShell directory and open the file for you.

Then enter this into `test.sh` and exit.

#!/usr/bin/bash
echo "Hello World"

No run this command and you can see the results in the AWS CloudShell terminal.