DEV Community

Cover image for Shell scripting with Aws
Shubham Srivastava
Shubham Srivastava

Posted on β€’ Edited on

1

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 ➑️

Hot sauce if you're wrong - web dev trivia for staff engineers

Hot sauce if you're wrong Β· web dev trivia for staff engineers (Chris vs Jeremy, Leet Heat S1.E4)

  • Shipping Fast: Test your knowledge of deployment strategies and techniques
  • Authentication: Prove you know your OAuth from your JWT
  • CSS: Demonstrate your styling expertise under pressure
  • Acronyms: Decode the alphabet soup of web development
  • Accessibility: Show your commitment to building for everyone

Contestants must answer rapid-fire questions across the full stack of modern web development. Get it right, earn points. Get it wrong? The spice level goes up!

Watch Video 🌢️πŸ”₯

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

πŸ‘₯ Ideal for solo developers, teams, and cross-company projects

Learn more

πŸ‘‹ Kindness is contagious

If you found this article helpful, please give a ❀️ or share a friendly comment!

Got it