Skip to content

Latest commit

 

History

History
267 lines (191 loc) · 8.56 KB

README.md

File metadata and controls

267 lines (191 loc) · 8.56 KB

bash-my-aws

bash-my-aws assists Infrastructure Jockeys using Amazon Web Services from the command line.

This project provides short, memorable commands for realtime control of resources in Amazon AWS. The goal is to reduce the time between intention and effect.

These functions make extensive use of the incredibly powerful AWSCLI.

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-universe/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 the 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 can still source the functions instead of loading the aliases:

# 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

Authenticate to AWS in a terminal that has bash-my-aws loaded. You should now be able to explore the commands.

We'll start off with stack commands as an example but there are many other resource types supported. Checkout the full list in ~/.bash-my-aws/functions

With aliases (or sourced functions) :

$ stacks

Using the bma wrapper:

$ bma stacks

Typing stack[TAB][TAB] will list available functions for CloudFormation:

$ stacks # lists CloudFormation stacks

$ stack-[TAB][TAB]
stack-arn            stack-elbs           stack-recreate       stack-tags-text
stack-asg-instances  stack-events         stack-resources      stack-tail
stack-asgs           stack-exports        stack-status         stack-template
stack-cancel-update  stack-failure        stack-tag            stack-update
stack-create         stack-instances      stack-tag-apply      stack-validate
stack-delete         stack-outputs        stack-tag-delete
stack-diff           stack-parameters     stack-tags

$ aws-[TAB][TAB]
aws-account-alias                 aws-account-cost-recommendations  aws-account-id
aws-account-cost-explorer         aws-account-each                  aws-panopticon

$ asgs # lists Autoscaling groups

$ asg-[TAB][TAB]
asg-capacity             asg-min-size-set         asg-stack
asg-desired-size-set     asg-processes_suspended  asg-suspend
asg-instances            asg-resume
asg-max-size-set         asg-scaling-activities

$ buckets # lists S3 buckets
bucket-acls

$ elbs # lists Elastic Load Balancers (classic)
$ elb-[TAB][TAB]
elb-dnsname    elb-instances

$ instances # lists EC2 instances

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

$ keypairs # lists EC2 SSH KeyPairs

$ keypair-[TAB][TAB]
keypair-create  keypair-delete

$ vpcs # lists VPCs

$ vpc-[TAB][TAB]
vpc-default-delete    vpc-lambda-functions  vpc-rds
vpc-dhcp-options-ntp  vpc-nat-gateways      vpc-route-tables
vpc-igw               vpc-network-acls      vpc-subnets

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

Piping output between functions

We're very excited to announce this functionality.

Most bash-my-aws functions will accept AWS Resource Ids from STDIN. This means you can pipe output from many functions into other functions.

$ instances | grep splunk | instance-stack | stack-status
splunk-forwarder  UPDATE_COMPLETE
splunk-forwarder-role CREATE_COMPLETE

Usage examples

cloudformation-functions

Create a stack

This function gives you tab completion for filenames (missing from AWSCLI).

$ stack-create
USAGE: stack-create stack

$ stack-create example      # creates stack called example using example.json

It's also one of the functions that allows you to omit the template name if it exists in the current directory and matches the stack name with '.json' appended.

It's even smart enough to detect that you've added '-blah' to the stack name.

$ stack-create example-test # creates stack called example-test using example.json

List stacks

This is basically 'ls' with the ability to filter by a search string

$ stacks # call without filter argument to return all stacks
example-app
example-app-test
example-app-dev
something
something-else

$ stacks example # Or filter out the relevant stacks
example-app
example-app-test
example-app-dev

See what changes will be made by updating a stack

$ stack-diff
USAGE: stack-diff stack [template-file]

$ stack-diff example-dev
template for stack (example) and contents of file (example-dev.json) are the same

e--- params
+++ example-params-dev.json
@@ -4,7 +4,7 @@
         "ParameterKey": "slipGeneratorRolePath"
     },
     {
-        "ParameterValue": "something",
+        "ParameterValue": "something-else",
         "ParameterKey": "storageBucketName"
     },
     {

Updating a stack

$ stack-update
USAGE: stack-update stack [template-file] [params-file]

$ stack-update example # creates stack called example using example.json
...

Deleting a stack

$ stack-delete
USAGE: stack-delete stack

$ stack-delete example # deletes stack called example
...

Tailing stack events

The create/update tasks call this one but it can also be called directly. It watches events for a stack until it sees them complete or fail.

$ stack-tail my-stack
---------------------------------------------------------------------------------------------------------------------------------------------------------
|                                                                  DescribeStackEvents                                                                  |
+--------------------------+-------------------------------+-------------------------------------------+------------------------------------------------+
|  2015-07-25T23:13:21.628Z|  MyStack                      |  AWS::CloudFormation::Stack               |  CREATE_IN_PROGRESS                            |
|  2015-07-25T23:13:27.221Z|  AppServerSSHSecurityGroup    |  AWS::EC2::SecurityGroup                  |  CREATE_IN_PROGRESS                            |
|  2015-07-25T23:13:27.235Z|  DeploymentSQSQueue           |  AWS::SQS::Queue                          |  CREATE_IN_PROGRESS                            |
|  2015-07-25T23:13:27.291Z|  InternalELBSecurityGroup     |  AWS::EC2::SecurityGroup                  |  CREATE_IN_PROGRESS                            |
|  2015-07-25T23:13:27.537Z|  AppServerRole                |  AWS::IAM::Role                           |  CREATE_IN_PROGRESS                            |
|  2015-07-25T23:13:28.244Z|  DeploymentSQSQueue           |  AWS::SQS::Queue                          |  CREATE_IN_PROGRESS                            |
|  2015-07-25T23:13:28.769Z|  DeploymentSQSQueue           |  AWS::SQS::Queue                          |  CREATE_COMPLETE                               |
+--------------------------+-------------------------------+-------------------------------------------+------------------------------------------------+