All Projects → bash-my-aws → Bash My Aws

bash-my-aws / Bash My Aws

Licence: mit
Bash-my-AWS provides simple but powerful CLI commands for managing AWS resources

Programming Languages

shell
77523 projects
bash
514 projects

Projects that are alternatives of or similar to Bash My Aws

Saws
A supercharged AWS command line interface (CLI).
Stars: ✭ 4,886 (+524.81%)
Mutual labels:  aws, aws-cli, cli
Aws Cost Saver
A tiny CLI tool to help save costs in development environments when you're asleep and don't need them!
Stars: ✭ 178 (-77.24%)
Mutual labels:  aws, aws-cli, cli
Iamy
A cli tool for importing and exporting AWS IAM configuration to YAML files
Stars: ✭ 200 (-74.42%)
Mutual labels:  aws, aws-cli, cli
Torchlambda
Lightweight tool to deploy PyTorch models to AWS Lambda
Stars: ✭ 83 (-89.39%)
Mutual labels:  aws, aws-cli, cli
Awless
A Mighty CLI for AWS
Stars: ✭ 4,821 (+516.5%)
Mutual labels:  aws, aws-cli, cli
Aws Google Auth
Provides AWS STS credentials based on Google Apps SAML SSO auth (what a jumble!)
Stars: ✭ 428 (-45.27%)
Mutual labels:  aws, cli
Serverlessui
A command-line utility for deploying serverless applications to AWS. Complete with custom domains, deploy previews, TypeScript support, and more.
Stars: ✭ 434 (-44.5%)
Mutual labels:  aws, cli
Aws
A collection of bash shell scripts for automating various tasks with Amazon Web Services using the AWS CLI and jq.
Stars: ✭ 493 (-36.96%)
Mutual labels:  aws, aws-cli
Aws Security Viz
Visualize your aws security groups.
Stars: ✭ 511 (-34.65%)
Mutual labels:  aws, aws-cli
Aws Vault
A vault for securely storing and accessing AWS credentials in development environments
Stars: ✭ 5,626 (+619.44%)
Mutual labels:  aws, cli
Mt Aws Glacier
Perl Multithreaded Multipart sync to Amazon Glacier
Stars: ✭ 522 (-33.25%)
Mutual labels:  aws, cli
Cw
The best way to tail AWS CloudWatch Logs from your terminal
Stars: ✭ 368 (-52.94%)
Mutual labels:  aws, cli
Aws Demos
A hands on repo with multiple demonstrations on AWS 🎓
Stars: ✭ 324 (-58.57%)
Mutual labels:  aws, aws-cli
Org Formation Cli
Better than landingzones!
Stars: ✭ 471 (-39.77%)
Mutual labels:  aws, cli
Prowler
Prowler is a security tool to perform AWS security best practices assessments, audits, incident response, continuous monitoring, hardening and forensics readiness. It contains more than 200 controls covering CIS, ISO27001, GDPR, HIPAA, SOC2, ENS and other security frameworks.
Stars: ✭ 4,561 (+483.25%)
Mutual labels:  aws, aws-cli
Cloudiscovery
The tool to help you discover resources in the cloud environment
Stars: ✭ 298 (-61.89%)
Mutual labels:  aws, aws-cli
Ecs Deploy
Powerful CLI tool to simplify Amazon ECS deployments, rollbacks & scaling
Stars: ✭ 541 (-30.82%)
Mutual labels:  aws, aws-cli
Ttyplot
a realtime plotting utility for terminal/console with data input from stdin
Stars: ✭ 532 (-31.97%)
Mutual labels:  cli, pipe
Terragrunt
Terragrunt is a thin wrapper for Terraform that provides extra tools for working with multiple Terraform modules.
Stars: ✭ 5,446 (+596.42%)
Mutual labels:  aws, cli
Sagify
MLOps for AWS SageMaker. www.sagifyml.com
Stars: ✭ 277 (-64.58%)
Mutual labels:  aws, cli

Bash-my-AWS

Dec 2019: New Bash-my-AWS website has extensive documentation at https://bash-my-aws.org/

Bash-my-AWS is a simple but powerful set of CLI commands for managing resources on Amazon Web Services.

They harness the power of Amazon's AWSCLI, while abstracting away verbosity.

The project implements some innovative patterns but (arguably) remains simple, beautiful and readable.

screencast

Introduction

Short, Memorable Commands

There are two main types of commands.

1. Resource Listing Commands

These generally consist of the pluralised form of the resource name.

