DEV Community

Cover image for Shell scripting with Aws
Shubham Srivastava
Shubham Srivastava

Posted on • Updated on

Shell scripting with Aws

Introduction

After successfully installing and creating your AWS EC2 instance, let's delve into the world of shell scripting by implementing a popular GitHub API. This script will allow you to view the list of collaborators and remove someone from it, addressing the common issue of revoking permissions when a person leaves an organization or a project.

AWS EC2 Instance Setup

Start by creating an AWS instance using the following image:

AWS Instance Setup

Connect your CLI to your EC2 instance and clone the GitHub repository with the following command:

git clone https://github.com/surajvast1/shell-script
Enter fullscreen mode Exit fullscreen mode

Clone Repository

GitHub Collaboration Test

Create a GitHub organization and add a collaborator to test your script. Run the following set of commands in your terminal:

cd shell-scripting-projects/github-api
export username="<organization_username>"
export token="<github_access_token>"
./list-users.sh <repo_owner> <repo_name>
Enter fullscreen mode Exit fullscreen mode

For example:

cd shell-scripting-projects/github-api
export username="surajvast1"
export token="ghp_sAJKxxxxxxxxxxxxxxxxxxxxxxxxxx"
./list-users.sh surajvast1 shell-script
Enter fullscreen mode Exit fullscreen mode

GitHub Collaboration Test

jq Information

The script utilizes jq to access only the names of collaborators from the JSON response.

Advanced Scripting with Helper Function

To enhance the shell script, a helper function can be added. Here is an example:

function helper {
  expected_cmd_args=2
  if [ $# -ne $expected_cmd_args ]; then
    echo "Please execute the script with the required cmd and args"
    echo "./list-users.sh <repo_owner> <repo_name>"
  fi
}
Enter fullscreen mode Exit fullscreen mode

This function ensures that the script is executed with the correct number of command-line arguments.
πŸš€πŸ‘©β€πŸ’»

Git branching strategy ➑️

Top comments (0)