Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aliases
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ alias aws-account-cost-explorer='~/.bash-my-aws/bin/bma aws-account-cost-explore
alias aws-account-cost-recommendations='~/.bash-my-aws/bin/bma aws-account-cost-recommendations'
alias aws-account-each='~/.bash-my-aws/bin/bma aws-account-each'
alias aws-account-id='~/.bash-my-aws/bin/bma aws-account-id'
alias aws-accounts='~/.bash-my-aws/bin/bma aws-accounts'
alias aws-panopticon='~/.bash-my-aws/bin/bma aws-panopticon'
alias bucket-acls='~/.bash-my-aws/bin/bma bucket-acls'
alias bucket-remove='~/.bash-my-aws/bin/bma bucket-remove'
Expand Down
10 changes: 10 additions & 0 deletions bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ _bma_asgs_completion() {
COMPREPLY=($(compgen -W "${options}" -- ${word}))
return 0
}
_bma_aws-accounts_completion() {
local command="$1"
local word="$2"
local options=$(bma aws-accounts | awk '{ print $1 }')
COMPREPLY=($(compgen -W "${options}" -- ${word}))
return 0
}
_bma_buckets_completion() {
local command="$1"
local word="$2"
Expand Down Expand Up @@ -127,6 +134,9 @@ complete -F _bma_asgs_completion asg-scaling-activities
complete -F _bma_asgs_completion asg-stack
complete -F _bma_asgs_completion asg-suspend
complete -F _bma_asgs_completion asgs
complete -F _bma_aws-accounts_completion aws-account-cost-explorer
complete -F _bma_aws-accounts_completion aws-account-cost-recommendations
complete -F _bma_aws-accounts_completion aws-accounts
complete -F _bma_buckets_completion bucket-acls
complete -F _bma_buckets_completion bucket-remove
complete -F _bma_buckets_completion bucket-remove-force
Expand Down
14 changes: 14 additions & 0 deletions docs/command-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ the most interest to readers.
## aws-account-commands


### aws-accounts

List AWS Accounts in an [Organization](https://aws.amazon.com/organizations/)

$ aws-accounts
089834043791 ACTIVE INVITED 1488257653.638 mike-aws@bailey.net.au
812094344564 ACTIVE CREATED 1537922950.972 mike-bash-my-aws@bailey.net.au
001721147249 ACTIVE INVITED 1548752330.723 mike@bailey.net.au
867077406134 ACTIVE CREATED 1557910982.885 mike-deleteme@bailey.net.au
892345420873 ACTIVE CREATED 1557911243.358 mike-delete@bailey.net.au

*Optionally provide a filter string for a `| grep` effect with tighter columisation:*


### aws-account-alias

Retrieve AWS Account Alias for current account
Expand Down
1 change: 1 addition & 0 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ aws-account-cost-explorer
aws-account-cost-recommendations
aws-account-each
aws-account-id
aws-accounts
aws-panopticon
bucket-acls
bucket-remove
Expand Down
33 changes: 33 additions & 0 deletions lib/aws-account-functions
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@
# authenticated to or the Account IDs provided to them.


aws-accounts() {

# List AWS Accounts in an [Organization](https://aws.amazon.com/organizations/)
#
# $ aws-accounts
# 089834043791 ACTIVE INVITED 1488257653.638 mike-aws@bailey.net.au
# 812094344564 ACTIVE CREATED 1537922950.972 mike-bash-my-aws@bailey.net.au
# 001721147249 ACTIVE INVITED 1548752330.723 mike@bailey.net.au
# 867077406134 ACTIVE CREATED 1557910982.885 mike-deleteme@bailey.net.au
# 892345420873 ACTIVE CREATED 1557911243.358 mike-delete@bailey.net.au
#
# *Optionally provide a filter string for a `| grep` effect with tighter columisation:*

local account_ids=$(skim-stdin)
local filters=$(__bma_read_filters "$@")

aws organizations list-accounts \
--output text \
--query "
Accounts[${account_ids:+?contains(['${account_ids// /"','"}'], Id)}].[
Id,
Status,
JoinedMethod,
JoinedTimestamp,
Email
]" |
grep -E -- "$filters" |
LC_ALL=C sort -b -k 4 |
column -s$'\t' -t

}


aws-account-alias() {

# Retrieve AWS Account Alias for current account
Expand Down
7 changes: 6 additions & 1 deletion scripts/build-completions
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@ done

cat "${bma_path}/scripts/completions/bma-completion"



# dont add auto_completions for these functions
funcs_no_completion=(
asg-desired-size-set
asg-max-size-set
asg-min-size-set
aws-account-alias
aws-account-each
aws-account-id
keypair-create
region-each
regions
stack-validate
stack-create
stack-tag
stack-tag-apply
stack-tag-delete
stack-validate
vpc-default-delete
vpc-dhcp-options-ntp
vpc-endpoint-services
Expand Down
7 changes: 7 additions & 0 deletions scripts/completions/aws-account-completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_bma_aws-accounts_completion() {
local command="$1"
local word="$2"
local options=$(bma aws-accounts | awk '{ print $1 }')
COMPREPLY=($(compgen -W "${options}" -- ${word}))
return 0
}