$ buckets
example-assets   2019-12-08  02:35:44.758551
example-logs     2019-12-08  02:35:52.669771
example-backups  2019-12-08  02:35:56.579434
$ stacks
nagios      CREATE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
postgres01  CREATE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
postgres02  CREATE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
prometheus  CREATE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
$ keypairs
alice  8f:85:9a:1e:6c:76:29:34:37:45:de:7f:8d:f9:70:eb
bob    56:73:29:c2:ad:7b:6f:b6:f2:f3:b4🇩🇪e4:2b:12:d4
carol  29:4e:1c:cb:ba:d4:85:0e:4f:b6:34:4c:d4:79:32:00

2. Resource detail/action commands

These generally consist of a resource name and action separated by a hyphen. This makes discovering them via shell completion simple.

Some retrieve information about resources while others make changes to them.

$ keypair-delete alice bob
You are about to delete the following EC2 SSH KeyPairs:
alice
bob
Are you sure you want to continue? y

See the Command Reference for a full list of commands.

Shell Command Completion

In the example above, shell autocompletion retrieved the existing EC2 Keypair names (alice, bob) from AWS. This helps avoid the need to rely on human memory or terminal copypasta.

Additionally, all of the bash-my-aws commands are available as completions for the bma command, so bma[tab][tab] will produce a list of all of the available commands.

Unix Pipeline Friendly

The commands themselves are line oriented and work nicely in unix pipelines with other unix commands (e.g. grep, awk, etc).

$ stacks | grep postgres
postgres01  CREATE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
postgres02  CREATE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED

They also work incredibly well with each other due to the way they treat input from STDIN. The first token from each line of STDIN is taken to be a resource identifier (and the rest is discarded).

$ stacks | grep postgres | stack-delete
You are about to delete the following stacks:
postgres01
postgres02
Are you sure you want to continue? y

Some users have compared this User Experience to functionality in Windows Powershell.

Convenient Shortcuts

Bash-my-AWS is insanely simple to pick up and start using but contains a lot of convenient shortcuts you can make use of.

Example: resource listing commands accept a filter argument, removing the need for | grep.

In the following example someone has given a CloudFormation stack a really long name:

$ stacks
nagios                             CREATE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
postgres01                         DELETE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
postgres02                         DELETE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
prometheus                         CREATE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
stack-with-a-annoyingly-long-name  CREATE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED

This affects the output when we look at our Postgres stacks:

$ stacks | grep postgres
postgres01                         DELETE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
postgres02                         DELETE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED

The resource listing command can filter output before applying column.

$ stacks postgres
postgres01  DELETE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED
postgres02  DELETE_COMPLETE  2011-05-23T15:47:44Z  NEVER_UPDATED  NOT_NESTED

Quickstart

Prerequisites

Installation

As shown below, you may simply clone the GitHub repo and source the files required. (You should probably fork it instead to keep your customisations)

$ git clone https://github.com/bash-my-aws/bash-my-aws.git ~/.bash-my-aws

Put the following in your shell's startup file:

export PATH="$PATH:$HOME/.bash-my-aws/bin"
source ~/.bash-my-aws/aliases

# For ZSH users, uncomment the following two lines:
# autoload -U +X compinit && compinit
# autoload -U +X bashcompinit && bashcompinit

source ~/.bash-my-aws/bash_completion.sh

Why use shell aliases?

Bash-my-AWS began as a collection of bash functions, sourced into your shell. More recently, the default suggestion has been to load aliases that execute a small wrapper script that loads the functions and executes the desired function.

After years of zsh users asking for support, one stepped up and identified a changes that would eliminate any shell compatibility problems without compromising the functionaility, simplicity and discoverability of the project. Massive thanks to @ninth-dev for this.

# bash users may source the functions instead of loading the aliases
if [ -d ${HOME}/.bash-my-aws ]; then
  for f in ~/.bash-my-aws/lib/*-functions; do source $f; done
fi

Usage

Running Commands

The default way to run the commands is using the aliases:

$ instances
i-e6f097f6ea4457757  ami-123456789012  t3.nano  running  example-ec2-ap-southeast-2  2019-12-07T08:12:00.000Z  ap-southeast-2a  None
i-b983805b4b254f749  ami-123456789012  t3.nano  running  postfix-prod                2019-12-07T08:26:30.000Z  ap-southeast-2a  None
i-fed39ebe7204dfd37  ami-123456789012  t3.nano  running  postfix-prod                2019-12-07T08:26:34.000Z  ap-southeast-2a  None
i-47955eb46d98b4dd8  ami-123456789012  t3.nano  running  prometheus                  2019-12-07T08:27:02.000Z  ap-southeast-2a  None
i-8d25b78d40d17f38a  ami-123456789012  t3.nano  running  plex-server                 2019-12-07T08:27:38.000Z  ap-southeast-2a  None

It's also possible to run them using the bma wrapper. (This is sometimes required when using a restrictive auth tool.)

$ bma instances
i-e6f097f6ea4457757  ami-123456789012  t3.nano  running  example-ec2-ap-southeast-2  2019-12-07T08:12:00.000Z  ap-southeast-2a  None
i-b983805b4b254f749  ami-123456789012  t3.nano  running  postfix-prod                2019-12-07T08:26:30.000Z  ap-southeast-2a  None
i-fed39ebe7204dfd37  ami-123456789012  t3.nano  running  postfix-prod                2019-12-07T08:26:34.000Z  ap-southeast-2a  None
i-47955eb46d98b4dd8  ami-123456789012  t3.nano  running  prometheus                  2019-12-07T08:27:02.000Z  ap-southeast-2a  None
i-8d25b78d40d17f38a  ami-123456789012  t3.nano  running  plex-server                 2019-12-07T08:27:38.000Z  ap-southeast-2a  None

Discovering Commands

For each resource type, there is a command to list them:

$ instances
i-e6f097f6ea4457757  ami-123456789012  t3.nano  running  example-ec2-ap-southeast-2  2019-12-07T08:12:00.000Z  ap-southeast-2a  None
i-b983805b4b254f749  ami-123456789012  t3.nano  running  postfix-prod                2019-12-07T08:26:30.000Z  ap-southeast-2a  None
i-fed39ebe7204dfd37  ami-123456789012  t3.nano  running  postfix-prod                2019-12-07T08:26:34.000Z  ap-southeast-2a  None
i-47955eb46d98b4dd8  ami-123456789012  t3.nano  running  prometheus                  2019-12-07T08:27:02.000Z  ap-southeast-2a  None
i-8d25b78d40d17f38a  ami-123456789012  t3.nano  running  plex-server                 2019-12-07T08:27:38.000Z  ap-southeast-2a  None

and a number of commands to act on these resources:

$ instance-[TAB][TAB]
instance-asg          instance-ssh-details  instance-termination-protection
instance-az           instance-stack        instance-termination-protection-disable
instance-console      instance-start        instance-termination-protection-enable
instance-dns          instance-state        instance-type
instance-iam-profile  instance-stop         instance-userdata
instance-ip           instance-tags         instance-volumes
instance-ssh          instance-terminate    instance-vpc

Whether you're new to the tools or just have a bad memory, bash completion makes discovering these commands simple.

See the Command Reference for a full list of commands and usage examples.

Piping Between Commands

This is where the magic happens!

The first token on each line is almost always a resource identifier. When you pipe output between the commands they just take the first token from each line.

$ instances | grep postfix | instance-ip
i-b983805b4b254f749  10.190.1.70    54.214.71.51
i-fed39ebe7204dfd37  10.135.204.82  54.214.26.190

!!! Note Most commands that list resources (stacks, instances , etc) accept filter term as first arg. As well as reducing keystrokes, it can also improve output as columnisation is done after filtering.

    $ instances postfix | instance-ip
    i-b983805b4b254f749  10.190.1.70    54.214.71.51
    i-fed39ebe7204dfd37  10.135.204.82  54.214.26.190

Inspecting Commands

For those interested in how it works:

  • Each command is a bash function.
  • Most are very simple and wrap an AWSCLI command.

For a quick look at how a command works, you can use bma type:

$ bma type instances
instances is a function
instances () 
{ 
    local instance_ids=$(__bma_read_inputs);
    local filters=$(__bma_read_filters [email protected]);
    aws ec2 describe-instances $([[ -n ${instance_ids} ]] && echo --instance-ids ${instance_ids}) --query "
      Reservations[].Instances[][
        InstanceId,
        ImageId,
        InstanceType,
        State.Name,
        [Tags[?Key=='Name'].Value][0][0],
        LaunchTime,
        Placement.AvailabilityZone,
        VpcId
      ]" --output text | grep -E -- "$filters" | LC_ALL=C sort -b -k 6 | column -s'	' -t
}

A prettier version can be found in the source code:

# ~/.bash-my-aws/lib/instance-functions
instances() {
  local instance_ids=$(__bma_read_inputs)
  local filters=$(__bma_read_filters [email protected])

  aws ec2 describe-instances                                            \
    $([[ -n ${instance_ids} ]] && echo --instance-ids ${instance_ids})  \
    --query "
      Reservations[].Instances[][
        InstanceId,
        ImageId,
        InstanceType,
        State.Name,
        [Tags[?Key=='Name'].Value][0][0],
        LaunchTime,
        Placement.AvailabilityZone,
        VpcId
      ]"                                                               \
    --output text       |
  grep -E -- "$filters" |
  LC_ALL=C sort -b -k 6 |
  column -s$'\t' -t
}

For more info on AWSCLI query syntax, check out http://jmespath.org/tutorial.html

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].