From 189570cf269f902d5375ef2e261f0407211ef25e Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 14 Dec 2022 15:35:17 +1100 Subject: [PATCH 01/44] stack drift, more asg --- aliases | 3 ++ lib/instance-functions | 8 ++-- lib/rds-functions | 5 +- lib/stack-functions | 104 ++++++++++++++++++++++++++++++++++++----- 4 files changed, 105 insertions(+), 15 deletions(-) diff --git a/aliases b/aliases index 3cfe2ec2..ccf2adfc 100644 --- a/aliases +++ b/aliases @@ -160,7 +160,10 @@ alias stack-asgs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-asgs' alias stack-cancel-update='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-cancel-update' alias stack-create='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-create' alias stack-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-delete' +alias stack-describe-drift='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-describe-drift' +alias stack-detect-drift='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-detect-drift' alias stack-diff='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-diff' +alias stack-diff-drift='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-diff-drift' alias stack-elbs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-elbs' alias stack-events='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-events' alias stack-exports='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-exports' diff --git a/lib/instance-functions b/lib/instance-functions index 96d3a599..51ae37e4 100644 --- a/lib/instance-functions +++ b/lib/instance-functions @@ -22,6 +22,8 @@ instances() { local instance_ids=$(skim-stdin) local filters=$(__bma_read_filters $@) + local sort_key=5 + [ -z $filters ] && sort_key=6 aws ec2 describe-instances \ ${instance_ids/#/'--instance-ids '} \ @@ -34,11 +36,10 @@ instances() { State.Name, [Tags[?Key=='Name'].Value][0][0], LaunchTime, - Placement.AvailabilityZone, - VpcId + Placement.AvailabilityZone ]" | grep -E -- "$filters" | - LC_ALL=C sort -b -k 6 | + LC_ALL=C sort -b -k $sort_key | column -s$'\t' -t } @@ -87,6 +88,7 @@ instance-az() { Reservations[].Instances[][ [ InstanceId, + VpcId, Placement.AvailabilityZone ] ][]" | diff --git a/lib/rds-functions b/lib/rds-functions index 8d524d08..a0270523 100644 --- a/lib/rds-functions +++ b/lib/rds-functions @@ -19,11 +19,14 @@ rds-db-instances() { --output text \ --query "DBInstances[].[ DBInstanceIdentifier, + DBInstanceClass, Engine, EngineVersion, DBInstanceStatus, - DBName + DBName, + MultiAZ ]" | + sed 's/True$/MultiAZ/g' | sed 's/False$//' | grep -E -- "$filters" | LC_ALL=C sort -b -k 1 | column -s$'\t' -t diff --git a/lib/stack-functions b/lib/stack-functions index 153a82a3..754bafa6 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -700,19 +700,20 @@ stack-tail() { stack-template() { - # Return template of a stack - - local inputs=$(skim-stdin "$@") - local stack=$(_bma_stack_name_arg ${inputs}) + # Return template of each stack + local stacks=$(skim-stdin "$@") - [[ -z ${stack} ]] && __bma_usage "stack" && return 1 + [[ -z ${stacks} ]] && __bma_usage "stack [stack]" && return 1 + local stack + for stack in $stacks; do - aws cloudformation get-template \ - --stack-name "$stack" \ - --query TemplateBody | - jq --raw-output --sort-keys . | - sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' # remove trailing blank lines + aws cloudformation get-template \ + --stack-name "$stack" \ + --query TemplateBody | + jq --raw-output --sort-keys . | + sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' # remove trailing blank lines # sometimes appended by jq + done } @@ -791,6 +792,87 @@ stack-validate() { } +stack-detect-drift() { + + # Detect drift for provided stacks; and print coloured diff + local stacks=$(skim-stdin "$@") + [[ -z ${stacks} ]] && __bma_usage "stack [stack]" && return 1 + + for stack in $stacks; do + driftDetectionId=$(aws cloudformation detect-stack-drift \ + --stack-name "$stack" --output text) + DetectionStatus="" + while [[ "$DetectionStatus" != "DETECTION_COMPLETE" ]]; do + printf "." + DescribeDriftDetectionStatus=$(aws cloudformation describe-stack-drift-detection-status \ + --stack-drift-detection-id $driftDetectionId ) + DetectionStatus=$(echo $DescribeDriftDetectionStatus | jq --raw-output .DetectionStatus ) + StackDriftStatus=$(echo $DescribeDriftDetectionStatus | jq --raw-output .StackDriftStatus) + sleep 5; + done + if [[ "$StackDriftStatus" == "IN_SYNC" ]]; then + echo + echo "$stack is in sync" + else + echo "$stack has drifted" + stack-diff-drift $stack + fi + done + +} + +stack-describe-drift() { + + # List stack-tags applied to a stack + + local inputs=$(skim-stdin "$@") + local stack=$(_bma_stack_name_arg ${inputs}) + + [[ -z ${stack} ]] && __bma_usage "stack" && return 1 + + stackResourceDrifts=$( aws cloudformation describe-stack-resource-drifts \ + --stack-name "$stack" \ + --query 'StackResourceDrifts[*].{StackId:StackId,ExpectedProperties:ExpectedProperties,ActualProperties:ActualProperties}' ) +# jq -S <<< $stackResourceDrifts + ExpectedProperties=$(echo $stackResourceDrifts | jq --raw-output .[].ExpectedProperties) +# ExpectedPropertiesPretty=$(jq . -S --raw-output <<< "$ExpectedProperties") + ActualProperties=$(echo $stackResourceDrifts | jq --raw-output .[].ActualProperties) +# ActualPropertiesPretty=$(jq . -S --raw-output <<< "$ActualProperties") + echo + echo "Expected Properties:" + jq . <<< "$ExpectedProperties" + echo "Actual Properties:" + jq . <<< "$ActualProperties" + echo + +} + +stack-diff-drift() { + + # List stack-tags applied to a stack + + local inputs=$(skim-stdin "$@") + local stack=$(_bma_stack_name_arg ${inputs}) + + [[ -z ${stack} ]] && __bma_usage "stack" && return 1 + + stackResourceDrifts=$( aws cloudformation describe-stack-resource-drifts \ + --stack-name "$stack" \ + --query 'StackResourceDrifts[*].{StackId:StackId,ExpectedProperties:ExpectedProperties,ActualProperties:ActualProperties}' ) +# jq -S <<< $stackResourceDrifts + ExpectedProperties=$(echo $stackResourceDrifts | jq --raw-output .[].ExpectedProperties) + ExpectedPropertiesPretty=$(jq . -S --raw-output <<< "$ExpectedProperties") + ActualProperties=$(echo $stackResourceDrifts | jq --raw-output .[].ActualProperties) + ActualPropertiesPretty=$(jq . -S --raw-output <<< "$ActualProperties") + echo + # TODO : check whether diff is installed, otherwise just print $ExpectedPropertiesPretty and $ActualPropertiesPretty + echo "The diff ( Expected | Actual )" + diff -y --left-column --color=always <(printf %s "$ExpectedPropertiesPretty") <(printf %s "$ActualPropertiesPretty") + +} + + + stack-diff(){ # Compare live stack against local template (and optional params file) @@ -845,7 +927,7 @@ _bma_stack_diff_template() { elif command -v icdiff; then local DIFF_CMD=icdiff else - local DIFF_CMD=diff + local DIFF_CMD='diff --color=always' fi $DIFF_CMD -u \ From ff2adf53d71c81c68b14ac46496790a24f0bcb78 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 14 Dec 2022 15:36:03 +1100 Subject: [PATCH 02/44] stack drift, elasticaches --- bash_completion.sh | 3 +++ docs/command-reference.md | 17 ++++++++++++++++- functions | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bash_completion.sh b/bash_completion.sh index 460734fe..7c149b0d 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -202,7 +202,10 @@ complete -F _bma_stacks_completion stack-asg-instances complete -F _bma_stacks_completion stack-asgs complete -F _bma_stacks_completion stack-cancel-update complete -F _bma_stacks_completion stack-delete +complete -F _bma_stacks_completion stack-describe-drift +complete -F _bma_stacks_completion stack-detect-drift complete -F _bma_stacks_completion stack-diff +complete -F _bma_stacks_completion stack-diff-drift complete -F _bma_stacks_completion stack-elbs complete -F _bma_stacks_completion stack-events complete -F _bma_stacks_completion stack-exports diff --git a/docs/command-reference.md b/docs/command-reference.md index d6259786..73f99c79 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -408,7 +408,7 @@ Show all events for CF stack until update completes or fails. ### stack-template -Return template of a stack +Return template of each stack ### stack-tags @@ -431,6 +431,21 @@ List outputs of a stack Validate a stack template +### stack-detect-drift + +Detect drift for provided stacks; and print coloured diff + + +### stack-describe-drift + +List stack-tags applied to a stack + + +### stack-diff-drift + +List stack-tags applied to a stack + + ### stack-diff Compare live stack against local template (and optional params file) diff --git a/functions b/functions index 76824304..d8efdaa0 100644 --- a/functions +++ b/functions @@ -63,6 +63,8 @@ columnise debug ecr-repositories ecr-repository-images +elasticaches +elasticache-replication-groups elb-azs elb-dnsname elb-instances @@ -161,7 +163,10 @@ stack-asgs stack-cancel-update stack-create stack-delete +stack-describe-drift +stack-detect-drift stack-diff +stack-diff-drift stack-elbs stack-events stack-exports From d15ab9bf1e2b169cc57b1a0d0fdadfc438fe16ca Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 22 Sep 2023 09:26:31 +1000 Subject: [PATCH 03/44] add complex ecs and simple elasticache queries --- lib/ecs-functions | 118 ++++++++++++++++++++++++++++++++++++++ lib/elasticache-functions | 56 ++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 lib/ecs-functions create mode 100644 lib/elasticache-functions diff --git a/lib/ecs-functions b/lib/ecs-functions new file mode 100644 index 00000000..e080a4c1 --- /dev/null +++ b/lib/ecs-functions @@ -0,0 +1,118 @@ +#!/bin/bash +# +# ecs-functions +## +# Shortcut the complicated dependencies between clusters, services, and tasks in the ecs cli + +ecs-clusters() { + # List ECS clusters + # output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount + # if you pass an argument, it'll filter for clusters whose ARN contains your text + # + # $ ecs-clusters test + # test-octopus-ecs-cluster ACTIVE 1 1 0 + # test1-ecs-cluster ACTIVE 3 1 0 + # test3-ecs-cluster ACTIVE 3 1 0 + # test2-ecs-cluster ACTIVE 3 3 0 + + local cluster=$(__bma_read_filters $@) # Filter output by arguments (optional) +# echo "cluster=$cluster" + aws ecs describe-clusters \ + --clusters $(aws ecs list-clusters --query "clusterArns[?contains(@, \`${cluster}\`) == \`true\`]" --output text) \ + --query "clusters[].[clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount]" \ + --output text | + LC_ALL=C sort -b -k 2| + columnise +} + +ecs-services() { + + # List ECS services + # output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt + # + # gets all clusters if no filter passed in + # if you do pass a filter: + # 1. if your filter is the name of one of your clusters, it will list the services in that cluster (eg ecs-clusters test1 | ecs-services) + # 2. if your filter is not a cluster name, it will list the services in all clusters whose names match your filter (ie it filters on cluster name not service name) + # 3. if you do not pass a filter, it will list all services in all clusters + # + # $ ecs-clusters test1|ecs-services + # test1-ecs-admin-7URaUr0YGJHi ACTIVE 0 0 0 2023-09-13T17:16:48.198000+10:00 + # test1-ecs-public-wEaTAqGXqbpq ACTIVE 0 0 0 2023-09-13T16:54:54.162000+10:00 + # test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 + + local filter=$(skim-stdin "$@") + local cluster_names=$filter +# check for input that isn't a valid cluster name and use it as a regex... + if [[ -z "$cluster_names" || "$(aws ecs describe-clusters --clusters $cluster_names --query "failures[].reason" --output text)" == "MISSING" ]]; then + #echo "cluster not found, using input to search" + cluster_names=$(ecs-clusters $cluster_names |skim-stdin) + if [[ -z "$cluster_names" ]]; then + #echo "no matching cluster, using input as a service filter" + cluster_names=$(ecs-clusters |skim-stdin) + service_filter=$filter + fi + fi +# echo "cluster_names=$cluster_names" + + local cluster_name + for cluster_name in $(echo $cluster_names); do # other scripts don't need this echo?? +# echo "cluster_name=$cluster_name" + aws ecs list-services \ + --cluster "$cluster_name" \ + --query " + serviceArns[?contains(@, \`${service_filter}\`) == \`true\`] + " \ + --output text | + xargs -d '\t' -I {} echo {} | + sed 's/.*\///' | + xargs -I {} \ + aws ecs describe-services \ + --cluster $cluster_name \ + --services {} \ + --query " + services[].[ + serviceName,status,desiredCount,runningCount,pendingCount,createdAt + ]" \ + --output text | + columnise +# --query "services[].[serviceName,status,desiredCount,runningCount,pendingCount,taskDefinition,createdAt,deployments[0].createdAt]" \ + + done +} + +ecs-tasks() { + + # List ECS tasks + # output includes taskDefinitionArn, createdAt, cpu, memory + # + # gets all tasks if no filter passed in + # if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) + # + # $ ecs-tasks test2 + # arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 + # arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 + # arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 + + local filter=$(skim-stdin "$@") + + for cluster_name in $(ecs-clusters |skim-stdin); do + #echo "cluster_name=$cluster_name" + aws ecs describe-tasks \ + --cluster $cluster_name \ + --query " + tasks[?contains(taskDefinitionArn, \`$filter\`) == \`true\`] + .[taskDefinitionArn, createdAt, cpu, memory] + " \ + --tasks $( \ + aws ecs list-tasks \ + --cluster $cluster_name \ + --output text | + sed 's/.*\///' \ + ) \ + --output text | + columnise + done + +# --query 'tasks[].{createdAt: createdAt,startedAt: startedAt,cpu: cpu,memory: memory,taskDefinitionArn: taskDefinitionArn,ephemeralStorage: ephemeralStorage.sizeInGiB,privateIpv4Address: containers[0].networkInterfaces[0].privateIpv4Address}' \ +} \ No newline at end of file diff --git a/lib/elasticache-functions b/lib/elasticache-functions new file mode 100644 index 00000000..ca0b1b89 --- /dev/null +++ b/lib/elasticache-functions @@ -0,0 +1,56 @@ +#!/bin/bash +# +# elasticache-functions +# +# + + +elasticaches() { + + # List elasticache thingies (code borrowed from target-groups) + # + # $ target-groups + # bash-my-aws-nlb-tg TCP 22 vpc-04636ebe5573f6f65 instance bash-my-aws-nlb + # bash-my-aws-alb-tg HTTP 443 vpc-04636ebe5573f6f65 instance bash-my-aws-alb + + local cache_names=$(skim-stdin) + local filters=$(__bma_read_filters $@) + + aws elasticache describe-cache-clusters \ + --output text \ + --query " + CacheClusters[][ + CacheClusterId, + CacheNodeType, + Engine, + EngineVersion, + CacheClusterStatus + ]" | + grep -E -- "$filters" | + LC_ALL=C sort -b | + column -s$'\t' -t +} + + +elasticache-replication-groups() { + + # + # Accepts a string to filter on + # This is not very useful without column headings. + # Most of the things you want to know about a replication group are boolean + # eg AutomaticFailover, MultiAZClusterEnabled, AtRestEncryptionEnabled etc + + local ec_names=$(skim-stdin "$@") + + for ec_name in $ec_names; do +# echo "ec_name=$ec_name" + aws elasticache describe-replication-groups \ + --output text \ + --query " + ReplicationGroups + [?contains(ReplicationGroupId, \`$ec_name\`) == \`true\`] + .[ReplicationGroupId,Status, CacheNodeType] + " + done | column -s$'\t' -t +} +# how to get ReplicationGroupId etc?? \ No newline at end of file From ca10c60c9efbf9294d28514c4e8012837d2e0c51 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 25 Sep 2023 11:54:42 +1000 Subject: [PATCH 04/44] tweak ecr functions --- aliases | 10 ++++++++++ functions | 10 +++++++++- lib/ecr-functions | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/aliases b/aliases index 115a35b7..a0224279 100644 --- a/aliases +++ b/aliases @@ -89,12 +89,19 @@ alias connector-group-members='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma connector alias connector-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma connector-groups' alias connectors='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma connectors' alias debug='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma debug' +alias deployment='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment' alias deployment-delete-danger='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-delete-danger' alias deployment-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-groups' +alias deployments='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments' alias deployments-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments-group' alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' alias ecr-repository-images='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repository-images' +alias ecs-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-clusters' +alias ecs-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-services' +alias ecs-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-tasks' +alias elasticache-replication-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticache-replication-groups' +alias elasticaches='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticaches' alias elb-azs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elb-azs' alias elb-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elb-dnsname' alias elb-instances='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elb-instances' @@ -108,6 +115,9 @@ alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-groups' alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s' +alias fargate-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-clusters' +alias fargate-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-services' +alias fargate-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-tasks' alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records' alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones' alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal' diff --git a/functions b/functions index bf860c57..2f7c1d41 100644 --- a/functions +++ b/functions @@ -89,14 +89,19 @@ connector-group-members connector-groups connectors debug +deployment deployment-delete-danger deployment-groups +deployments deployments-group distributions ecr-repositories ecr-repository-images -elasticaches +ecs-clusters +ecs-services +ecs-tasks elasticache-replication-groups +elasticaches elb-azs elb-dnsname elb-instances @@ -110,6 +115,9 @@ elbv2-dnsname elbv2-subnets elbv2-target-groups elbv2s +fargate-clusters +fargate-services +fargate-tasks hosted-zone-ns-records hosted-zones iam-role-principal diff --git a/lib/ecr-functions b/lib/ecr-functions index e5db48ce..8ad317c8 100644 --- a/lib/ecr-functions +++ b/lib/ecr-functions @@ -34,6 +34,8 @@ ecr-repository-images() { local repository_names=$(skim-stdin "$@") # XXX Display USAGE if no repository_names passed in + local repository_names=$(skim-stdin "$@") + [[ -z ${repository_names} ]] && __bma_usage "ecr" && return 1 local repository_name for repository_name in $repository_names; do From ac92434c7a27547be03c8a5779ffb59562578fe1 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 25 Sep 2023 14:45:46 +1000 Subject: [PATCH 05/44] add scaling-ecs --- lib/autoscaling-functions | 42 +++++++++++++++++++++++++++++++++++++++ lib/ecs-functions | 3 ++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 lib/autoscaling-functions diff --git a/lib/autoscaling-functions b/lib/autoscaling-functions new file mode 100644 index 00000000..991cab16 --- /dev/null +++ b/lib/autoscaling-functions @@ -0,0 +1,42 @@ +#!/bin/bash +# +# autoscaling-functions +## +# show the current autoscale settings +# namespace | implemented +# ecs | yes +# elasticmapreduce | no +# ec2 | maybe +# appstream | maybe +# dynamodb | no +# rds | maybe +# sagemaker | no +# custom-resource | no +# comprehend | no +# lambda | no +# cassandra | no +# kafka | no +# elasticache | no +# neptune | no + + +scaling-ecs() { + # List autoscaling actions + # filter by environment (eg test1) or namespace (eg ecs) + # if you pass an argument, it'll filter for clusters whose ARN contains your text + # + # $ scaling-actions test + # test-octopus-ecs-cluster ACTIVE 1 1 0 + # test1-ecs-cluster ACTIVE 3 1 0 + # test3-ecs-cluster ACTIVE 3 1 0 + # test2-ecs-cluster ACTIVE 3 3 0 + + local filters=$(__bma_read_filters $@) # Filter output by arguments (optional) + aws application-autoscaling describe-scheduled-actions \ + --service-namespace ecs \ + --query "ScheduledActions[].[ScheduledActionName,Schedule,ScalableTargetAction.MinCapacity,ScalableTargetAction.MaxCapacity]" \ + --output text | + grep -E -- "$filters" | + LC_ALL=C sort -b -k 2| + columnise +} diff --git a/lib/ecs-functions b/lib/ecs-functions index e080a4c1..7a48bceb 100644 --- a/lib/ecs-functions +++ b/lib/ecs-functions @@ -98,6 +98,7 @@ ecs-tasks() { for cluster_name in $(ecs-clusters |skim-stdin); do #echo "cluster_name=$cluster_name" + # TODO: remove the account bit from the task definition, ie print gc3-test1-public:27 instead of arn:aws:ecs:ap-southeast-2:167642850091:task-definition/gc3-test1-public:27 aws ecs describe-tasks \ --cluster $cluster_name \ --query " @@ -115,4 +116,4 @@ ecs-tasks() { done # --query 'tasks[].{createdAt: createdAt,startedAt: startedAt,cpu: cpu,memory: memory,taskDefinitionArn: taskDefinitionArn,ephemeralStorage: ephemeralStorage.sizeInGiB,privateIpv4Address: containers[0].networkInterfaces[0].privateIpv4Address}' \ -} \ No newline at end of file +} From 30c0abc530e83bd4bb3fce7a54372e158c275315 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 25 Sep 2023 14:47:58 +1000 Subject: [PATCH 06/44] add scaling-ecs --- lib/autoscaling-functions | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/autoscaling-functions b/lib/autoscaling-functions index 991cab16..fbc82ef0 100644 --- a/lib/autoscaling-functions +++ b/lib/autoscaling-functions @@ -25,11 +25,13 @@ scaling-ecs() { # filter by environment (eg test1) or namespace (eg ecs) # if you pass an argument, it'll filter for clusters whose ARN contains your text # - # $ scaling-actions test - # test-octopus-ecs-cluster ACTIVE 1 1 0 - # test1-ecs-cluster ACTIVE 3 1 0 - # test3-ecs-cluster ACTIVE 3 1 0 - # test2-ecs-cluster ACTIVE 3 3 0 + # $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments +# test1-ecs-admin-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test1-ecs-public-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test2-ecs-admin-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test2-ecs-public-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test3-ecs-admin-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test3-ecs-public-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 local filters=$(__bma_read_filters $@) # Filter output by arguments (optional) aws application-autoscaling describe-scheduled-actions \ From eeb84bc0e93d3e2c6ee6d2df1571d266a49dfd9c Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Mon, 25 Sep 2023 20:50:48 +1000 Subject: [PATCH 07/44] add instance-id --- lib/instance-functions | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/instance-functions b/lib/instance-functions index 51ae37e4..35585f4b 100644 --- a/lib/instance-functions +++ b/lib/instance-functions @@ -44,6 +44,18 @@ instances() { } +instance-id() { + + # Just return the instance ID of whatever was passed in (so you can run a for loop, for instance) + # + # USAGE: instances [grep] | instance-id + + local instance_ids=$(skim-stdin "$@") + [[ -z $instance_ids ]] && __bma_usage "instance-id [instance-id]" && return 1 + echo $instance_ids | + column -s$'\t' -t +} + instance-asg() { # List autoscaling group membership of EC2 Instance(s) From 60b8e1273d1ca8be7c945ed9947ef03bcb757958 Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Wed, 27 Sep 2023 16:56:05 +1000 Subject: [PATCH 08/44] revise cluster-checking --- lib/ecs-functions | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/ecs-functions b/lib/ecs-functions index 7a48bceb..4f381354 100644 --- a/lib/ecs-functions +++ b/lib/ecs-functions @@ -3,6 +3,11 @@ # ecs-functions ## # Shortcut the complicated dependencies between clusters, services, and tasks in the ecs cli +# this is against the normal way bash-my-aws works +# it should be +# ecs-tasks [cluster-name] +# ecs-services [cluster-name] +# but then i don't know how to filter on the task/service name ecs-clusters() { # List ECS clusters @@ -42,17 +47,36 @@ ecs-services() { # test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 local filter=$(skim-stdin "$@") + echo "searching with $filter" local cluster_names=$filter # check for input that isn't a valid cluster name and use it as a regex... if [[ -z "$cluster_names" || "$(aws ecs describe-clusters --clusters $cluster_names --query "failures[].reason" --output text)" == "MISSING" ]]; then - #echo "cluster not found, using input to search" + echo "cluster not found, using input to search" cluster_names=$(ecs-clusters $cluster_names |skim-stdin) if [[ -z "$cluster_names" ]]; then - #echo "no matching cluster, using input as a service filter" + echo "no matching cluster, using input as a service filter" cluster_names=$(ecs-clusters |skim-stdin) service_filter=$filter fi fi + + +### wait that wasn't right. +## if $filter is empty just get all the clusters +## if $filter is not empty, loop through $filter to check for valid complete cluster names +## if there is one, skip the rest +## search for cluster names containing $filter +# if [[ -z "$cluster_names" ]]; then +# echo "no matching cluster, passing all clusters to search" +# cluster_names=$(ecs-clusters |skim-stdin) +# ## here we should loop through the $filter checking that each element is a cluster?, in case the ecs-clusters command returned more than one + ##for cluster_name in $(echo $cluster_names); do # other scripts don't need this echo?? +# elif [[ "$(aws ecs describe-clusters --clusters $cluster_names --query "failures[].reason" --output text)" == "MISSING" ]]; then +# echo "cluster not found, using input to search" +# cluster_names=$(ecs-clusters $cluster_names |skim-stdin) +# service_filter=$filter +# fi +# echo "cluster_names=$cluster_names" # echo "cluster_names=$cluster_names" local cluster_name @@ -77,7 +101,6 @@ ecs-services() { --output text | columnise # --query "services[].[serviceName,status,desiredCount,runningCount,pendingCount,taskDefinition,createdAt,deployments[0].createdAt]" \ - done } From c9d71292fd8166cda5266103b2a0a83f4fff6ea8 Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Tue, 3 Oct 2023 13:59:48 +1100 Subject: [PATCH 09/44] update build --- aliases | 6 +- bash_completion.sh | 1 + docs/command-reference.md | 124 +++++++++++++++++++++++++++++++++++++- functions | 6 +- 4 files changed, 128 insertions(+), 9 deletions(-) diff --git a/aliases b/aliases index a0224279..67179885 100644 --- a/aliases +++ b/aliases @@ -92,7 +92,6 @@ alias debug='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma debug' alias deployment='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment' alias deployment-delete-danger='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-delete-danger' alias deployment-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-groups' -alias deployments='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments' alias deployments-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments-group' alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' @@ -115,9 +114,6 @@ alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-groups' alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s' -alias fargate-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-clusters' -alias fargate-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-services' -alias fargate-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-tasks' alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records' alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones' alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal' @@ -131,6 +127,7 @@ alias instance-console='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-console alias instance-dns='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-dns' alias instance-health-set-unhealthy='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-health-set-unhealthy' alias instance-iam-profile='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-iam-profile' +alias instance-id='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-id' alias instance-ip='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-ip' alias instance-rdp='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-rdp' alias instance-ssh='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-ssh' @@ -198,6 +195,7 @@ alias resource-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-groups' alias resource-show='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-show' alias resourceids='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resourceids' alias resources='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resources' +alias scaling-ecs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma scaling-ecs' alias secrets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma secrets' alias service-principals='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma service-principals' alias skim-stdin='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma skim-stdin' diff --git a/bash_completion.sh b/bash_completion.sh index a921a5bd..e8fc781f 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -202,6 +202,7 @@ complete -F _bma_instances_completion instance-console complete -F _bma_instances_completion instance-dns complete -F _bma_instances_completion instance-health-set-unhealthy complete -F _bma_instances_completion instance-iam-profile +complete -F _bma_instances_completion instance-id complete -F _bma_instances_completion instance-ip complete -F _bma_instances_completion instance-rdp complete -F _bma_instances_completion instance-ssh diff --git a/docs/command-reference.md b/docs/command-reference.md index e09f9885..7a0832d6 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -533,6 +533,13 @@ List EC2 Instances i-806d8f1592e2a2efd ami-123456789012 t3.nano running postgres2 2019-12-10T08:17:22.000Z ap-southeast-2a None +### instance-id + +Just return the instance ID of whatever was passed in (so you can run a for loop, for instance) + + USAGE: instances [grep] | instance-id + + ### instance-asg List autoscaling group membership of EC2 Instance(s) @@ -905,7 +912,16 @@ List CloudFormation stack for asg(s) List scaling activities for Autoscaling Group(s) -azure.azcli +## autoscaling-commands + + +### scaling-ecs + +List autoscaling actions +filter by environment (eg test1) or namespace (eg ecs) +if you pass an argument, it'll filter for clusters whose ARN contains your text + + $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments ## azure-commands @@ -1237,6 +1253,9 @@ List routes of all endpoints for Front Door Profile(s) +azure.azcli + + ## backup-commands @@ -1326,6 +1345,19 @@ List logging status of Cloudtrails USAGE: cloudtrail-status cloudtrail [cloudtrail] +## codedeploy-commands + + +### deployment + +List deployments + + +### deployment-groups + +List min, desired and maximum capacities of EC2 Autoscaling Group(s) + + ## ecr-commands @@ -1339,6 +1371,96 @@ List ECR Repositories List images for ECR Repositories +## ecs-commands + + +### ecs-clusters + +List ECS clusters +output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount +if you pass an argument, it'll filter for clusters whose ARN contains your text + + $ ecs-clusters test + test-octopus-ecs-cluster ACTIVE 1 1 0 + test1-ecs-cluster ACTIVE 3 1 0 + test3-ecs-cluster ACTIVE 3 1 0 + test2-ecs-cluster ACTIVE 3 3 0 + + +### ecs-services + +List ECS services +output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt + +gets all clusters if no filter passed in +if you do pass a filter: +1. if your filter is the name of one of your clusters, it will list the services in that cluster (eg ecs-clusters test1 | ecs-services) +2. if your filter is not a cluster name, it will list the services in all clusters whose names match your filter (ie it filters on cluster name not service name) +3. if you do not pass a filter, it will list all services in all clusters + + $ ecs-clusters test1|ecs-services + test1-ecs-admin-7URaUr0YGJHi ACTIVE 0 0 0 2023-09-13T17:16:48.198000+10:00 + test1-ecs-public-wEaTAqGXqbpq ACTIVE 0 0 0 2023-09-13T16:54:54.162000+10:00 + test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 + + +### ecs-tasks + +List ECS tasks +output includes taskDefinitionArn, createdAt, cpu, memory + +gets all tasks if no filter passed in +if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) + + $ ecs-tasks test2 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 + + +## elasticache-commands + + +### elasticaches + +List elasticache thingies (code borrowed from target-groups) + + $ target-groups + bash-my-aws-nlb-tg TCP 22 vpc-04636ebe5573f6f65 instance bash-my-aws-nlb + bash-my-aws-alb-tg HTTP 443 vpc-04636ebe5573f6f65 instance bash-my-aws-alb + + +### elasticache-replication-groups + + +Accepts a string to filter on +This is not very useful without column headings. +Most of the things you want to know about a replication group are boolean +eg AutomaticFailover, MultiAZClusterEnabled, AtRestEncryptionEnabled etc + + +## elasticache-commands-littlelaptop + + +### elasticaches + +List elasticache thingies + + $ target-groups + bash-my-aws-nlb-tg TCP 22 vpc-04636ebe5573f6f65 instance bash-my-aws-nlb + bash-my-aws-alb-tg HTTP 443 vpc-04636ebe5573f6f65 instance bash-my-aws-alb + + +### elasticache-replication-groups + + +Accepts Target Group names on stdin or as arguments + + $ target-group-targets bash-my-aws-nlb-tg + i-4e15ece1de1a3f869 443 healthy bash-my-aws-nlb-tg + i-89cefa9403373d7a5 443 unhealthy bash-my-aws-nlb-tg + + ## elb-commands diff --git a/functions b/functions index 2f7c1d41..3cb8503b 100644 --- a/functions +++ b/functions @@ -92,7 +92,6 @@ debug deployment deployment-delete-danger deployment-groups -deployments deployments-group distributions ecr-repositories @@ -115,9 +114,6 @@ elbv2-dnsname elbv2-subnets elbv2-target-groups elbv2s -fargate-clusters -fargate-services -fargate-tasks hosted-zone-ns-records hosted-zones iam-role-principal @@ -131,6 +127,7 @@ instance-console instance-dns instance-health-set-unhealthy instance-iam-profile +instance-id instance-ip instance-rdp instance-ssh @@ -199,6 +196,7 @@ resource-groups resource-show resourceids resources +scaling-ecs secrets service-principals skim-stdin From 21a0fa6bad8ac1ecf6fe000c27342d1783c800db Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 5 Oct 2023 14:10:16 +1100 Subject: [PATCH 10/44] update build --- docs/command-reference.md | 70 ++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/docs/command-reference.md b/docs/command-reference.md index 7a0832d6..025a9f24 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -1353,9 +1353,33 @@ List logging status of Cloudtrails List deployments +### deployments + +List all deployment IDs for a deployment group (not useful for the user, only internal) +# ?? if no deployment group, could we list all deployments for this application, with their groups and statuses? + + ### deployment-groups -List min, desired and maximum capacities of EC2 Autoscaling Group(s) +List all deployment groups for an application + + +## codedeploy-commands~ + + +### deployment + +List deployments + + +### deployments + +List all deployment IDs for a deployment group (not useful for the user, only internal) + + +### deployment-groups + +List all deployment groups for an application ## ecr-commands @@ -1439,28 +1463,6 @@ Most of the things you want to know about a replication group are boolean eg AutomaticFailover, MultiAZClusterEnabled, AtRestEncryptionEnabled etc -## elasticache-commands-littlelaptop - - -### elasticaches - -List elasticache thingies - - $ target-groups - bash-my-aws-nlb-tg TCP 22 vpc-04636ebe5573f6f65 instance bash-my-aws-nlb - bash-my-aws-alb-tg HTTP 443 vpc-04636ebe5573f6f65 instance bash-my-aws-alb - - -### elasticache-replication-groups - - -Accepts Target Group names on stdin or as arguments - - $ target-group-targets bash-my-aws-nlb-tg - i-4e15ece1de1a3f869 443 healthy bash-my-aws-nlb-tg - i-89cefa9403373d7a5 443 unhealthy bash-my-aws-nlb-tg - - ## elb-commands @@ -1597,6 +1599,28 @@ List target groups of ELBv2(s) [Application and Network Load Balancers) bash-my-aws-alb-tg HTTP 443 vpc-018d9739 bash-my-aws-alb +## fargate-commands + + +### fargate-clusters + +List ECS clusters + + +### fargate-services + +List ECS services +gets all clusters if no cluster_names passed in +echo "cluster_names=$cluster_names" + + +### fargate-tasks + +List ECS services +gets all clusters if no cluster_names passed in +echo "service_names=$service_names" + + ## iam-commands From fcb542656881733073c67283cd8e91d36b78ea5e Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 24 Oct 2023 11:39:32 +1100 Subject: [PATCH 11/44] improve ecs task output --- aliases | 5 ++++- functions | 5 ++++- lib/ecs-functions | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/aliases b/aliases index 67179885..a998dbda 100644 --- a/aliases +++ b/aliases @@ -92,13 +92,13 @@ alias debug='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma debug' alias deployment='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment' alias deployment-delete-danger='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-delete-danger' alias deployment-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-groups' +alias deployments='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments' alias deployments-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments-group' alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' alias ecr-repository-images='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repository-images' alias ecs-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-clusters' alias ecs-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-services' -alias ecs-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-tasks' alias elasticache-replication-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticache-replication-groups' alias elasticaches='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticaches' alias elb-azs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elb-azs' @@ -114,6 +114,9 @@ alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-groups' alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s' +alias fargate-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-clusters' +alias fargate-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-services' +alias fargate-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-tasks' alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records' alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones' alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal' diff --git a/functions b/functions index 3cb8503b..5fd2048c 100644 --- a/functions +++ b/functions @@ -92,13 +92,13 @@ debug deployment deployment-delete-danger deployment-groups +deployments deployments-group distributions ecr-repositories ecr-repository-images ecs-clusters ecs-services -ecs-tasks elasticache-replication-groups elasticaches elb-azs @@ -114,6 +114,9 @@ elbv2-dnsname elbv2-subnets elbv2-target-groups elbv2s +fargate-clusters +fargate-services +fargate-tasks hosted-zone-ns-records hosted-zones iam-role-principal diff --git a/lib/ecs-functions b/lib/ecs-functions index 4f381354..8b010afb 100644 --- a/lib/ecs-functions +++ b/lib/ecs-functions @@ -126,7 +126,7 @@ ecs-tasks() { --cluster $cluster_name \ --query " tasks[?contains(taskDefinitionArn, \`$filter\`) == \`true\`] - .[taskDefinitionArn, createdAt, cpu, memory] + .[taskDefinitionArn, healthStatus, lastStatus, createdAt, cpu, memory] " \ --tasks $( \ aws ecs list-tasks \ @@ -135,6 +135,7 @@ ecs-tasks() { sed 's/.*\///' \ ) \ --output text | + sed 's/arn.*task-definition\///g' | columnise done From 2b1f2d42e63042e38b62d4d7fb5a2f8867f2b049 Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Wed, 22 Nov 2023 10:53:12 +1100 Subject: [PATCH 12/44] build --- aliases | 7 +++---- functions | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/aliases b/aliases index b5aaec89..677f2480 100644 --- a/aliases +++ b/aliases @@ -92,13 +92,13 @@ alias debug='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma debug' alias deployment='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment' alias deployment-delete-danger='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-delete-danger' alias deployment-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-groups' -alias deployments='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments' alias deployments-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments-group' alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' alias ecr-repository-images='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repository-images' alias ecs-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-clusters' alias ecs-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-services' +alias ecs-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-tasks' alias elasticache-replication-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticache-replication-groups' alias elasticaches='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticaches' alias elb-azs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elb-azs' @@ -114,9 +114,6 @@ alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-groups' alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s' -alias fargate-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-clusters' -alias fargate-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-services' -alias fargate-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-tasks' alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records' alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones' alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal' @@ -211,7 +208,9 @@ alias ssm-association-execution-targets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma alias ssm-association-executions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-association-executions' alias ssm-associations='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-associations' alias ssm-automation-execution='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-execution' +alias ssm-automation-execution-failures='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-execution-failures' alias ssm-automation-executions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-executions' +alias ssm-automation-step-executions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-step-executions' alias ssm-instances='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-instances' alias ssm-parameter-value='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-parameter-value' alias ssm-parameters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-parameters' diff --git a/functions b/functions index 8f47eacc..fe956ff5 100644 --- a/functions +++ b/functions @@ -92,13 +92,13 @@ debug deployment deployment-delete-danger deployment-groups -deployments deployments-group distributions ecr-repositories ecr-repository-images ecs-clusters ecs-services +ecs-tasks elasticache-replication-groups elasticaches elb-azs @@ -114,9 +114,6 @@ elbv2-dnsname elbv2-subnets elbv2-target-groups elbv2s -fargate-clusters -fargate-services -fargate-tasks hosted-zone-ns-records hosted-zones iam-role-principal @@ -212,7 +209,9 @@ ssm-association-execution-targets ssm-association-executions ssm-associations ssm-automation-execution +ssm-automation-execution-failures ssm-automation-executions +ssm-automation-step-executions ssm-instances ssm-parameter-value ssm-parameters From e8d0384c07c8dba18a97463cd7b3aafd83fa38b9 Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Wed, 22 Nov 2023 11:38:30 +1100 Subject: [PATCH 13/44] ecs-scaling functions --- aliases | 3 ++- functions | 3 ++- lib/autoscaling-functions | 22 +++++++++---------- lib/ecs-functions | 46 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/aliases b/aliases index 677f2480..020a74e3 100644 --- a/aliases +++ b/aliases @@ -97,6 +97,8 @@ alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' alias ecr-repository-images='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repository-images' alias ecs-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-clusters' +alias ecs-scaling-actions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-scaling-actions' +alias ecs-scaling-activities='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-scaling-activities' alias ecs-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-services' alias ecs-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-tasks' alias elasticache-replication-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticache-replication-groups' @@ -198,7 +200,6 @@ alias resource-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-groups' alias resource-show='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-show' alias resourceids='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resourceids' alias resources='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resources' -alias scaling-ecs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma scaling-ecs' alias secrets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma secrets' alias service-principals='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma service-principals' alias skim-stdin='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma skim-stdin' diff --git a/functions b/functions index fe956ff5..7d70a74f 100644 --- a/functions +++ b/functions @@ -97,6 +97,8 @@ distributions ecr-repositories ecr-repository-images ecs-clusters +ecs-scaling-actions +ecs-scaling-activities ecs-services ecs-tasks elasticache-replication-groups @@ -199,7 +201,6 @@ resource-groups resource-show resourceids resources -scaling-ecs secrets service-principals skim-stdin diff --git a/lib/autoscaling-functions b/lib/autoscaling-functions index fbc82ef0..b98b02c6 100644 --- a/lib/autoscaling-functions +++ b/lib/autoscaling-functions @@ -19,8 +19,8 @@ # elasticache | no # neptune | no - -scaling-ecs() { +### this has been moved to the ecs functions. was that a good idea? +##scaling-ecs() { # List autoscaling actions # filter by environment (eg test1) or namespace (eg ecs) # if you pass an argument, it'll filter for clusters whose ARN contains your text @@ -33,12 +33,12 @@ scaling-ecs() { # test3-ecs-admin-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 # test3-ecs-public-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 - local filters=$(__bma_read_filters $@) # Filter output by arguments (optional) - aws application-autoscaling describe-scheduled-actions \ - --service-namespace ecs \ - --query "ScheduledActions[].[ScheduledActionName,Schedule,ScalableTargetAction.MinCapacity,ScalableTargetAction.MaxCapacity]" \ - --output text | - grep -E -- "$filters" | - LC_ALL=C sort -b -k 2| - columnise -} +## local filters=$(__bma_read_filters $@) # Filter output by arguments (optional) +## aws application-autoscaling describe-scheduled-actions \ +## --service-namespace ecs \ +## --query "ScheduledActions[].[ScheduledActionName,Schedule,ScalableTargetAction.MinCapacity,ScalableTargetAction.MaxCapacity]" \ +## --output text | +## grep -E -- "$filters" | +## LC_ALL=C sort -b -k 2| +## columnise +##} diff --git a/lib/ecs-functions b/lib/ecs-functions index 8b010afb..a9107de6 100644 --- a/lib/ecs-functions +++ b/lib/ecs-functions @@ -141,3 +141,49 @@ ecs-tasks() { # --query 'tasks[].{createdAt: createdAt,startedAt: startedAt,cpu: cpu,memory: memory,taskDefinitionArn: taskDefinitionArn,ephemeralStorage: ephemeralStorage.sizeInGiB,privateIpv4Address: containers[0].networkInterfaces[0].privateIpv4Address}' \ } + +ecs-scaling-activities() { + + # show scaling activities for a selected ECS cluster + # eg + # ecs-scaling www + # 2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. + # 2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. + local filter=$(skim-stdin "$@") + +aws application-autoscaling describe-scaling-activities \ + --service-namespace ecs \ + --query " + ScalingActivities[].[StartTime, Description, Cause] + " \ + --output text | + # --resource-id # add cluster and service name for better filtering + grep $filter | + sed 's/monitor alarm TargetTracking-service\/.*\///' | + columnise + +} + + +ecs-scaling-actions() { + # List autoscaling actions + # filter by environment (eg test1) or namespace (eg ecs) + # if you pass an argument, it'll filter for clusters whose ARN contains your text + # + # $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments +# test1-ecs-admin-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test1-ecs-public-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test2-ecs-admin-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test2-ecs-public-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test3-ecs-admin-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 +# test3-ecs-public-scale-down-overnight cron(0 0 9 ? * MON-FRI *) 0 0 + + local filters=$(__bma_read_filters $@) # Filter output by arguments (optional) + aws application-autoscaling describe-scheduled-actions \ + --service-namespace ecs \ + --query "ScheduledActions[].[ScheduledActionName,Schedule,ScalableTargetAction.MinCapacity,ScalableTargetAction.MaxCapacity]" \ + --output text | + grep -E -- "$filters" | + LC_ALL=C sort -b -k 2| + columnise +} From c16e6aa35dc42427f8c6cb89df4b674208a0d402 Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Wed, 22 Nov 2023 11:57:32 +1100 Subject: [PATCH 14/44] trim some dates --- aliases | 1 + functions | 1 + lib/ecs-functions | 10 ++++++---- lib/misc-functions | 4 ++++ lib/stack-functions | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/aliases b/aliases index 020a74e3..b9068646 100644 --- a/aliases +++ b/aliases @@ -256,6 +256,7 @@ alias tag-keys='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma tag-keys' alias tag-values='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma tag-values' alias target-group-targets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma target-group-targets' alias target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma target-groups' +alias trim_date='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma trim_date' alias vpc-az-count='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-az-count' alias vpc-azs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-azs' alias vpc-default-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-default-delete' diff --git a/functions b/functions index 7d70a74f..78b8fc16 100644 --- a/functions +++ b/functions @@ -257,6 +257,7 @@ tag-keys tag-values target-group-targets target-groups +trim_date vpc-az-count vpc-azs vpc-default-delete diff --git a/lib/ecs-functions b/lib/ecs-functions index a9107de6..faea511f 100644 --- a/lib/ecs-functions +++ b/lib/ecs-functions @@ -144,11 +144,13 @@ ecs-tasks() { ecs-scaling-activities() { - # show scaling activities for a selected ECS cluster + # LIst autoscaling activities - the actual scaling events that have happened # eg # ecs-scaling www # 2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. # 2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. + + # TODO : the list can be very long, add max-items or even better implement generic paging for BMA local filter=$(skim-stdin "$@") aws application-autoscaling describe-scaling-activities \ @@ -158,15 +160,16 @@ aws application-autoscaling describe-scaling-activities \ " \ --output text | # --resource-id # add cluster and service name for better filtering - grep $filter | + grep -E -- "$filters" | sed 's/monitor alarm TargetTracking-service\/.*\///' | + trim_date | columnise } ecs-scaling-actions() { - # List autoscaling actions + # List autoscaling actions - cron-based scheduled scaling # filter by environment (eg test1) or namespace (eg ecs) # if you pass an argument, it'll filter for clusters whose ARN contains your text # @@ -184,6 +187,5 @@ ecs-scaling-actions() { --query "ScheduledActions[].[ScheduledActionName,Schedule,ScalableTargetAction.MinCapacity,ScalableTargetAction.MaxCapacity]" \ --output text | grep -E -- "$filters" | - LC_ALL=C sort -b -k 2| columnise } diff --git a/lib/misc-functions b/lib/misc-functions index 6102aa49..c35d807d 100644 --- a/lib/misc-functions +++ b/lib/misc-functions @@ -20,3 +20,7 @@ columnise() { column -t -s $'\t' fi } + +trim_date() { + sed 's/\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)\S*/\1/g' +} diff --git a/lib/stack-functions b/lib/stack-functions index e5b13921..d962b975 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -90,6 +90,7 @@ stacks() { --output text | grep -E -- "$filters" | LC_ALL=C sort -b -k 3 | + trim_date | columnise } From f73a6442e34fee326cb7dd667e38379b91c3caa4 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 12 Dec 2023 11:30:47 +1100 Subject: [PATCH 15/44] ECS : add IP address --- lib/ecs-functions | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ecs-functions b/lib/ecs-functions index 8b010afb..6446ac23 100644 --- a/lib/ecs-functions +++ b/lib/ecs-functions @@ -9,7 +9,7 @@ # ecs-services [cluster-name] # but then i don't know how to filter on the task/service name -ecs-clusters() { +ecs-clusters2() { # List ECS clusters # output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount # if you pass an argument, it'll filter for clusters whose ARN contains your text @@ -30,7 +30,7 @@ ecs-clusters() { columnise } -ecs-services() { +ecs-services2() { # List ECS services # output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt @@ -52,10 +52,10 @@ ecs-services() { # check for input that isn't a valid cluster name and use it as a regex... if [[ -z "$cluster_names" || "$(aws ecs describe-clusters --clusters $cluster_names --query "failures[].reason" --output text)" == "MISSING" ]]; then echo "cluster not found, using input to search" - cluster_names=$(ecs-clusters $cluster_names |skim-stdin) + cluster_names=$(ecs-clusters2 $cluster_names |skim-stdin) if [[ -z "$cluster_names" ]]; then echo "no matching cluster, using input as a service filter" - cluster_names=$(ecs-clusters |skim-stdin) + cluster_names=$(ecs-clusters2 |skim-stdin) service_filter=$filter fi fi @@ -119,14 +119,14 @@ ecs-tasks() { local filter=$(skim-stdin "$@") - for cluster_name in $(ecs-clusters |skim-stdin); do + for cluster_name in $(ecs-clusters2 |skim-stdin); do #echo "cluster_name=$cluster_name" # TODO: remove the account bit from the task definition, ie print gc3-test1-public:27 instead of arn:aws:ecs:ap-southeast-2:167642850091:task-definition/gc3-test1-public:27 aws ecs describe-tasks \ --cluster $cluster_name \ --query " tasks[?contains(taskDefinitionArn, \`$filter\`) == \`true\`] - .[taskDefinitionArn, healthStatus, lastStatus, createdAt, cpu, memory] + .[taskDefinitionArn, lastStatus, createdAt, cpu, memory, containers[].networkInterfaces[].privateIpv4Address] " \ --tasks $( \ aws ecs list-tasks \ From 3e3cac9360fbb22a61150520c235d15d041915e8 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 12 Dec 2023 13:14:23 +1100 Subject: [PATCH 16/44] build --- aliases | 8 ++++++-- docs/command-reference.md | 38 +++++++++++++++++++++++++++++++++++--- functions | 8 ++++++-- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/aliases b/aliases index b9068646..32c89eb6 100644 --- a/aliases +++ b/aliases @@ -92,14 +92,15 @@ alias debug='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma debug' alias deployment='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment' alias deployment-delete-danger='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-delete-danger' alias deployment-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-groups' +alias deployments='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments' alias deployments-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments-group' alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' alias ecr-repository-images='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repository-images' -alias ecs-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-clusters' +alias ecs-clusters2='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-clusters2' alias ecs-scaling-actions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-scaling-actions' alias ecs-scaling-activities='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-scaling-activities' -alias ecs-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-services' +alias ecs-services2='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-services2' alias ecs-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-tasks' alias elasticache-replication-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticache-replication-groups' alias elasticaches='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticaches' @@ -116,6 +117,9 @@ alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-groups' alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s' +alias fargate-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-clusters' +alias fargate-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-services' +alias fargate-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-tasks' alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records' alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones' alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal' diff --git a/docs/command-reference.md b/docs/command-reference.md index 3afe468a..ee2cf8ec 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -923,7 +923,7 @@ List scaling activities for Autoscaling Group(s) ## autoscaling-commands -### scaling-ecs +### ##scaling-ecs List autoscaling actions filter by environment (eg test1) or namespace (eg ecs) @@ -1406,7 +1406,7 @@ List images for ECR Repositories ## ecs-commands -### ecs-clusters +### ecs-clusters2 List ECS clusters output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount @@ -1419,7 +1419,7 @@ if you pass an argument, it'll filter for clusters whose ARN contains your text test2-ecs-cluster ACTIVE 3 3 0 -### ecs-services +### ecs-services2 List ECS services output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt @@ -1450,6 +1450,24 @@ if you do pass a filter, it filters on the task name. All clusters are included arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 +### ecs-scaling-activities + +LIst autoscaling activities - the actual scaling events that have happened +eg +ecs-scaling www +2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. +2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. + + +### ecs-scaling-actions + +List autoscaling actions - cron-based scheduled scaling +filter by environment (eg test1) or namespace (eg ecs) +if you pass an argument, it'll filter for clusters whose ARN contains your text + + $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments + + ## elasticache-commands @@ -2124,6 +2142,20 @@ USAGE: ssm-automation-executions [filter] ghijqrst-uvwx-2345-yzab-abcd5678efgh UpdateAndSecureNodes i-3d4e5f6g7h8i90123 Failed 2023-07-20T09:00:40.000000+00:00 None +### ssm-automation-execution-failures + + + +### ssm-automation-step-executions + +Show step-by-step details for an SSM Automation Execution + + USAGE: automation-execution-steps execution_id [execution_id] + + $ ssm-automation-executions | ssm-automation-steps-executions + [Outputs detailed step information for each provided execution ID] + + ### ssm-automation-execution Show details for an SSM Automation Execution diff --git a/functions b/functions index 78b8fc16..5dc311e7 100644 --- a/functions +++ b/functions @@ -92,14 +92,15 @@ debug deployment deployment-delete-danger deployment-groups +deployments deployments-group distributions ecr-repositories ecr-repository-images -ecs-clusters +ecs-clusters2 ecs-scaling-actions ecs-scaling-activities -ecs-services +ecs-services2 ecs-tasks elasticache-replication-groups elasticaches @@ -116,6 +117,9 @@ elbv2-dnsname elbv2-subnets elbv2-target-groups elbv2s +fargate-clusters +fargate-services +fargate-tasks hosted-zone-ns-records hosted-zones iam-role-principal From 2bcd2c79242ed0c8105f4b2cafc063716b95c55d Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 31 Jan 2024 11:54:07 +1100 Subject: [PATCH 17/44] first pass mostly comments --- lib/stack-functions | 154 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 124 insertions(+), 30 deletions(-) diff --git a/lib/stack-functions b/lib/stack-functions index ffbff5af..739a899e 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -90,6 +90,7 @@ stacks() { --output text | grep -E -- "$filters" | LC_ALL=C sort -b -k 3 | + trim_date | columnise } @@ -139,7 +140,7 @@ stack-create() { # to take advantage of shorter commands* # # USAGE: stack-create stack [template-file] [parameters-file] \ - # [--capabilities=OPTIONAL_VALUE] [--role-arn=OPTIONAL_VALUE] + # [CAPABILITY_1 CAPABILITY_2] [--role-arn=OPTIONAL_VALUE] # # $ stack-create params/asg-params-prod.json # Resolved arguments: asg-prod ./asg.yml params/asg-params-prod.json @@ -176,16 +177,23 @@ stack-create() { local inputs_array=($@) local IFS='=' # override default field separator in the scope of this function only local regex_role_arn="^\-\-role\-arn=.*" - local regex_capabilities="^\-\-capabilities=.*" + + # scan the whole commandline for anything in the list of capabities + local list_capabilities="CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND" for index in "${inputs_array[@]}" ; do if [[ "$index" =~ $regex_role_arn ]] ; then read arn_opt arn_arg <<< "$index" # ignore anything after option + arg arn="--role-arn $arn_arg" - elif [[ "$index" =~ $regex_capabilities ]] ; then + elif [[ "$index" =~ $list_capabilities ]] ; then read caps_opt caps_arg <<< "$index" # ignore anything after option + arg capabilities="--capabilities $caps_arg" fi + echo "capabilities include $caps_arg" done + + ## also add shell completion + # end capabilities + unset IFS # to prevent it from breaking things later if aws cloudformation create-stack \ @@ -198,6 +206,9 @@ stack-create() { --output text; then stack-tail $stack fi + + ## if it fails because of missing capabilities, add a "do you want to try again with the following capabilities" question + ## see stack-delete for a simple yes/no } stack-update() { @@ -557,22 +568,22 @@ stack-tag() { # XXX Handy but dangerous - updating a nested stack breaks things. Put in a guard. # XXX # XXX stack-tag-apply() { -# XXX +# XXX # XXX # Apply a stack tag -# XXX +# XXX # XXX local tag_key=$1 # XXX local tag_value=$2 # XXX shift 2 # XXX local usage_msg="tag-key tag-value stack [stack]" # XXX [[ -z "${tag_key}" ]] && __bma_usage $usage_msg && return 1 # XXX [[ -z "${tag_value}" ]] && __bma_usage $usage_msg && return 1 -# XXX +# XXX # XXX local stacks=$(skim-stdin "$@") # XXX [[ -z "${stacks}" && -t 0 ]] && __bma_usage $usage_msg && return 1 -# XXX +# XXX # XXX local stack # XXX for stack in $stacks; do -# XXX +# XXX # XXX # XXX deal with tagging service failing # XXX local tags=$(aws cloudformation describe-stacks \ # XXX --stack-name "$stack" \ @@ -580,7 +591,7 @@ stack-tag() { # XXX [{Key:'$tag_key', Value:'$tag_value'}], # XXX Stacks[].Tags[?Key != '$tag_key'][] # XXX ][]") -# XXX +# XXX # XXX local parameters=$(aws cloudformation describe-stacks \ # XXX --stack-name "$stack" \ # XXX --query ' @@ -588,11 +599,11 @@ stack-tag() { # XXX ParameterKey: ParameterKey, # XXX UsePreviousValue: `true` # XXX }') -# XXX +# XXX # XXX local capabilities='' # XXX local capabilities_value=$(_bma_stack_capabilities $stack) # XXX [[ -z "${capabilities_value}" ]] || capabilities="--capabilities ${capabilities_value}" -# XXX +# XXX # XXX $([[ -n $DRY_RUN ]] && echo echo) aws cloudformation update-stack \ # XXX --stack-name "$stack" \ # XXX --use-previous-template \ @@ -607,26 +618,26 @@ stack-tag() { # XXX Handy but dangerous - updating a nested stack breaks things. Put in a guard. # XXX # XXX stack-tag-delete() { -# XXX +# XXX # XXX # delete a stack tag -# XXX +# XXX # XXX local tag_key=$1 # XXX shift 1 # XXX [[ -z "${tag_key}" ]] && __bma_usage "tag-key stack [stack]" && return 1 -# XXX +# XXX # XXX local stacks=$(skim-stdin "$@") # XXX [[ -z "${stacks}" ]] && __bma_usage "tag-key stack [stack]" && return 1 -# XXX +# XXX # XXX local stack # XXX for stack in $stacks; do -# XXX +# XXX # XXX # XXX deal with tagging service failing # XXX local tags=$(aws cloudformation describe-stacks \ # XXX --stack-name "$stack" \ # XXX --query "[ # XXX Stacks[].Tags[?Key != '$tag_key'][] # XXX ][]") -# XXX +# XXX # XXX local parameters=$(aws cloudformation describe-stacks \ # XXX --stack-name "$stack" \ # XXX --query ' @@ -634,13 +645,13 @@ stack-tag() { # XXX ParameterKey: ParameterKey, # XXX UsePreviousValue: `true` # XXX }') -# XXX +# XXX # XXX aws cloudformation update-stack \ # XXX --stack-name "$stack" \ # XXX --use-previous-template \ # XXX --parameters "$parameters" \ # XXX --tags "$tags" -# XXX +# XXX # XXX done # XXX } @@ -681,19 +692,20 @@ stack-tail() { stack-template() { - # Return template of a stack - - local inputs=$(skim-stdin "$@") - local stack=$(_bma_stack_name_arg ${inputs}) + # Return template of each stack + local stacks=$(skim-stdin "$@") - [[ -z ${stack} ]] && __bma_usage "stack" && return 1 + [[ -z ${stacks} ]] && __bma_usage "stack [stack]" && return 1 + local stack + for stack in $stacks; do - aws cloudformation get-template \ - --stack-name "$stack" \ - --query TemplateBody | - jq --raw-output --sort-keys . | - sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' # remove trailing blank lines + aws cloudformation get-template \ + --stack-name "$stack" \ + --query TemplateBody | + jq --raw-output --sort-keys . | + sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' # remove trailing blank lines # sometimes appended by jq + done } stack-template-changeset-latest() { @@ -791,6 +803,88 @@ stack-validate() { fi } + +stack-detect-drift() { + + # Detect drift for provided stacks; and print coloured diff + local stacks=$(skim-stdin "$@") + [[ -z ${stacks} ]] && __bma_usage "stack [stack]" && return 1 + + for stack in $stacks; do + driftDetectionId=$(aws cloudformation detect-stack-drift \ + --stack-name "$stack" --output text) + DetectionStatus="" + while [[ "$DetectionStatus" != "DETECTION_COMPLETE" ]]; do + printf "." + DescribeDriftDetectionStatus=$(aws cloudformation describe-stack-drift-detection-status \ + --stack-drift-detection-id $driftDetectionId ) + DetectionStatus=$(echo $DescribeDriftDetectionStatus | jq --raw-output .DetectionStatus ) + StackDriftStatus=$(echo $DescribeDriftDetectionStatus | jq --raw-output .StackDriftStatus) + sleep 5; + done + if [[ "$StackDriftStatus" == "IN_SYNC" ]]; then + echo + echo "$stack is in sync" + else + echo "$stack has drifted" + stack-diff-drift $stack + fi + done + +} + +stack-describe-drift() { + + # List stack-tags applied to a stack + + local inputs=$(skim-stdin "$@") + local stack=$(_bma_stack_name_arg ${inputs}) + + [[ -z ${stack} ]] && __bma_usage "stack" && return 1 + + stackResourceDrifts=$( aws cloudformation describe-stack-resource-drifts \ + --stack-name "$stack" \ + --query 'StackResourceDrifts[*].{StackId:StackId,ExpectedProperties:ExpectedProperties,ActualProperties:ActualProperties}' ) +# jq -S <<< $stackResourceDrifts + ExpectedProperties=$(echo $stackResourceDrifts | jq --raw-output .[].ExpectedProperties) +# ExpectedPropertiesPretty=$(jq . -S --raw-output <<< "$ExpectedProperties") + ActualProperties=$(echo $stackResourceDrifts | jq --raw-output .[].ActualProperties) +# ActualPropertiesPretty=$(jq . -S --raw-output <<< "$ActualProperties") + echo + echo "Expected Properties:" + jq . <<< "$ExpectedProperties" + echo "Actual Properties:" + jq . <<< "$ActualProperties" + echo + +} + +stack-diff-drift() { + + # List stack-tags applied to a stack + + local inputs=$(skim-stdin "$@") + local stack=$(_bma_stack_name_arg ${inputs}) + + [[ -z ${stack} ]] && __bma_usage "stack" && return 1 + + stackResourceDrifts=$( aws cloudformation describe-stack-resource-drifts \ + --stack-name "$stack" \ + --query 'StackResourceDrifts[*].{StackId:StackId,ExpectedProperties:ExpectedProperties,ActualProperties:ActualProperties}' ) +# jq -S <<< $stackResourceDrifts + ExpectedProperties=$(echo $stackResourceDrifts | jq --raw-output .[].ExpectedProperties) + ExpectedPropertiesPretty=$(jq . -S --raw-output <<< "$ExpectedProperties") + ActualProperties=$(echo $stackResourceDrifts | jq --raw-output .[].ActualProperties) + ActualPropertiesPretty=$(jq . -S --raw-output <<< "$ActualProperties") + echo + # TODO : check whether diff is installed, otherwise just print $ExpectedPropertiesPretty and $ActualPropertiesPretty + echo "The diff ( Expected | Actual )" + diff -y --left-column --color=always <(printf %s "$ExpectedPropertiesPretty") <(printf %s "$ActualPropertiesPretty") + +} + + + stack-diff(){ # Compare live stack against local template (and optional params file) @@ -845,7 +939,7 @@ _bma_stack_diff_template() { elif command -v icdiff; then local DIFF_CMD=icdiff else - local DIFF_CMD=diff + local DIFF_CMD='diff --color=always' fi $DIFF_CMD -u \ From a35d7671f9f40432b589378bd40ea48e3417adf8 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 31 Jan 2024 12:06:00 +1100 Subject: [PATCH 18/44] add A-records, support multiple hosted zones --- lib/route53-functions | 56 ++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/lib/route53-functions b/lib/route53-functions index 08e9b553..bdf7b434 100644 --- a/lib/route53-functions +++ b/lib/route53-functions @@ -42,23 +42,47 @@ hosted-zone-ns-records(){ # bash-my-aws.org. 300 IN NS ns-1464.awsdns-55.org. local inputs=$(skim-stdin "$@") - local hosted_zone_id=$(echo "$inputs" | awk '{print $1}') - [[ -z "$hosted_zone_id" ]] && __bma_usage "hosted-zone-id" && return 1 + local hosted_zone_ids=$(echo "$inputs") + [[ -z "$hosted_zone_ids" ]] && __bma_usage "hosted-zone-id" && return 1 local hosted_zone_name - hosted_zone_name=$( - aws route53 list-resource-record-sets \ - --hosted-zone-id "$hosted_zone_id" \ - --query "ResourceRecordSets[?Type=='NS'].Name" \ - --output text - ) + for hosted_zone_id in $hosted_zone_ids; do + hosted_zone_name=$( + aws route53 list-resource-record-sets \ + --hosted-zone-id "$hosted_zone_id" \ + --query "ResourceRecordSets[?Type=='NS'].Name" \ + --output text + ) - aws route53 list-resource-record-sets \ - --hosted-zone-id "$hosted_zone_id" \ - --output text \ - --query " - ResourceRecordSets[?Type=='NS'].ResourceRecords[].[ - '$hosted_zone_name 300 IN NS', - Value - ]" + aws route53 list-resource-record-sets \ + --hosted-zone-id "$hosted_zone_id" \ + --output text \ + --query " + ResourceRecordSets[?Type=='NS'].ResourceRecords[].[ + '$hosted_zone_name 300 IN NS', + Value + ]" + done +} + +hosted-zone-a-records(){ + + # Generate NS records for delegating domain to AWS + # + # $ hosted-zone-a-records bash-my-aws.org + # + # $ hosted-zones | hosted-zone-a-records + + local inputs=$(skim-stdin "$@") + local hosted_zone_ids=$(echo "$inputs") + [[ -z "$hosted_zone_ids" ]] && __bma_usage "hosted-zone-id" && return 1 + + local hosted_zone_name + for hosted_zone_id in $hosted_zone_ids; do + + aws route53 list-resource-record-sets \ + --hosted-zone-id "$hosted_zone_id" \ + --output text \ + --query "ResourceRecordSets[?Type=='A'].[Name,AliasTarget.DNSName]" + done } From 85f501b63704c0ca0cea0c1f5a7a94a53a267fce Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 31 Jan 2024 12:17:40 +1100 Subject: [PATCH 19/44] build --- aliases | 3 ++- docs/command-reference.md | 35 +++++++++++++++++++++++++++++++++++ functions | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/aliases b/aliases index a6ef299d..58dac048 100644 --- a/aliases +++ b/aliases @@ -108,6 +108,7 @@ alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-groups' alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s' +alias hosted-zone-a-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-a-records' alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records' alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones' alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal' @@ -247,7 +248,7 @@ alias vpcs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpcs' # We'll find a less suprising place for this in future # region() needs to be a function in order to let it # set AWS_DEFAULT_REGION in the current shell -function region() { +function region() { local inputs=$(skim-stdin "$@"); if [[ -z "$inputs" ]]; then echo "${AWS_DEFAULT_REGION:-'AWS_DEFAULT_REGION not set'}"; diff --git a/docs/command-reference.md b/docs/command-reference.md index 9fad1ae0..fb02397f 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -1800,6 +1800,41 @@ Generate NS records for delegating domain to AWS bash-my-aws.org. 300 IN NS ns-1464.awsdns-55.org. +### hosted-zones + +List Route53 Hosted Zones + + $ hosted-zones + /hostedzone/Z3333333333333 5 NotPrivateZone bash-my-aws.org. + /hostedzone/Z5555555555555 2 NotPrivateZone bash-my-universe.com. + /hostedzone/Z4444444444444 3 NotPrivateZone bashmyaws.org. + /hostedzone/Z1111111111111 3 NotPrivateZone bash-my-aws.com. + /hostedzone/Z2222222222222 3 NotPrivateZone bashmyaws.com. + + +### hosted-zone-ns-records + +Generate NS records for delegating domain to AWS + + $ hosted-zones bash-my-aws.org + /hostedzone/ZJ6ZCG2UD6OKX 5 NotPrivateZone bash-my-aws.org. + + $ hosted-zones bash-my-aws.org | hosted-zone-ns-records + bash-my-aws.org. 300 IN NS ns-786.awsdns-34.net. + bash-my-aws.org. 300 IN NS ns-1549.awsdns-01.co.uk. + bash-my-aws.org. 300 IN NS ns-362.awsdns-45.com. + bash-my-aws.org. 300 IN NS ns-1464.awsdns-55.org. + + +### hosted-zone-a-records + +Generate NS records for delegating domain to AWS + + $ hosted-zone-a-records bash-my-aws.org + + $ hosted-zones | hosted-zone-a-records + + ## s3-commands diff --git a/functions b/functions index 85f35768..ab8868e7 100644 --- a/functions +++ b/functions @@ -108,6 +108,7 @@ elbv2-dnsname elbv2-subnets elbv2-target-groups elbv2s +hosted-zone-a-records hosted-zone-ns-records hosted-zones iam-role-principal From e2f9810b2eae27b2efb1ad149e4ac4d5e94b9bde Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 31 Jan 2024 12:30:12 +1100 Subject: [PATCH 20/44] first pass mostly comments --- lib/stack-functions | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/stack-functions b/lib/stack-functions index 739a899e..467626f7 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -208,7 +208,14 @@ stack-create() { fi ## if it fails because of missing capabilities, add a "do you want to try again with the following capabilities" question - ## see stack-delete for a simple yes/no + ## +# local regex_yes="^[Yy]$" +# echo "This stack requires the following capabilities:" +# echo "$missing_capabilities" | tr ' ' "\n" | missing_capabilities +# read -p "Do you want to try again with these capabilities? " -n 1 -r +# echo +# [[ $REPLY =~ $regex_yes ]] || return 0 + } stack-update() { From 3204b3cb809030ce8aa1b0a5640999555b79d10c Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 31 Jan 2024 13:14:34 +1100 Subject: [PATCH 21/44] columnise --- lib/route53-functions | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/route53-functions b/lib/route53-functions index bdf7b434..75a0896b 100644 --- a/lib/route53-functions +++ b/lib/route53-functions @@ -83,6 +83,7 @@ hosted-zone-a-records(){ aws route53 list-resource-record-sets \ --hosted-zone-id "$hosted_zone_id" \ --output text \ - --query "ResourceRecordSets[?Type=='A'].[Name,AliasTarget.DNSName]" + --query "ResourceRecordSets[?Type=='A'].[Name,AliasTarget.DNSName]" | + columnise done } From 069ccfe537a9e1186f596f4591694b7081ed331e Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 1 Feb 2024 10:06:09 +1100 Subject: [PATCH 22/44] Merge branch 'master' into features/route53-fixes --- aliases | 2 +- docs/command-reference.md | 124 ++++++++++++++++++++++++++++---------- 2 files changed, 94 insertions(+), 32 deletions(-) diff --git a/aliases b/aliases index d2f92d75..df9e9a32 100644 --- a/aliases +++ b/aliases @@ -280,7 +280,7 @@ alias vpcs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpcs' # We'll find a less suprising place for this in future # region() needs to be a function in order to let it # set AWS_DEFAULT_REGION in the current shell -function region() { +function region() { local inputs=$(skim-stdin "$@"); if [[ -z "$inputs" ]]; then echo "${AWS_DEFAULT_REGION:-'AWS_DEFAULT_REGION not set'}"; diff --git a/docs/command-reference.md b/docs/command-reference.md index 1652aee9..192194de 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -1405,9 +1405,6 @@ List images for ECR Repositories ## ecs-commands - -### ecs-clusters2 - List ECS clusters output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount if you pass an argument, it'll filter for clusters whose ARN contains your text @@ -1419,7 +1416,7 @@ if you pass an argument, it'll filter for clusters whose ARN contains your text test2-ecs-cluster ACTIVE 3 3 0 -### ecs-services2 +### ecs-services List ECS services output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt @@ -1489,6 +1486,68 @@ Most of the things you want to know about a replication group are boolean eg AutomaticFailover, MultiAZClusterEnabled, AtRestEncryptionEnabled etc +### ecs-clusters + +List ECS clusters +output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount +if you pass an argument, it'll filter for clusters whose ARN contains your text + + $ ecs-clusters test + test-octopus-ecs-cluster ACTIVE 1 1 0 + test1-ecs-cluster ACTIVE 3 1 0 + test3-ecs-cluster ACTIVE 3 1 0 + test2-ecs-cluster ACTIVE 3 3 0 + + +### ecs-services + +List ECS services +output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt + +gets all clusters if no filter passed in +if you do pass a filter: +1. if your filter is the name of one of your clusters, it will list the services in that cluster (eg ecs-clusters test1 | ecs-services) +2. if your filter is not a cluster name, it will list the services in all clusters whose names match your filter (ie it filters on cluster name not service name) +3. if you do not pass a filter, it will list all services in all clusters + + $ ecs-clusters test1|ecs-services + test1-ecs-admin-7URaUr0YGJHi ACTIVE 0 0 0 2023-09-13T17:16:48.198000+10:00 + test1-ecs-public-wEaTAqGXqbpq ACTIVE 0 0 0 2023-09-13T16:54:54.162000+10:00 + test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 + + +### ecs-tasks + +List ECS tasks +output includes taskDefinitionArn, createdAt, cpu, memory + +gets all tasks if no filter passed in +if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) + + $ ecs-tasks test2 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 + + +### ecs-scaling-activities + +LIst autoscaling activities - the actual scaling events that have happened +eg +ecs-scaling www +2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. +2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. + + +### ecs-scaling-actions + +List autoscaling actions - cron-based scheduled scaling +filter by environment (eg test1) or namespace (eg ecs) +if you pass an argument, it'll filter for clusters whose ARN contains your text + + $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments + + ## elb-commands @@ -1987,6 +2046,18 @@ Generate NS records for delegating domain to AWS bash-my-aws.org. 300 IN NS ns-1464.awsdns-55.org. +### hosted-zone-a-records + +Generate NS records for delegating domain to AWS + + $ hosted-zone-a-records bash-my-aws.org + + $ hosted-zones | hosted-zone-a-records + + +## route53-commandsTEMP + + ### hosted-zones List Route53 Hosted Zones @@ -2013,15 +2084,6 @@ Generate NS records for delegating domain to AWS bash-my-aws.org. 300 IN NS ns-1464.awsdns-55.org. -### hosted-zone-a-records - -Generate NS records for delegating domain to AWS - - $ hosted-zone-a-records bash-my-aws.org - - $ hosted-zones | hosted-zone-a-records - - ## s3-commands @@ -2142,24 +2204,24 @@ Run a command locally on EC2 instance(s) running Windows $ ssm-instances Windows | ssm-send-command-windows Get-Hotfix Command ID: a0eeeddc-2edf-42bc-b0c7-122f5bc50956 Waiting for command to complete... - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM - FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM - FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM - FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM - ---Output truncated--- - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM + FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM + FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM + FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM + ---Output truncated--- + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM See also: ssm-send-command-windows From acca9c65e8c1800467acb5d0c0f810fbfdd678d1 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 1 Feb 2024 15:48:13 +1100 Subject: [PATCH 23/44] clean up --- docs/command-reference.md | 131 +++++++++++++++++++++++++++++--------- lib/ecs-functions | 4 +- 2 files changed, 103 insertions(+), 32 deletions(-) diff --git a/docs/command-reference.md b/docs/command-reference.md index 192194de..2018bdc8 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -1405,6 +1405,9 @@ List images for ECR Repositories ## ecs-commands + +### ecs-clusters2 + List ECS clusters output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount if you pass an argument, it'll filter for clusters whose ARN contains your text @@ -1416,7 +1419,7 @@ if you pass an argument, it'll filter for clusters whose ARN contains your text test2-ecs-cluster ACTIVE 3 3 0 -### ecs-services +### ecs-services2 List ECS services output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt @@ -1465,25 +1468,72 @@ if you pass an argument, it'll filter for clusters whose ARN contains your text $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments -## elasticache-commands +## ecs-commands2 -### elasticaches +### ecs-clusters2 -List elasticache thingies (code borrowed from target-groups) +List ECS clusters +output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount +if you pass an argument, it'll filter for clusters whose ARN contains your text - $ target-groups - bash-my-aws-nlb-tg TCP 22 vpc-04636ebe5573f6f65 instance bash-my-aws-nlb - bash-my-aws-alb-tg HTTP 443 vpc-04636ebe5573f6f65 instance bash-my-aws-alb + $ ecs-clusters test + test-octopus-ecs-cluster ACTIVE 1 1 0 + test1-ecs-cluster ACTIVE 3 1 0 + test3-ecs-cluster ACTIVE 3 1 0 + test2-ecs-cluster ACTIVE 3 3 0 -### elasticache-replication-groups +### ecs-services2 +List ECS services +output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt -Accepts a string to filter on -This is not very useful without column headings. -Most of the things you want to know about a replication group are boolean -eg AutomaticFailover, MultiAZClusterEnabled, AtRestEncryptionEnabled etc +gets all clusters if no filter passed in +if you do pass a filter: +1. if your filter is the name of one of your clusters, it will list the services in that cluster (eg ecs-clusters test1 | ecs-services) +2. if your filter is not a cluster name, it will list the services in all clusters whose names match your filter (ie it filters on cluster name not service name) +3. if you do not pass a filter, it will list all services in all clusters + + $ ecs-clusters test1|ecs-services + test1-ecs-admin-7URaUr0YGJHi ACTIVE 0 0 0 2023-09-13T17:16:48.198000+10:00 + test1-ecs-public-wEaTAqGXqbpq ACTIVE 0 0 0 2023-09-13T16:54:54.162000+10:00 + test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 + + +### ecs-tasks + +List ECS tasks +output includes taskDefinitionArn, createdAt, cpu, memory + +gets all tasks if no filter passed in +if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) + + $ ecs-tasks test2 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 + + +### ecs-scaling-activities + +LIst autoscaling activities - the actual scaling events that have happened +eg +ecs-scaling www +2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. +2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. + + +### ecs-scaling-actions + +List autoscaling actions - cron-based scheduled scaling +filter by environment (eg test1) or namespace (eg ecs) +if you pass an argument, it'll filter for clusters whose ARN contains your text + + $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments + + +## ecs-commands~ ### ecs-clusters @@ -1548,6 +1598,27 @@ if you pass an argument, it'll filter for clusters whose ARN contains your text $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments +## elasticache-commands + + +### elasticaches + +List elasticache thingies (code borrowed from target-groups) + + $ target-groups + bash-my-aws-nlb-tg TCP 22 vpc-04636ebe5573f6f65 instance bash-my-aws-nlb + bash-my-aws-alb-tg HTTP 443 vpc-04636ebe5573f6f65 instance bash-my-aws-alb + + +### elasticache-replication-groups + + +Accepts a string to filter on +This is not very useful without column headings. +Most of the things you want to know about a replication group are boolean +eg AutomaticFailover, MultiAZClusterEnabled, AtRestEncryptionEnabled etc + + ## elb-commands @@ -2204,24 +2275,24 @@ Run a command locally on EC2 instance(s) running Windows $ ssm-instances Windows | ssm-send-command-windows Get-Hotfix Command ID: a0eeeddc-2edf-42bc-b0c7-122f5bc50956 Waiting for command to complete... - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM - FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM - FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM - FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM - ---Output truncated--- - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM + FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM + FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM + FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM + ---Output truncated--- + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM See also: ssm-send-command-windows diff --git a/lib/ecs-functions b/lib/ecs-functions index 248c400a..befc0024 100644 --- a/lib/ecs-functions +++ b/lib/ecs-functions @@ -9,7 +9,7 @@ # ecs-services [cluster-name] # but then i don't know how to filter on the task/service name -ecs-clusters2() { +ecs-clusters() { # List ECS clusters # output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount # if you pass an argument, it'll filter for clusters whose ARN contains your text @@ -30,7 +30,7 @@ ecs-clusters2() { columnise } -ecs-services2() { +ecs-services() { # List ECS services # output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt From 6f7288eb68b0b8cb9c1acd746fc841335a62da69 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 1 Feb 2024 16:48:36 +1100 Subject: [PATCH 24/44] trim date (empty) --- lib/misc-functions | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/misc-functions b/lib/misc-functions index 6102aa49..a0b651c0 100644 --- a/lib/misc-functions +++ b/lib/misc-functions @@ -20,3 +20,7 @@ columnise() { column -t -s $'\t' fi } + +trim_date() { + echo +} \ No newline at end of file From de43e5d1bc9fb0d7db40fefd12ce4fa77c398a9f Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 1 Feb 2024 16:49:46 +1100 Subject: [PATCH 25/44] trim date --- lib/misc-functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/misc-functions b/lib/misc-functions index a0b651c0..c35d807d 100644 --- a/lib/misc-functions +++ b/lib/misc-functions @@ -22,5 +22,5 @@ columnise() { } trim_date() { - echo -} \ No newline at end of file + sed 's/\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)\S*/\1/g' +} From 566d16186b5b3cc274af751010f1152c22064711 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 21 Feb 2024 18:35:26 +1100 Subject: [PATCH 26/44] issue 342 : add missing capabilities --- aliases | 4 ++-- functions | 4 ++-- lib/stack-functions | 47 +++++++++++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/aliases b/aliases index df9e9a32..7134f4e6 100644 --- a/aliases +++ b/aliases @@ -97,10 +97,10 @@ alias deployments-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments-gro alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' alias ecr-repository-images='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repository-images' -alias ecs-clusters2='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-clusters2' +alias ecs-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-clusters' alias ecs-scaling-actions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-scaling-actions' alias ecs-scaling-activities='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-scaling-activities' -alias ecs-services2='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-services2' +alias ecs-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-services' alias ecs-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-tasks' alias elasticache-replication-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticache-replication-groups' alias elasticaches='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticaches' diff --git a/functions b/functions index ca9e31a7..df4dee20 100644 --- a/functions +++ b/functions @@ -97,10 +97,10 @@ deployments-group distributions ecr-repositories ecr-repository-images -ecs-clusters2 +ecs-clusters ecs-scaling-actions ecs-scaling-activities -ecs-services2 +ecs-services ecs-tasks elasticache-replication-groups elasticaches diff --git a/lib/stack-functions b/lib/stack-functions index 467626f7..961e7a9c 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -177,44 +177,53 @@ stack-create() { local inputs_array=($@) local IFS='=' # override default field separator in the scope of this function only local regex_role_arn="^\-\-role\-arn=.*" + local list_capabilities=("CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND") - # scan the whole commandline for anything in the list of capabities - local list_capabilities="CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND" for index in "${inputs_array[@]}" ; do if [[ "$index" =~ $regex_role_arn ]] ; then read arn_opt arn_arg <<< "$index" # ignore anything after option + arg arn="--role-arn $arn_arg" - elif [[ "$index" =~ $list_capabilities ]] ; then - read caps_opt caps_arg <<< "$index" # ignore anything after option + arg - capabilities="--capabilities $caps_arg" fi - echo "capabilities include $caps_arg" + # search for anything in the capabilities list, with or without "--capabilities" + test_capability=${index##* } + if [[ " $list_capabilities " =~ "$test_capability" ]] ; then + capabilities="${capabilities} ${test_capability}" + fi done - - ## also add shell completion - # end capabilities + if [ ! -z "${capabilities}" ] ; then + capabilities="--capabilities ${capabilities}" + fi + ## TODO: add capabilities shell completion unset IFS # to prevent it from breaking things later - if aws cloudformation create-stack \ + if output=$( + aws cloudformation create-stack \ --stack-name $stack \ --template-body file://$template \ $parameters \ $capabilities \ $arn \ --disable-rollback \ - --output text; then + --output text \ + 2>&1 + ); then stack-tail $stack + else + echo "stack creation failed because $output" + for capability in ${list_capabilities} ; do + if [[ $output == *"$capability"* ]] ; then + capabilities="${capabilities} ${capability}" + fi + done + local regex_yes="^[Yy]$" + read -p "Do you want to try again with these capabilities? " -n 1 -r + echo + [[ $REPLY =~ $regex_yes ]] || return 0 + echo "now what?" + stack-create $@ ${capabilities} fi - ## if it fails because of missing capabilities, add a "do you want to try again with the following capabilities" question - ## -# local regex_yes="^[Yy]$" -# echo "This stack requires the following capabilities:" -# echo "$missing_capabilities" | tr ' ' "\n" | missing_capabilities -# read -p "Do you want to try again with these capabilities? " -n 1 -r -# echo -# [[ $REPLY =~ $regex_yes ]] || return 0 } From f62236dca0c291eb9034149bceb3916c54627f23 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 21 Feb 2024 18:43:36 +1100 Subject: [PATCH 27/44] issue 342 : add missing capabilities --- lib/stack-functions | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/stack-functions b/lib/stack-functions index 961e7a9c..300225e3 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -220,7 +220,6 @@ stack-create() { read -p "Do you want to try again with these capabilities? " -n 1 -r echo [[ $REPLY =~ $regex_yes ]] || return 0 - echo "now what?" stack-create $@ ${capabilities} fi From 1815a42271708eb0e036dbf37cfe6fc768960961 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 22 Feb 2024 10:21:50 +1100 Subject: [PATCH 28/44] #342 improve failure/retry handling --- lib/stack-functions | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/stack-functions b/lib/stack-functions index 300225e3..e4d302f4 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -211,16 +211,20 @@ stack-create() { stack-tail $stack else echo "stack creation failed because $output" - for capability in ${list_capabilities} ; do - if [[ $output == *"$capability"* ]] ; then - capabilities="${capabilities} ${capability}" + if [[ $output == *"InsufficientCapabilitiesException"* ]] ; then + for capability in ${list_capabilities} ; do + if [[ $output == *"$capability"* ]] ; then + capabilities="${capabilities} ${capability}" + fi + done + if [[ $capabilities ]] ; then + local regex_yes="^[Yy]$" + read -p "Do you want to try again with these capabilities? " -n 1 -r + echo + [[ $REPLY =~ $regex_yes ]] || return 0 + stack-create $@ ${capabilities} fi - done - local regex_yes="^[Yy]$" - read -p "Do you want to try again with these capabilities? " -n 1 -r - echo - [[ $REPLY =~ $regex_yes ]] || return 0 - stack-create $@ ${capabilities} + fi fi From 36afa053834d67e06f69df21629eb7c73ab732e0 Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Sun, 25 Feb 2024 22:18:16 +1100 Subject: [PATCH 29/44] build --- aliases | 4 - docs/command-reference.md | 108 ++-- functions | 4 - lib/codedeploy-functions | 54 ++ lib/ecs-functions | 3 +- lib/elasticache-functions-littlelaptop | 57 ++ lib/instance-functions~ | 734 +++++++++++++++++++++++++ lib/stack-functions | 2 + 8 files changed, 891 insertions(+), 75 deletions(-) create mode 100644 lib/codedeploy-functions create mode 100644 lib/elasticache-functions-littlelaptop create mode 100644 lib/instance-functions~ diff --git a/aliases b/aliases index 32c89eb6..b606dc6c 100644 --- a/aliases +++ b/aliases @@ -92,7 +92,6 @@ alias debug='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma debug' alias deployment='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment' alias deployment-delete-danger='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-delete-danger' alias deployment-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-groups' -alias deployments='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments' alias deployments-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments-group' alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' @@ -117,9 +116,6 @@ alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-groups' alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s' -alias fargate-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-clusters' -alias fargate-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-services' -alias fargate-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma fargate-tasks' alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records' alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones' alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal' diff --git a/docs/command-reference.md b/docs/command-reference.md index ee2cf8ec..1dc2f83d 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -923,7 +923,7 @@ List scaling activities for Autoscaling Group(s) ## autoscaling-commands -### ##scaling-ecs +### scaling-ecs List autoscaling actions filter by environment (eg test1) or namespace (eg ecs) @@ -1361,33 +1361,9 @@ List logging status of Cloudtrails List deployments -### deployments - -List all deployment IDs for a deployment group (not useful for the user, only internal) -# ?? if no deployment group, could we list all deployments for this application, with their groups and statuses? - - -### deployment-groups - -List all deployment groups for an application - - -## codedeploy-commands~ - - -### deployment - -List deployments - - -### deployments - -List all deployment IDs for a deployment group (not useful for the user, only internal) - - ### deployment-groups -List all deployment groups for an application +List min, desired and maximum capacities of EC2 Autoscaling Group(s) ## ecr-commands @@ -1489,6 +1465,28 @@ Most of the things you want to know about a replication group are boolean eg AutomaticFailover, MultiAZClusterEnabled, AtRestEncryptionEnabled etc +## elasticache-commands-littlelaptop + + +### elasticaches + +List elasticache thingies + + $ target-groups + bash-my-aws-nlb-tg TCP 22 vpc-04636ebe5573f6f65 instance bash-my-aws-nlb + bash-my-aws-alb-tg HTTP 443 vpc-04636ebe5573f6f65 instance bash-my-aws-alb + + +### elasticache-replication-groups + + +Accepts Target Group names on stdin or as arguments + + $ target-group-targets bash-my-aws-nlb-tg + i-4e15ece1de1a3f869 443 healthy bash-my-aws-nlb-tg + i-89cefa9403373d7a5 443 unhealthy bash-my-aws-nlb-tg + + ## elb-commands @@ -1625,28 +1623,6 @@ List target groups of ELBv2(s) [Application and Network Load Balancers) bash-my-aws-alb-tg HTTP 443 vpc-018d9739 bash-my-aws-alb -## fargate-commands - - -### fargate-clusters - -List ECS clusters - - -### fargate-services - -List ECS services -gets all clusters if no cluster_names passed in -echo "cluster_names=$cluster_names" - - -### fargate-tasks - -List ECS services -gets all clusters if no cluster_names passed in -echo "service_names=$service_names" - - ## iam-commands @@ -2107,24 +2083,24 @@ Run a command locally on EC2 instance(s) running Windows $ ssm-instances Windows | ssm-send-command-windows Get-Hotfix Command ID: a0eeeddc-2edf-42bc-b0c7-122f5bc50956 Waiting for command to complete... - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM - FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM - FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM - FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM - ---Output truncated--- - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM + FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM + FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM + FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM + ---Output truncated--- + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM See also: ssm-send-command-windows diff --git a/functions b/functions index 5dc311e7..9a68469f 100644 --- a/functions +++ b/functions @@ -92,7 +92,6 @@ debug deployment deployment-delete-danger deployment-groups -deployments deployments-group distributions ecr-repositories @@ -117,9 +116,6 @@ elbv2-dnsname elbv2-subnets elbv2-target-groups elbv2s -fargate-clusters -fargate-services -fargate-tasks hosted-zone-ns-records hosted-zones iam-role-principal diff --git a/lib/codedeploy-functions b/lib/codedeploy-functions new file mode 100644 index 00000000..39c9fc8b --- /dev/null +++ b/lib/codedeploy-functions @@ -0,0 +1,54 @@ +#!/bin/bash +# shellcheck disable=SC2046 +# shellcheck disable=SC2155 +# +# codedeploy-functions + +deployment() { + + # List deployments + + local deploymentgroup_names=$(skim-stdin) + local filters=$(__bma_read_filters $@) + +# aws deploy list-applications +# aws deploy list-deployment-groups --application-name 'tenders-web-dev2' +# list-deployments (limit to last 24 hours or most recent 5??) +# aws deploy list-deployments --deployment-group-name gc3-test2 --application-name grants-web-gc3-test2 --include-only-statuses "Succeeded" --query 'deployments[0]' +# aws deploy get-deployment --deployment-id d-MLWOBA1PK + aws deploy list-deployments \ + ${asg_names/#/'--auto-scaling-group-names '} \ + --output text \ + --query "AutoScalingGroups[].[ + AutoScalingGroupName, + join(',', [Tags[?Key=='Name'].Value || 'NO_NAME'][]), + CreatedTime, + join(',' sort(AvailabilityZones)) + ]" | + grep -E -- "$filters" | + sort -k 3 | + column -s$'\t' -t +} + + +deployment-groups() { + + # List min, desired and maximum capacities of EC2 Autoscaling Group(s) + + local asg_names=$(skim-stdin "$@") + [[ -z $asg_names ]] && __bma_usage "asg_name [asg_name]" && return 1 + + # shellcheck disable=SC2086 + aws autoscaling describe-auto-scaling-groups \ + --auto-scaling-group-names $asg_names \ + --output text \ + --query "AutoScalingGroups[][ + AutoScalingGroupName, + MinSize, + DesiredCapacity, + MaxSize + ]" | + column -s$'\t' -t +} + + diff --git a/lib/ecs-functions b/lib/ecs-functions index 248c400a..e4724b2f 100644 --- a/lib/ecs-functions +++ b/lib/ecs-functions @@ -144,7 +144,7 @@ ecs-tasks() { ecs-scaling-activities() { - # LIst autoscaling activities - the actual scaling events that have happened + # List autoscaling activities - the actual scaling events that have happened # eg # ecs-scaling www # 2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. @@ -187,5 +187,6 @@ ecs-scaling-actions() { --query "ScheduledActions[].[ScheduledActionName,Schedule,ScalableTargetAction.MinCapacity,ScalableTargetAction.MaxCapacity]" \ --output text | grep -E -- "$filters" | + LC_ALL=C sort -k 1 | columnise } diff --git a/lib/elasticache-functions-littlelaptop b/lib/elasticache-functions-littlelaptop new file mode 100644 index 00000000..5d75ac1e --- /dev/null +++ b/lib/elasticache-functions-littlelaptop @@ -0,0 +1,57 @@ +#!/bin/bash +# +# elasticache-functions +# +# + + +elasticaches() { + + # List elasticache thingies + # + # $ target-groups + # bash-my-aws-nlb-tg TCP 22 vpc-04636ebe5573f6f65 instance bash-my-aws-nlb + # bash-my-aws-alb-tg HTTP 443 vpc-04636ebe5573f6f65 instance bash-my-aws-alb + + local cache_names=$(skim-stdin) + local filters=$(__bma_read_filters $@) + + aws elasticache describe-cache-clusters \ + ${cache_names/#/'--cache-cluster-id '} \ + --output text \ + --query " + CacheClusters[][ + CacheClusterId, + CacheNodeType, + Engine, + EngineVersion, + CacheClusterStatus + ]" | + grep -E -- "$filters" | + LC_ALL=C sort -b | + column -s$'\t' -t +} + + +elasticache-replication-groups() { + + # + # Accepts Target Group names on stdin or as arguments + # + # $ target-group-targets bash-my-aws-nlb-tg + # i-4e15ece1de1a3f869 443 healthy bash-my-aws-nlb-tg + # i-89cefa9403373d7a5 443 unhealthy bash-my-aws-nlb-tg + + local ec_names=$(skim-stdin "$@") + + for ec_name in $ec_names; do + local tg_arn=$(aws describe-replication-groups \ + --names "$ec_name" \ + --output text \ + --query " + ReplicationGroups[][ + ReplicationGroupId + ] + ") + done | column -s$'\t' -t +} diff --git a/lib/instance-functions~ b/lib/instance-functions~ new file mode 100644 index 00000000..40bbc74e --- /dev/null +++ b/lib/instance-functions~ @@ -0,0 +1,734 @@ +#!/bin/bash +# +# instance-functions +# +# List, run, start, stop and ssh to Amazon AWS EC2 instances + +instances() { + + # List EC2 Instances + # + # $ instances + # i-4e15ece1de1a3f869 ami-123456789012 t3.nano running nagios 2019-12-10T08:17:18.000Z ap-southeast-2a None + # i-89cefa9403373d7a5 ami-123456789012 t3.nano running postgres1 2019-12-10T08:17:20.000Z ap-southeast-2a None + # i-806d8f1592e2a2efd ami-123456789012 t3.nano running postgres2 2019-12-10T08:17:22.000Z ap-southeast-2a None + # i-61e86ac6be1e2c193 ami-123456789012 t3.nano running prometheus-web 2019-12-10T08:17:24.000Z ap-southeast-2a None + # + # *Optionally provide a filter string for a `| grep` effect with tighter columisation:* + # + # $ instances postgres + # i-89cefa9403373d7a5 ami-123456789012 t3.nano running postgres1 2019-12-10T08:17:20.000Z ap-southeast-2a None + # i-806d8f1592e2a2efd ami-123456789012 t3.nano running postgres2 2019-12-10T08:17:22.000Z ap-southeast-2a None + + local instance_ids=$(skim-stdin) + local filters=$(__bma_read_filters $@) + local sort_key=5 + [ -z $filters ] && sort_key=6 + + aws ec2 describe-instances \ + ${instance_ids/#/'--instance-ids '} \ + --output text \ + --query " + Reservations[].Instances[][ + InstanceId, + ImageId, + InstanceType, + State.Name, + [Tags[?Key=='Name'].Value][0][0], + LaunchTime, + Placement.AvailabilityZone + ]" | + grep -E -- "$filters" | + LC_ALL=C sort -b -k $sort_key | + column -s$'\t' -t +} + + +instance-id() { + + # List autoscaling group membership of EC2 Instance(s) + # + # USAGE: instance-asg instance-id [instance-id] + + local instance_ids=$(skim-stdin "$@") + [[ -z $instance_ids ]] && __bma_usage "instance-id [instance-id]" && return 1 + echo $instance_ids | + column -s$'\t' -t +} + +instance-asg() { + + # List autoscaling group membership of EC2 Instance(s) + # + # USAGE: instance-asg instance-id [instance-id] + + local instance_ids=$(skim-stdin "$@") + [[ -z $instance_ids ]] && __bma_usage "instance-id [instance-id]" && return 1 + + aws ec2 describe-instances \ + --instance-ids $instance_ids \ + --output text \ + --query " + Reservations[].Instances[][ + { + "AutoscalingGroupName": + [Tags[?Key=='aws:autoscaling:groupName'].Value][0][0], + "InstanceId": InstanceId + } + ][]" | + column -s$'\t' -t +} + + +instance-az() { + + # List availability zone of EC2 Instance(s) + # + # USAGE: instance-az instance-id [instance-id] + # + # $ instances postgres | instance-az + # i-89cefa9403373d7a5 ap-southeast-2a + # i-806d8f1592e2a2efd ap-southeast-2a + + local instance_ids=$(skim-stdin "$@") + [[ -z $instance_ids ]] && __bma_usage "instance-id [instance-id]" && return 1 + + aws ec2 describe-instances \ + --instance-ids $instance_ids \ + --output text \ + --query " + Reservations[].Instances[][ + [ + InstanceId, + VpcId, + Placement.AvailabilityZone + ] + ][]" | + column -s$'\t' -t +} + + +instance-console() { + + # List console output of EC2 Instance(s) + # + # USAGE: instance-console instance-id [instance-id] + # + # $ instances postgres | instance-console + # Console output for EC2 Instance i-89cefa9403373d7a5 + # Linux version 2.6.16-xenU (builder@patchbat.amazonsa) (gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)) #1 SMP Thu Oct 26 08:41:26 SAST 2006 + # BIOS-provided physical RAM map: + # Xen: 0000000000000000 - 000000006a400000 (usable) + # ...snip... + # + # Console output for EC2 Instance i-806d8f1592e2a2efd + # Linux version 2.6.16-xenU (builder@patchbat.amazonsa) (gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)) #1 SMP Thu Oct 26 08:41:26 SAST 2006 + # BIOS-provided physical RAM map: + # Xen: 0000000000000000 - 000000006a400000 (usable) + # ...snip... + + local instance_ids=$(skim-stdin "$@") + [[ -z $instance_ids ]] && __bma_usage "instance-id [instance-id]" && return 1 + + local instance_id + for instance_id in $instance_ids; do + echo + echo "Console output for EC2 Instance $instance_id" + aws ec2 get-console-output \ + --instance-id "$instance_id" \ + --output text \ + --query Output + done +} + + +instance-dns() { + + # List DNS name of EC2 Instance(s) + # + # USAGE: instance-dns instance-id [instance-id] + # + # $ instances postgres | instance-dns + # i-89cefa9403373d7a5 ip-10-155-35-61.ap-southeast-2.compute.internal ec2-54-214-206-114.ap-southeast-2.compute.amazonaws.com + # i-806d8f1592e2a2efd ip-10-178-243-63.ap-southeast-2.compute.internal ec2-54-214-244-90.ap-southeast-2.compute.amazonaws.com + + local instance_ids=$(skim-stdin "$@") + [[ -z $instance_ids ]] && __bma_usage "instance-id [instance-id]" && return 1 + + aws ec2 describe-instances \ + --instance-ids $instance_ids \ + --output text \ + --query " + Reservations[].Instances[][ + { + "InstanceId": InstanceId, + "Private": PrivateDnsName, + "Public": PublicDnsName + } + ][]" | + column -s$'\t' -t +} + + +instance-health-set-unhealthy() { + + # Mark EC2 Instance(s) as unhealthy (to trigger replacement by ASG) + # + # USAGE: instance-health-set-unhealthy instance-id [instance-id] + + local instance_ids=$(skim-stdin "$@") + [[ -z $instance_ids ]] && __bma_usage "instance-id [instance-id]" && return 1 + + local health_status=Unhealthy + + local instance + for instance_id in $instance_ids; do + aws autoscaling set-instance-health \ + --instance-id "$instance_id" \ + --health-status "$health_status" + done +} + + +instance-iam-profile() { + + # List iam-profile of EC2 Instance(s) + # + # USAGE: instance-iam-profile instance-id [instance-id] + + local instance_ids=$(skim-stdin "$@") + [[ -z $instance_ids ]] && __bma_usage "instance-id [instance-id]" && return 1 + + aws ec2 describe-instances \ + --instance-ids $instance_ids \ + --output text \ + --query " + Reservations[].Instances[][ + [ + InstanceId, + IamInstanceProfile.Id + ] + ][]" | + column -s$'\t' -t +} + + +instance-ip() { + + # List ip address of EC2 Instance(s) + # + # USAGE: instance-ip instance-id [instance-id] + # + # $ instances postgres | instance-ip + # i-89cefa9403373d7a5 10.155.35.61 54.214.206.114 + # i-806d8f1592e2a2efd 10.178.243.63 54.214.244.90 + + local instance_ids=$(skim-stdin "$@") + [[ -z $instance_ids ]] && __bma_usage "instance-id [instance-id]" && return 1 + + aws ec2 describe-instances \ + --instance-ids $instance_ids \ + --output text \ + --query " + Reservations[].Instances[][ + { + "InstanceId": InstanceId, + "Private": PrivateIpAddress, + "Public": PublicIpAddress + } + ][]" | + column -s$'\t' -t +} + + +instance-ssh() { + + # Establish SSH connection to EC2 Instance(s) + # + # USAGE: instance-ssh [login] [instance-id] [instance-id] + + if [[ $1 != *i-* ]]; then + local user=${1} + shift + fi + local instance_ids=$(skim-stdin "$@") + if [[ -z $instance_ids ]] ; then + echo "Usage: $FUNCNAME [login] [instance-id] [instance-id]" + return 1 + fi + + exec &1 + + ssh \ + -t \ + -i "${BMA_SSH_DIR:-~/.ssh}/$keyname" \ + -o LogLevel=error \ + -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null \ + -l "$USERNAME" \ + "$private_ip" + done +} + + +instance-ssh-details() { + + # List details needed to SSH into EC2 Instance(s) + # + # USAGE: instance-ssh-details [login] [instance-id] [instance-id] + + if [[ $1 != *i-* ]]; then + local user=${1} + shift + fi + local instance_ids=$(skim-stdin "$@") + [[ -z "${instance_ids}" ]] && __bma_usage "instance_id" && return 1 + + aws ec2 describe-instances \ + --instance-ids $instance_ids \ + --output text \ + --query " + Reservations[].Instances[][ + InstanceId, + KeyName, + (PublicIpAddress || PrivateIpAddress), + join(' ', [Tags[?Key=='Name'].Value][] || ['not-named']), + join(' ', [Tags[?Key=='default-user'].Value][] || ['']) + ]" | + column -s$'\t' -t +} + + +instance-ssm() { + + # Establish SSM connection to EC2 Instance(s) + # + # USAGE: instance-ssm instance-id [instance-id] + + local instance_ids=$(skim-stdin "$@") + if [[ -z $instance_ids ]] ; then + echo "Usage: $FUNCNAME instance-id [instance-id]" + return 1 + fi + + exec Date: Sun, 25 Feb 2024 22:43:56 +1100 Subject: [PATCH 30/44] build --- aliases | 3 +- docs/command-reference.md | 201 ++++---------------------------------- functions | 1 + 3 files changed, 24 insertions(+), 181 deletions(-) diff --git a/aliases b/aliases index 25574276..a49961a0 100644 --- a/aliases +++ b/aliases @@ -116,6 +116,7 @@ alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-groups' alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s' +alias hosted-zone-a-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-a-records' alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records' alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones' alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal' @@ -275,7 +276,7 @@ alias vpcs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpcs' # We'll find a less suprising place for this in future # region() needs to be a function in order to let it # set AWS_DEFAULT_REGION in the current shell -function region() { +function region() { local inputs=$(skim-stdin "$@"); if [[ -z "$inputs" ]]; then echo "${AWS_DEFAULT_REGION:-'AWS_DEFAULT_REGION not set'}"; diff --git a/docs/command-reference.md b/docs/command-reference.md index 791cf5ef..8fe03da4 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -204,7 +204,7 @@ Create a CloudFormation Stack to take advantage of shorter commands* USAGE: stack-create stack [template-file] [parameters-file] \ - [--capabilities=OPTIONAL_VALUE] [--role-arn=OPTIONAL_VALUE] + [CAPABILITY_1 CAPABILITY_2] [--role-arn=OPTIONAL_VALUE] $ stack-create params/asg-params-prod.json Resolved arguments: asg-prod ./asg.yml params/asg-params-prod.json @@ -923,7 +923,7 @@ List scaling activities for Autoscaling Group(s) ## autoscaling-commands -### scaling-ecs +### ##scaling-ecs List autoscaling actions filter by environment (eg test1) or namespace (eg ecs) @@ -1382,136 +1382,6 @@ List images for ECR Repositories ## ecs-commands -### ecs-clusters2 - -List ECS clusters -output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount -if you pass an argument, it'll filter for clusters whose ARN contains your text - - $ ecs-clusters test - test-octopus-ecs-cluster ACTIVE 1 1 0 - test1-ecs-cluster ACTIVE 3 1 0 - test3-ecs-cluster ACTIVE 3 1 0 - test2-ecs-cluster ACTIVE 3 3 0 - - -### ecs-services2 - -List ECS services -output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt - -gets all clusters if no filter passed in -if you do pass a filter: -1. if your filter is the name of one of your clusters, it will list the services in that cluster (eg ecs-clusters test1 | ecs-services) -2. if your filter is not a cluster name, it will list the services in all clusters whose names match your filter (ie it filters on cluster name not service name) -3. if you do not pass a filter, it will list all services in all clusters - - $ ecs-clusters test1|ecs-services - test1-ecs-admin-7URaUr0YGJHi ACTIVE 0 0 0 2023-09-13T17:16:48.198000+10:00 - test1-ecs-public-wEaTAqGXqbpq ACTIVE 0 0 0 2023-09-13T16:54:54.162000+10:00 - test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 - - -### ecs-tasks - -List ECS tasks -output includes taskDefinitionArn, createdAt, cpu, memory - -gets all tasks if no filter passed in -if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) - - $ ecs-tasks test2 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 - - -### ecs-scaling-activities - -LIst autoscaling activities - the actual scaling events that have happened -eg -ecs-scaling www -2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. -2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. - - -### ecs-scaling-actions - -List autoscaling actions - cron-based scheduled scaling -filter by environment (eg test1) or namespace (eg ecs) -if you pass an argument, it'll filter for clusters whose ARN contains your text - - $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments - - -## ecs-commands2 - - -### ecs-clusters2 - -List ECS clusters -output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount -if you pass an argument, it'll filter for clusters whose ARN contains your text - - $ ecs-clusters test - test-octopus-ecs-cluster ACTIVE 1 1 0 - test1-ecs-cluster ACTIVE 3 1 0 - test3-ecs-cluster ACTIVE 3 1 0 - test2-ecs-cluster ACTIVE 3 3 0 - - -### ecs-services2 - -List ECS services -output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt - -gets all clusters if no filter passed in -if you do pass a filter: -1. if your filter is the name of one of your clusters, it will list the services in that cluster (eg ecs-clusters test1 | ecs-services) -2. if your filter is not a cluster name, it will list the services in all clusters whose names match your filter (ie it filters on cluster name not service name) -3. if you do not pass a filter, it will list all services in all clusters - - $ ecs-clusters test1|ecs-services - test1-ecs-admin-7URaUr0YGJHi ACTIVE 0 0 0 2023-09-13T17:16:48.198000+10:00 - test1-ecs-public-wEaTAqGXqbpq ACTIVE 0 0 0 2023-09-13T16:54:54.162000+10:00 - test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 - - -### ecs-tasks - -List ECS tasks -output includes taskDefinitionArn, createdAt, cpu, memory - -gets all tasks if no filter passed in -if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) - - $ ecs-tasks test2 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 - - -### ecs-scaling-activities - -LIst autoscaling activities - the actual scaling events that have happened -eg -ecs-scaling www -2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. -2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. - - -### ecs-scaling-actions - -List autoscaling actions - cron-based scheduled scaling -filter by environment (eg test1) or namespace (eg ecs) -if you pass an argument, it'll filter for clusters whose ARN contains your text - - $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments - - -## ecs-commands~ - - ### ecs-clusters List ECS clusters @@ -1558,7 +1428,7 @@ if you do pass a filter, it filters on the task name. All clusters are included ### ecs-scaling-activities -LIst autoscaling activities - the actual scaling events that have happened +List autoscaling activities - the actual scaling events that have happened eg ecs-scaling www 2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. @@ -2102,35 +1972,6 @@ Generate NS records for delegating domain to AWS $ hosted-zones | hosted-zone-a-records -## route53-commandsTEMP - - -### hosted-zones - -List Route53 Hosted Zones - - $ hosted-zones - /hostedzone/Z3333333333333 5 NotPrivateZone bash-my-aws.org. - /hostedzone/Z5555555555555 2 NotPrivateZone bash-my-universe.com. - /hostedzone/Z4444444444444 3 NotPrivateZone bashmyaws.org. - /hostedzone/Z1111111111111 3 NotPrivateZone bash-my-aws.com. - /hostedzone/Z2222222222222 3 NotPrivateZone bashmyaws.com. - - -### hosted-zone-ns-records - -Generate NS records for delegating domain to AWS - - $ hosted-zones bash-my-aws.org - /hostedzone/ZJ6ZCG2UD6OKX 5 NotPrivateZone bash-my-aws.org. - - $ hosted-zones bash-my-aws.org | hosted-zone-ns-records - bash-my-aws.org. 300 IN NS ns-786.awsdns-34.net. - bash-my-aws.org. 300 IN NS ns-1549.awsdns-01.co.uk. - bash-my-aws.org. 300 IN NS ns-362.awsdns-45.com. - bash-my-aws.org. 300 IN NS ns-1464.awsdns-55.org. - - ## s3-commands @@ -2251,24 +2092,24 @@ Run a command locally on EC2 instance(s) running Windows $ ssm-instances Windows | ssm-send-command-windows Get-Hotfix Command ID: a0eeeddc-2edf-42bc-b0c7-122f5bc50956 Waiting for command to complete... - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM - FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM - FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM - FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM - ---Output truncated--- - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM + FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM + FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM + FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM + ---Output truncated--- + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM See also: ssm-send-command-windows diff --git a/functions b/functions index 78b8fc16..aae07778 100644 --- a/functions +++ b/functions @@ -116,6 +116,7 @@ elbv2-dnsname elbv2-subnets elbv2-target-groups elbv2s +hosted-zone-a-records hosted-zone-ns-records hosted-zones iam-role-principal From c3344ef7785abf24f0ff537273bc36c78c95e1df Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 29 Feb 2024 10:18:30 +1100 Subject: [PATCH 31/44] merge --- docs/command-reference.md | 179 +------------------------------------- lib/stack-functions | 19 +++- 2 files changed, 19 insertions(+), 179 deletions(-) diff --git a/docs/command-reference.md b/docs/command-reference.md index 2018bdc8..12ec2e3b 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -204,7 +204,7 @@ Create a CloudFormation Stack to take advantage of shorter commands* USAGE: stack-create stack [template-file] [parameters-file] \ - [--capabilities=OPTIONAL_VALUE] [--role-arn=OPTIONAL_VALUE] + [CAPABILITY_1 CAPABILITY_2] [--role-arn=OPTIONAL_VALUE] $ stack-create params/asg-params-prod.json Resolved arguments: asg-prod ./asg.yml params/asg-params-prod.json @@ -1372,24 +1372,6 @@ List all deployment IDs for a deployment group (not useful for the user, only in List all deployment groups for an application -## codedeploy-commands~ - - -### deployment - -List deployments - - -### deployments - -List all deployment IDs for a deployment group (not useful for the user, only internal) - - -### deployment-groups - -List all deployment groups for an application - - ## ecr-commands @@ -1406,136 +1388,6 @@ List images for ECR Repositories ## ecs-commands -### ecs-clusters2 - -List ECS clusters -output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount -if you pass an argument, it'll filter for clusters whose ARN contains your text - - $ ecs-clusters test - test-octopus-ecs-cluster ACTIVE 1 1 0 - test1-ecs-cluster ACTIVE 3 1 0 - test3-ecs-cluster ACTIVE 3 1 0 - test2-ecs-cluster ACTIVE 3 3 0 - - -### ecs-services2 - -List ECS services -output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt - -gets all clusters if no filter passed in -if you do pass a filter: -1. if your filter is the name of one of your clusters, it will list the services in that cluster (eg ecs-clusters test1 | ecs-services) -2. if your filter is not a cluster name, it will list the services in all clusters whose names match your filter (ie it filters on cluster name not service name) -3. if you do not pass a filter, it will list all services in all clusters - - $ ecs-clusters test1|ecs-services - test1-ecs-admin-7URaUr0YGJHi ACTIVE 0 0 0 2023-09-13T17:16:48.198000+10:00 - test1-ecs-public-wEaTAqGXqbpq ACTIVE 0 0 0 2023-09-13T16:54:54.162000+10:00 - test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 - - -### ecs-tasks - -List ECS tasks -output includes taskDefinitionArn, createdAt, cpu, memory - -gets all tasks if no filter passed in -if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) - - $ ecs-tasks test2 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 - - -### ecs-scaling-activities - -LIst autoscaling activities - the actual scaling events that have happened -eg -ecs-scaling www -2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. -2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. - - -### ecs-scaling-actions - -List autoscaling actions - cron-based scheduled scaling -filter by environment (eg test1) or namespace (eg ecs) -if you pass an argument, it'll filter for clusters whose ARN contains your text - - $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments - - -## ecs-commands2 - - -### ecs-clusters2 - -List ECS clusters -output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount -if you pass an argument, it'll filter for clusters whose ARN contains your text - - $ ecs-clusters test - test-octopus-ecs-cluster ACTIVE 1 1 0 - test1-ecs-cluster ACTIVE 3 1 0 - test3-ecs-cluster ACTIVE 3 1 0 - test2-ecs-cluster ACTIVE 3 3 0 - - -### ecs-services2 - -List ECS services -output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt - -gets all clusters if no filter passed in -if you do pass a filter: -1. if your filter is the name of one of your clusters, it will list the services in that cluster (eg ecs-clusters test1 | ecs-services) -2. if your filter is not a cluster name, it will list the services in all clusters whose names match your filter (ie it filters on cluster name not service name) -3. if you do not pass a filter, it will list all services in all clusters - - $ ecs-clusters test1|ecs-services - test1-ecs-admin-7URaUr0YGJHi ACTIVE 0 0 0 2023-09-13T17:16:48.198000+10:00 - test1-ecs-public-wEaTAqGXqbpq ACTIVE 0 0 0 2023-09-13T16:54:54.162000+10:00 - test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 - - -### ecs-tasks - -List ECS tasks -output includes taskDefinitionArn, createdAt, cpu, memory - -gets all tasks if no filter passed in -if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) - - $ ecs-tasks test2 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 - arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 - - -### ecs-scaling-activities - -LIst autoscaling activities - the actual scaling events that have happened -eg -ecs-scaling www -2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. -2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. - - -### ecs-scaling-actions - -List autoscaling actions - cron-based scheduled scaling -filter by environment (eg test1) or namespace (eg ecs) -if you pass an argument, it'll filter for clusters whose ARN contains your text - - $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments - - -## ecs-commands~ - - ### ecs-clusters List ECS clusters @@ -2126,35 +1978,6 @@ Generate NS records for delegating domain to AWS $ hosted-zones | hosted-zone-a-records -## route53-commandsTEMP - - -### hosted-zones - -List Route53 Hosted Zones - - $ hosted-zones - /hostedzone/Z3333333333333 5 NotPrivateZone bash-my-aws.org. - /hostedzone/Z5555555555555 2 NotPrivateZone bash-my-universe.com. - /hostedzone/Z4444444444444 3 NotPrivateZone bashmyaws.org. - /hostedzone/Z1111111111111 3 NotPrivateZone bash-my-aws.com. - /hostedzone/Z2222222222222 3 NotPrivateZone bashmyaws.com. - - -### hosted-zone-ns-records - -Generate NS records for delegating domain to AWS - - $ hosted-zones bash-my-aws.org - /hostedzone/ZJ6ZCG2UD6OKX 5 NotPrivateZone bash-my-aws.org. - - $ hosted-zones bash-my-aws.org | hosted-zone-ns-records - bash-my-aws.org. 300 IN NS ns-786.awsdns-34.net. - bash-my-aws.org. 300 IN NS ns-1549.awsdns-01.co.uk. - bash-my-aws.org. 300 IN NS ns-362.awsdns-45.com. - bash-my-aws.org. 300 IN NS ns-1464.awsdns-55.org. - - ## s3-commands diff --git a/lib/stack-functions b/lib/stack-functions index d962b975..a5face38 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -198,6 +198,22 @@ stack-create() { --disable-rollback \ --output text; then stack-tail $stack + else + echo "$output" + if [[ $output == *"InsufficientCapabilitiesException"* ]] ; then + for capability in ${list_capabilities} ; do + if [[ $output == *"$capability"* ]] ; then + capabilities="${capabilities} ${capability}" + fi + done + if [[ $capabilities ]] ; then + local regex_yes="^[Yy]$" + read -p "Do you want to try again with these capabilities? " -n 1 -r + echo + [[ $REPLY =~ $regex_yes ]] || return 0 + stack-create $@ ${capabilities} + fi + fi fi } @@ -1055,7 +1071,8 @@ _bma_stack_args(){ __bma_error "Could not find params file (${params})." else # Display calling (or current if none) with expanded arguments - echo "Resolved arguments: $stack $template $params" + # echo "Resolved arguments: $stack $template $params" + true fi } From ba2a8cd2e6e525d6232d9d9d947040129dedb5e9 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 29 Feb 2024 10:25:38 +1100 Subject: [PATCH 32/44] merge --- lib/stack-functions | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/stack-functions b/lib/stack-functions index 44897361..c152f6d9 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -210,11 +210,7 @@ stack-create() { ); then stack-tail $stack else -<<<<<<< HEAD echo "$output" -======= - echo "stack creation failed because $output" ->>>>>>> features/stack-capabilities if [[ $output == *"InsufficientCapabilitiesException"* ]] ; then for capability in ${list_capabilities} ; do if [[ $output == *"$capability"* ]] ; then From ffcdbea850e9bd8be8ebf7789a346b465ea424cc Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 29 Feb 2024 10:26:18 +1100 Subject: [PATCH 33/44] merge --- aliases | 1 + docs/command-reference.md | 63 +++++++++++++++++++++++++++------------ functions | 1 + lib/codedeploy-functions | 40 +++++++++++++++---------- 4 files changed, 71 insertions(+), 34 deletions(-) diff --git a/aliases b/aliases index a49961a0..87e07ffa 100644 --- a/aliases +++ b/aliases @@ -92,6 +92,7 @@ alias debug='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma debug' alias deployment='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment' alias deployment-delete-danger='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-delete-danger' alias deployment-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-groups' +alias deployments='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments' alias deployments-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments-group' alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' diff --git a/docs/command-reference.md b/docs/command-reference.md index 7799bdb8..71bf9e36 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -1361,9 +1361,34 @@ List logging status of Cloudtrails List deployments +### deployments + +List all deployment IDs for a deployment group (not useful for the user, only internal) +# ?? if no deployment group, could we list all deployments for this application, with their groups and statuses? + + ### deployment-groups -List min, desired and maximum capacities of EC2 Autoscaling Group(s) +List all deployment groups for an application + + +## codedeploy-commands.bak + + +### deployment + +List deployments + + +### deployments + +List all deployment IDs for a deployment group (not useful for the user, only internal) +# ?? if no deployment group, could we list all deployments for this application, with their groups and statuses? + + +### deployment-groups + +List all deployment groups for an application ## ecr-commands @@ -2092,24 +2117,24 @@ Run a command locally on EC2 instance(s) running Windows $ ssm-instances Windows | ssm-send-command-windows Get-Hotfix Command ID: a0eeeddc-2edf-42bc-b0c7-122f5bc50956 Waiting for command to complete... - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM - FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM - FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM - FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM - ---Output truncated--- - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM + FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM + FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM + FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM + ---Output truncated--- + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM See also: ssm-send-command-windows diff --git a/functions b/functions index aae07778..378004ec 100644 --- a/functions +++ b/functions @@ -92,6 +92,7 @@ debug deployment deployment-delete-danger deployment-groups +deployments deployments-group distributions ecr-repositories diff --git a/lib/codedeploy-functions b/lib/codedeploy-functions index 39c9fc8b..40759810 100644 --- a/lib/codedeploy-functions +++ b/lib/codedeploy-functions @@ -13,9 +13,11 @@ deployment() { # aws deploy list-applications # aws deploy list-deployment-groups --application-name 'tenders-web-dev2' -# list-deployments (limit to last 24 hours or most recent 5??) +# list-deployments (limit to last 24 hours or most recent 5??) : # aws deploy list-deployments --deployment-group-name gc3-test2 --application-name grants-web-gc3-test2 --include-only-statuses "Succeeded" --query 'deployments[0]' -# aws deploy get-deployment --deployment-id d-MLWOBA1PK +# describe-deployment : aws deploy get-deployment --deployment-id d-MLWOBA1PK +## deployment-status should return the status of the last deployment to this group +# deployment-status : aws deploy get-deployment --deployment-id d-49ASRV1VL --query 'deploymentInfo.status' aws deploy list-deployments \ ${asg_names/#/'--auto-scaling-group-names '} \ --output text \ @@ -31,24 +33,32 @@ deployment() { } -deployment-groups() { - - # List min, desired and maximum capacities of EC2 Autoscaling Group(s) +deployments() { - local asg_names=$(skim-stdin "$@") - [[ -z $asg_names ]] && __bma_usage "asg_name [asg_name]" && return 1 + # List all deployment IDs for a deployment group (not useful for the user, only internal) + ## ?? if no deployment group, could we list all deployments for this application, with their groups and statuses? + local application_name=$(skim-stdin "$@") + local deployment_group_name=$(skim-stdin "$@") + [[ -z $application_name ]] && __bma_usage "application_name [application_name]" && return 1 # shellcheck disable=SC2086 - aws autoscaling describe-auto-scaling-groups \ - --auto-scaling-group-names $asg_names \ + aws deploy list-deployments \ + --application-name $application_name \ + --deployment-group-name $deployment_group_name \ --output text \ - --query "AutoScalingGroups[][ - AutoScalingGroupName, - MinSize, - DesiredCapacity, - MaxSize - ]" | column -s$'\t' -t } +deployment-groups() { + + # List all deployment groups for an application + local application_name=$(skim-stdin "$@") + [[ -z $application_name ]] && __bma_usage "application_name [application_name]" && return 1 + + # shellcheck disable=SC2086 + aws deploy list-deployment-groups \ + --application-name $application_name \ + --output text \ + --query "deploymentGroups[*]" +} From 48f4f1e625b755970d8247cdc653f50cd93366d8 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 21 Mar 2024 16:28:54 +1100 Subject: [PATCH 34/44] remove testing code --- lib/ecs-functions | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ecs-functions b/lib/ecs-functions index 12d08dc6..85ccf473 100644 --- a/lib/ecs-functions +++ b/lib/ecs-functions @@ -52,10 +52,10 @@ ecs-services() { # check for input that isn't a valid cluster name and use it as a regex... if [[ -z "$cluster_names" || "$(aws ecs describe-clusters --clusters $cluster_names --query "failures[].reason" --output text)" == "MISSING" ]]; then echo "cluster not found, using input to search" - cluster_names=$(ecs-clusters2 $cluster_names |skim-stdin) + cluster_names=$(ecs-clusters $cluster_names |skim-stdin) if [[ -z "$cluster_names" ]]; then echo "no matching cluster, using input as a service filter" - cluster_names=$(ecs-clusters2 |skim-stdin) + cluster_names=$(ecs-clusters |skim-stdin) service_filter=$filter fi fi @@ -119,7 +119,7 @@ ecs-tasks() { local filter=$(skim-stdin "$@") - for cluster_name in $(ecs-clusters2 |skim-stdin); do + for cluster_name in $(ecs-clusters |skim-stdin); do #echo "cluster_name=$cluster_name" # TODO: remove the account bit from the task definition, ie print gc3-test1-public:27 instead of arn:aws:ecs:ap-southeast-2:167642850091:task-definition/gc3-test1-public:27 aws ecs describe-tasks \ From 46e03434b87515b93f38c8a80585613ee4df59a4 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 21 Mar 2024 16:29:37 +1100 Subject: [PATCH 35/44] add log-goup-delete --- lib/log-functions | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/log-functions b/lib/log-functions index 31958250..a10904b9 100644 --- a/lib/log-functions +++ b/lib/log-functions @@ -37,3 +37,18 @@ log-groups() { $column_command } + +log-group-delete() { + + # List CloudWatch Log Groups + # + # $ log-group-delete [log-group-name] [log-group-name] [log-group-name] + + local log_group_names=$(skim-stdin) + local log_group + [[ -z $log_group_names ]] && __bma_usage "log-group-delete [log_group_names]" && return 1 + for log_group in log_group_names; do + aws logs delete-log-groups \ + --log-group-name $(log_group) + done +} From 9032b873bc622e9ab479310319d96fcdfc994eec Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 21 Mar 2024 16:29:54 +1100 Subject: [PATCH 36/44] build --- aliases | 1 + docs/command-reference.md | 7 +++++++ functions | 1 + 3 files changed, 9 insertions(+) diff --git a/aliases b/aliases index 87e07ffa..4b5cc6b0 100644 --- a/aliases +++ b/aliases @@ -186,6 +186,7 @@ alias location='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma location' alias location-each='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma location-each' alias location-unset='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma location-unset' alias locations='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma locations' +alias log-group-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma log-group-delete' alias log-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma log-groups' alias management-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma management-groups' alias pcxs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma pcxs' diff --git a/docs/command-reference.md b/docs/command-reference.md index 71bf9e36..df18907a 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -1945,6 +1945,13 @@ List CloudWatch Log Groups /aws/lambda/walk 1576567300172 0 11794 +### log-group-delete + +List CloudWatch Log Groups + + $ log-group-delete [log-group-name] [log-group-name] [log-group-name] + + ## rds-commands diff --git a/functions b/functions index 378004ec..bf54db17 100644 --- a/functions +++ b/functions @@ -186,6 +186,7 @@ location location-each location-unset locations +log-group-delete log-groups management-groups pcxs From 40b5ace7718649fae802426bd8a739fc0c47e3ff Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 25 Mar 2024 09:02:29 +1100 Subject: [PATCH 37/44] fix registry-id --- lib/ecr-functions | 2 -- lib/stack-functions | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ecr-functions b/lib/ecr-functions index 8ad317c8..6abc3cea 100644 --- a/lib/ecr-functions +++ b/lib/ecr-functions @@ -10,7 +10,6 @@ ecr-repositories() { local filters=$(__bma_read_filters $@) aws ecr describe-repositories \ - ${aws_account_id/#/'--registry-id '} \ --query " repositories[].[ repositoryName, @@ -34,7 +33,6 @@ ecr-repository-images() { local repository_names=$(skim-stdin "$@") # XXX Display USAGE if no repository_names passed in - local repository_names=$(skim-stdin "$@") [[ -z ${repository_names} ]] && __bma_usage "ecr" && return 1 local repository_name diff --git a/lib/stack-functions b/lib/stack-functions index c152f6d9..10e4a529 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -287,7 +287,11 @@ stack-update() { local capabilities='' local capabilities_value=$(_bma_stack_capabilities $stack) [[ -z "${capabilities_value}" ]] || capabilities="--capabilities ${capabilities_value}" - +echo "aws cloudformation update-stack \ + --stack-name $stack \ + --template-body file://$template \ + $parameters \ + $capabilities" if aws cloudformation update-stack \ --stack-name $stack \ --template-body file://$template \ From 8aa7ecc080a6513518ab3a92cecf773d8c69d68d Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 22 May 2024 11:22:13 +1000 Subject: [PATCH 38/44] add elbv2-arn --- lib/elbv2-functions | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/elbv2-functions b/lib/elbv2-functions index ccb5d730..bf527fdf 100644 --- a/lib/elbv2-functions +++ b/lib/elbv2-functions @@ -32,6 +32,29 @@ elbv2s() { columnise } +elbv2-arn(){ + + # List DNS Names of elbv2(s) + # + # USAGE: elbv2-dnsname load-balancer [load-balancer] + # + # $ elbv2s | elbv2-dnsname + # bash-my-aws bash-my-aws-c23c598688520e51.elb.ap-southeast-2.amazonaws.com + # bash-my-aws-alb bash-my-aws-alb-2036199590.ap-southeast-2.elb.amazonaws.com + + local elbv2_names=$(skim-stdin "$@") + [[ -z "${elbv2_names}" ]] && __bma_usage "load-balancer [load-balancer]" && return 1 + + aws elbv2 describe-load-balancers \ + --names $elbv2_names \ + --output text \ + --query " + LoadBalancers[][ + LoadBalancerArn + ]" | + columnise +} + elbv2-dnsname(){ # List DNS Names of elbv2(s) From 00d87204125a067bcd9500bb6cd6dd45591e9abb Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 26 Jun 2024 11:01:58 +1000 Subject: [PATCH 39/44] Fix throttling for SSM parameters --- aliases | 1 + bash_completion.sh | 1 + docs/command-reference.md | 226 ++++++++++++++++++++++++++++++++++++++ functions | 1 + lib/ssm-functions | 4 +- 5 files changed, 232 insertions(+), 1 deletion(-) diff --git a/aliases b/aliases index c6bbcef6..719a44c1 100644 --- a/aliases +++ b/aliases @@ -113,6 +113,7 @@ alias elb-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elb-subnets' alias elb-tag='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elb-tag' alias elb-tags='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elb-tags' alias elbs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbs' +alias elbv2-arn='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-arn' alias elbv2-azs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-azs' alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' diff --git a/bash_completion.sh b/bash_completion.sh index 0224241e..1be4764c 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -192,6 +192,7 @@ complete -F _bma_elbs_completion elb-subnets complete -F _bma_elbs_completion elb-tag complete -F _bma_elbs_completion elb-tags complete -F _bma_elbs_completion elbs +complete -F _bma_elbv2s_completion elbv2-arn complete -F _bma_elbv2s_completion elbv2-azs complete -F _bma_elbv2s_completion elbv2-dnsname complete -F _bma_elbv2s_completion elbv2-subnets diff --git a/docs/command-reference.md b/docs/command-reference.md index 9938ae45..2f7fc9ad 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -1614,6 +1614,17 @@ Accepts Load Balancer names on STDIN and converts to Network Load Balancer names bash-my-aws-alb application internet-facing provisioning 2020-01-04T11:29:45.030Z +### elbv2-arn + +List DNS Names of elbv2(s) + + USAGE: elbv2-dnsname load-balancer [load-balancer] + + $ elbv2s | elbv2-dnsname + bash-my-aws bash-my-aws-c23c598688520e51.elb.ap-southeast-2.amazonaws.com + bash-my-aws-alb bash-my-aws-alb-2036199590.ap-southeast-2.elb.amazonaws.com + + ### elbv2-dnsname List DNS Names of elbv2(s) @@ -2242,6 +2253,221 @@ List targets for SSM Association Execution Note: Can't use skim-stdin as it requires to arguments +### ssm-parameters + +List SSM Parameters + + USAGE: ssm-parameters [filter] + + $ ssm-parameters + /company/ad/a1234567/username + /ami/Ubuntu-20.04-proxy + /cloudwatch-agent/config/general + /cnf/staticSite/B1P2V34SR5KF0Z/encryptionKeyArn + /ops/CloudMetrics/linux + /ops/CloudMetrics/windows + + +### ssm-parameter-value + +Print SSM Parameter Value + + USAGE: ssm-parameter-value ssm-parameter [ssm-parameter] + + $ ssm-parameters | ssm-parameter-value + /ops/Monitoring/metrics/unix + { + "agent": { + "metrics_collection_interval": 60, + "logfile": "/var/log/aws-monitoring/aws-monitoring-agent.log" + }, + "logs": { + "logs_collected": { + "files": { + + + +### instance-ssm-platform-type + +Show platform type (OS) for instance + + USAGE: instance-ssm-platform-type instance-id [instance-id] + + $ instances | instance-ssm-platform-type + i-0c1d2e3f4a567890b None + i-0d1c2b3a4e5f6789c Linux + i-0e1f2d3c4b5a6789d Linux + i-0f1e2d3c4b5a6789e None + i-0a9f8e7d6c5b4a312 None + i-01b2a3c4d5e6f7893 Windows + + +## ssm-commands~ + + +### ssm-instances + +List Instances known to SSM + + USAGE: ssm-instances [filter] + + $ ssm-instances + i-00a123b456d789012 Online Amazon Linux 2 192.168.1.10 server001.example.com + i-01b234c567e890123 Online Microsoft Windows Server 2019 Datacenter 10.0.17763 192.168.1.20 winserver002.example.com + i-02c345d678f901234 Online Ubuntu 20.04 192.168.1.30 ubuntu003.example.com + i-03d456e789a012345 Online Ubuntu 20.04 192.168.1.40 ubuntu004.example.com + i-04e567f89b1234567 Online Amazon Linux 2 192.168.1.50 server005.example.com + *Optionally provide a filter string for a `| grep` effect with tighter columisation:* + + $ ssm-instances Windows + i-00a123b456d789012 Online Microsoft Windows Server 2019 Datacenter 68.0.11111 192.168.1.10 server001.example.com + i-01b234c567e890123 Online Microsoft Windows Server 2022 Datacenter 68.0.11112 192.168.1.20 winserver002.example.com + + +### ssm-send-command + +Run a command locally on EC2 instance(s) running Linux + + USAGE: ssm-send-command COMMAND instance-id [instance-id] + + $ ssm-send-command 'date +%F' i-0fict1234abcd + Command ID: 12345abc-de67-f890-gh12-34ij56kl789m + Waiting for command to complete... + i-0fict1234abcd 2023-12-01 + + $ ssm-instances | grep Linux | ssm-send-command 'date +%F' + Command ID: 98b7c6d2-e3f4-11ac-8d20-47a56db09c8f + Waiting for command to complete... + i-0fake1234a567bcd 2023-12-01 + i-0fake2345b678cde 2023-12-01 + i-0fake3456c789def 2023-11-30 + i-0fake4567d890efa 2023-11-30 + i-0fake5678e901fgh 2023-12-01 + i-0fake6789f012ghi 2023-12-01 + + See also: ssm-send-command-windows +Escape double quotes in command +Send command + + +### ssm-send-command-windows + +Run a command locally on EC2 instance(s) running Windows + + USAGE: ssm-send-command-windows COMMAND instance-id [instance-id] + + $ ssm-send-command 'Get-Hotfix' i-0fict1234abcd + Command ID: 12345abc-de67-f890-gh12-34ij56kl789m + Waiting for command to complete... + i-0fict1234abcd 2023-12-01 + + $ ssm-instances Windows | ssm-send-command-windows Get-Hotfix + Command ID: a0eeeddc-2edf-42bc-b0c7-122f5bc50956 + Waiting for command to complete... + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM + FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM + FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM + FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM + ---Output truncated--- + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + + See also: ssm-send-command-windows + + +### ssm-automation-executions + +List recent SSM Automation Executions +USAGE: ssm-automation-executions [filter] + + $ ssm-automation-executions + 1234abcd-ef56-7890-gh12-ijk3456lmnop UpdateAndSecureNodes None Failed 2023-07-20T09:00:00.000000+00:00 None + 5678efgh-ijkl-9012-mnop-qrstuvwx3456 UpdateAndSecureNodes i-0a1b2c3d4e5f67890 Failed 2023-07-20T09:00:10.000000+00:00 None + 90abijkl-mnop-4567-qrst-uvwxyza12345 UpdateAndSecureNodes i-1b2c3d4e5f6g78901 Failed 2023-07-20T09:00:20.000000+00:00 None + cdefmnop-qrst-8910-uvwx-yzab1234cdef UpdateAndSecureNodes i-2c3d4e5f6g7h89012 Failed 2023-07-20T09:00:30.000000+00:00 None + ghijqrst-uvwx-2345-yzab-abcd5678efgh UpdateAndSecureNodes i-3d4e5f6g7h8i90123 Failed 2023-07-20T09:00:40.000000+00:00 None + + +### ssm-automation-execution-failures + + + +### ssm-automation-step-executions + +Show step-by-step details for an SSM Automation Execution + + USAGE: automation-execution-steps execution_id [execution_id] + + $ ssm-automation-executions | ssm-automation-steps-executions + [Outputs detailed step information for each provided execution ID] + + +### ssm-automation-execution + +Show details for an SSM Automation Execution + + USAGE: ssm-automation-execution execution_id [execution_id] + + $ ssm-automation-executions | head | ssm-automation-execution + 1234abcd-5678-9def-ghij-klmnopqrstuv DeployNewFeatures i-01234a5b6c7d8e9f0 Failed 2023-09-10T10:10:10.000000+00:00 2023-09-10T10:10:20.000000+00:00 + 9876fedc-ba98-7654-c321-onmlkjihgfed DeployNewFeatures i-09876b5c4d3e2f1g0 Failed 2023-09-10T10:20:30.000000+00:00 2023-09-10T10:20:40.000000+00:00 + abcd1234-efgh-5678-ijkl-9mnopq7rstuv DeployNewFeatures i-0a1b2c3d4e5f6g7h8 Failed 2023-09-10T10:30:50.000000+00:00 2023-09-10T10:31:00.000000+00:00 + ijkl8765-ghij-4321-klmn-5opq4rstu3vw DeployNewFeatures i-0i8j7k6l5m4n3o2p1 Failed 2023-09-10T10:40:10.000000+00:00 2023-09-10T10:40:20.000000+00:00 + + +### ssm-associations + +List SSM associations + + USAGE: ssm-associations [filter] + + $ ssm-associations + Task-RunSecurityScan cron(30 2 * * SUN) 2023-01-15T02:30:00.000000+00:00 Failed + Task-UpdateSystemPackages cron(0 4 * * SAT) 2023-04-22T04:00:00.000000+00:00 Success + Service-ConfigureNetworkSettings rate(7 days) 2023-05-07T11:00:00.000000+00:00 Success + Script-DeployMonitoringTools cron(15 3 * * FRI) 2023-03-03T03:15:00.000000+00:00 Failed + + +### ssm-association-executions + +List SSM Association Executions + + USAGE: ssm-associations [filter] + + $ ssm-associations + 12345678-9abc-def0-1234-56789abcdef0 a1b2c3d4-e5f6-7890-a1b2-c3d4e5f67890 Success {Success=10} 2023-07-21T10:30:00.000000+00:00 + 12345678-9abc-def0-1234-56789abcdef0 b1c2d3e4-f5g6-7890-b1c2-d3e4f5g67890 Success {Success=15} 2023-07-22T11:00:00.000000+00:00 + 12345678-9abc-def0-1234-56789abcdef0 c1d2e3f4-g5h6-7890-c1d2-e3f4g5h67890 Success {Success=13} 2023-07-23T09:45:00.000000+00:00 + 12345678-9abc-def0-1234-56789abcdef0 d1e2f3g4-h5i6-7890-d1e2-f3g4h5i67890 Failed {Failed=2, Success=12} 2023-07-24T12:30:00.000000+00:00 + 12345678-9abc-def0-1234-56789abcdef0 e1f2g3h4-i5j6-7890-e1f2-g3h4i5j67890 Failed {Failed=3, Success=11} 2023-07-25T14:15:00.000000+00:00 + + +### ssm-association-execution-targets + +List targets for SSM Association Execution + + USAGE: ssm-association-execution-targets association-id execution-id + + $ association-execution-targets abcd1234-ef56-7890-gh12-ijk3456lmnop 12345678-90ab-cdef-1234-567890abcdef + abcd1234-ef56-7890-gh12-ijk3456lmnop 12345678-90ab-cdef-1234-567890abcdef i-01234abcde56789f0 Success Success 2023-08-10T11:30:00.000000+00:00 + abcd1234-ef56-7890-gh12-ijk3456lmnop 12345678-90ab-cdef-1234-567890abcdef i-02345bcdef67891g1 Success Success 2023-08-10T11:30:10.000000+00:00 + abcd1234-ef56-7890-gh12-ijk3456lmnop 12345678-90ab-cdef-1234-567890abcdef i-03456cdefg78912h2 Success Success 2023-08-10T11:30:20.000000+00:00 + abcd1234-ef56-7890-gh12-ijk3456lmnop 12345678-90ab-cdef-1234-567890abcdef i-04567defgh89123i3 Success Success 2023-08-10T11:30:30.000000+00:00 + +Note: Can't use skim-stdin as it requires to arguments + + ### ssm-parameters List SSM Parameters diff --git a/functions b/functions index ff84e757..6ebae436 100644 --- a/functions +++ b/functions @@ -113,6 +113,7 @@ elb-subnets elb-tag elb-tags elbs +elbv2-arn elbv2-azs elbv2-dnsname elbv2-subnets diff --git a/lib/ssm-functions b/lib/ssm-functions index 80ab1ead..24a13894 100644 --- a/lib/ssm-functions +++ b/lib/ssm-functions @@ -387,7 +387,8 @@ ssm-parameters() { # /cnf/staticSite/B1P2V34SR5KF0Z/encryptionKeyArn # /ops/CloudMetrics/linux # /ops/CloudMetrics/windows - + export AWS_MAX_ATTEMPTS=10 + export AWS_RETRY_MODE=adaptive # try to avoid throttling exceptions local filters=$(__bma_read_filters $@) aws ssm describe-parameters \ --output text \ @@ -421,6 +422,7 @@ ssm-parameter-value() { aws ssm get-parameter \ --name "$parameter" \ --query Parameter.Value \ + --with-decryption \ --output json done } From a0293a3f6cc78b521aa08cc3ad4d77facd5dd41e Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Tue, 16 Jul 2024 11:35:14 +1000 Subject: [PATCH 40/44] https://github.com/bash-my-aws/bash-my-aws/pull/346 --- lib/log-functions | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/log-functions b/lib/log-functions index a10904b9..c9d2f2aa 100644 --- a/lib/log-functions +++ b/lib/log-functions @@ -38,17 +38,35 @@ log-groups() { } + log-group-delete() { - # List CloudWatch Log Groups + # Delete CloudWatch Log Group + # + # $ log-group-delete /aws/lambda/stars + # You are about to delete the following log groups? + # /aws/lambda/stars + # Are you sure? [y/N] y + # Deleting: /aws/lambda/stars + # Deleted: /aws/lambda/stars # - # $ log-group-delete [log-group-name] [log-group-name] [log-group-name] + # You can also pipe the log group names to this command + # $ log-groups | log-group-delete - local log_group_names=$(skim-stdin) - local log_group - [[ -z $log_group_names ]] && __bma_usage "log-group-delete [log_group_names]" && return 1 - for log_group in log_group_names; do - aws logs delete-log-groups \ - --log-group-name $(log_group) + local log_groups=$(skim-stdin "$@") + local log_group_name + + [[ -z $log_groups ]] && return 1 + [ -t 0 ] || exec 0< /dev/tty + local regex_yes='^[yY]$' + echo "You are about to delete the following log groups?" + echo "$log_groups" | tr ' ' '\n' + read -p "Are you sure? [y/N] " -n 1 -r + [[ $REPLY =~ $regex_yes ]] || return 0 + + for log_group_name in $log_groups; do + echo "Deleting: $log_group_name" + aws logs delete-log-group --log-group-name "$log_group_name" + echo "Deleted: $log_group_name" done } From 36c84b75c6803f9e6fd7e350dda76507743f3771 Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Tue, 16 Jul 2024 11:38:22 +1000 Subject: [PATCH 41/44] https://github.com/bash-my-aws/bash-my-aws/pull/252 --- lib/route53-functions | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/route53-functions b/lib/route53-functions index 75a0896b..aadd4b80 100644 --- a/lib/route53-functions +++ b/lib/route53-functions @@ -65,6 +65,35 @@ hosted-zone-ns-records(){ done } +hosted-zone-records(){ + + # List Records in a Route53 Hosted Zone + # NOTE: AWS alias records are shown with a fake TTL of 86400. + # + # $ hosted-zones bash-my-aws.org + # /hostedzone/ZJ6ZCG2UD6OKX 5 NotPrivateZone bash-my-aws.org. + # + # $ hosted-zones bash-my-aws.org | hosted-zone-records + # bash-my-aws.org. 900 SOA ns-1549.awsdns-01.co.uk. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400 + # bash-my-aws.org. 300 NS ns-1464.awsdns-55.org. + # bash-my-aws.org. 300 A 185.199.108.153 + # bash-my-aws.org. 300 A 185.199.109.153 + # bash-my-aws.org. 300 TXT "google-site-verification=RbKejqu95y4Q78BkWnjaiM0rl6SYugtTdVLexK35b2k" + # lb.bash-my-aws.org. 86400 ALIAS dualstack.lb-bmaorg-12345.us-east-1.elb.amazonaws.com + + local hosted_zone_id="$(__bma_read_inputs $@)" + [[ -z "$hosted_zone_id" ]] && __bma_usage "hosted-zone-id" && return 1 + + aws route53 list-resource-record-sets \ + --hosted-zone-id "$hosted_zone_id" \ + --output json | + jq --raw-output '.ResourceRecordSets[] | + (select(.ResourceRecords) | + "\(.Name) \t\(.TTL) \t\(.Type) \t\(.ResourceRecords[].Value)\n"), + (select(.AliasTarget) | + "\(.Name) \t86400 \tALIAS \t\(.AliasTarget.DNSName)\n")' +} + hosted-zone-a-records(){ # Generate NS records for delegating domain to AWS From 72752ab3e425f910f6bb99961c900e93af06143a Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Tue, 16 Jul 2024 11:40:11 +1000 Subject: [PATCH 42/44] https://github.com/bash-my-aws/bash-my-aws/pull/339 --- lib/stack-functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stack-functions b/lib/stack-functions index 10e4a529..28d53874 100644 --- a/lib/stack-functions +++ b/lib/stack-functions @@ -451,10 +451,10 @@ stack-resources() { local stack for stack in $stacks; do stack=$(_bma_stack_name_arg "$stack") - aws cloudformation describe-stack-resources \ + aws cloudformation list-stack-resources \ --stack-name $(_bma_stack_name_arg "$stack") \ --output "${BMA_OUTPUT_AWS:-text}" \ - --query "StackResources[].{ + --query "StackResourceSummaries[].{ PhysicalResourceId: PhysicalResourceId, ResourceType: ResourceType, ResourceStatus: ResourceStatus, From 243ff7c0de5e01bb7cf029f71a3e5c88afd526c3 Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Thu, 8 Jan 2026 12:45:09 +1100 Subject: [PATCH 43/44] build --- aliases | 236 +-------------------------------------------- bash_completion.sh | 91 ----------------- functions | 224 ------------------------------------------ 3 files changed, 2 insertions(+), 549 deletions(-) diff --git a/aliases b/aliases index 48f3e1c7..64ef79ac 100644 --- a/aliases +++ b/aliases @@ -1,49 +1,6 @@ # DO NOT MANUALLY MODIFY THIS FILE. # Use 'scripts/build' to regenerate if required. -alias __bma-using-aws-cli-v1='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma __bma-using-aws-cli-v1' -alias __bma_error='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma __bma_error' -alias __bma_read_filters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma __bma_read_filters' -alias __bma_read_filters-az='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma __bma_read_filters-az' -alias __bma_read_inputs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma __bma_read_inputs' -alias __bma_read_stdin='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma __bma_read_stdin' -alias __bma_usage='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma __bma_usage' -alias _bma_derive_params_from_stack_and_template='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_derive_params_from_stack_and_template' -alias _bma_derive_params_from_template='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_derive_params_from_template' -alias _bma_derive_stack_from_params='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_derive_stack_from_params' -alias _bma_derive_stack_from_template='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_derive_stack_from_template' -alias _bma_derive_template_from_params='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_derive_template_from_params' -alias _bma_derive_template_from_stack='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_derive_template_from_stack' -alias _bma_stack_args='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_stack_args' -alias _bma_stack_capabilities='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_stack_capabilities' -alias _bma_stack_diff_params='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_stack_diff_params' -alias _bma_stack_diff_template='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_stack_diff_template' -alias _bma_stack_name_arg='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_stack_name_arg' -alias _bma_stack_params_arg='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_stack_params_arg' -alias _bma_stack_template_arg='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma _bma_stack_template_arg' -alias ad-app='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-app' -alias ad-app-owners='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-app-owners' -alias ad-apps='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-apps' -alias ad-group-members='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-group-members' -alias ad-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-groups' -alias ad-user-group-diff='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-user-group-diff' -alias ad-user-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-user-groups' -alias ad-user-names='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-user-names' -alias ad-user-upns='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-user-upns' -alias ad-users='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-users' -alias ad-users-graph='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ad-users-graph' -alias afd-custom-domains='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-custom-domains' -alias afd-custom-domains-validation-request='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-custom-domains-validation-request' -alias afd-endpoints='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-endpoints' -alias afd-origin-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-origin-groups' -alias afd-routes='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-routes' -alias afd-waf-policies='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-waf-policies' -alias afd-waf-policy='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-waf-policy' -alias afd-waf-policy-rule-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-waf-policy-rule-delete' -alias afd-waf-policy-rule-match-condition-values='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-waf-policy-rule-match-condition-values' -alias afd-waf-policy-rule-match-conditions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-waf-policy-rule-match-conditions' -alias afd-waf-policy-rules='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afd-waf-policy-rules' -alias afds='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma afds' alias asg-capacity='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma asg-capacity' alias asg-desired-size-set='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma asg-desired-size-set' alias asg-detach-instances='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma asg-detach-instances' @@ -64,53 +21,16 @@ alias aws-account-each='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma aws-account-each alias aws-account-id='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma aws-account-id' alias aws-accounts='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma aws-accounts' alias aws-panopticon='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma aws-panopticon' -alias az-account='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma az-account' -alias az-cache-item='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma az-cache-item' -alias az-cache-item-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma az-cache-item-delete' -alias az-cache-items='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma az-cache-items' -alias az-user='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma az-user' alias backup-jobs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma backup-jobs' -alias bucket-acls='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma bucket-acls' -alias bucket-remove='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma bucket-remove' -alias bucket-remove-force='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma bucket-remove-force' -alias bucket-size='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma bucket-size' -alias buckets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma buckets' -alias cert-chain='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-chain' -alias cert-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-delete' -alias cert-ificate='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-ificate' -alias cert-resource-record-valid='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-resource-record-valid' -alias cert-users='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-users' -alias cert-verify='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cert-verify' -alias certs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma certs' -alias certs-arn='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma certs-arn' alias cloudtrail-status='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cloudtrail-status' alias cloudtrails='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cloudtrails' -alias cloudwatch-alarm-actions-disable='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cloudwatch-alarm-actions-disable' -alias cloudwatch-alarm-actions-enable='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cloudwatch-alarm-actions-enable' -alias cloudwatch-alarm-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cloudwatch-alarm-delete' -alias cloudwatch-alarms='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma cloudwatch-alarms' alias columnise='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma columnise' -alias connector-group-apps='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma connector-group-apps' -alias connector-group-members='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma connector-group-members' -alias connector-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma connector-groups' -alias connectors='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma connectors' -alias debug='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma debug' alias deployment='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment' -alias deployment-delete-danger='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-delete-danger' alias deployment-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployment-groups' alias deployments='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments' -alias deployments-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma deployments-group' alias distributions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma distributions' -alias domain-autorenew-disable='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma domain-autorenew-disable' -alias domain-autorenew-enable='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma domain-autorenew-enable' -alias domains='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma domains' alias ecr-repositories='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repositories' alias ecr-repository-images='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecr-repository-images' -alias ecs-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-clusters' -alias ecs-scaling-actions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-scaling-actions' -alias ecs-scaling-activities='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-scaling-activities' -alias ecs-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-services' -alias ecs-tasks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ecs-tasks' alias elasticache-replication-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticache-replication-groups' alias elasticaches='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elasticaches' alias elb-azs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elb-azs' @@ -127,54 +47,12 @@ alias elbv2-dnsname='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-dnsname' alias elbv2-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-subnets' alias elbv2-target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2-target-groups' alias elbv2s='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma elbv2s' -alias hosted-zone-a-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-a-records' -alias hosted-zone-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-delete' -alias hosted-zone-ns-records='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zone-ns-records' -alias hosted-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma hosted-zones' alias iam-access-key-rotate='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-access-key-rotate' alias iam-role-principal='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-role-principal' alias iam-roles='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-roles' alias iam-users='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma iam-users' alias image-deregister='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma image-deregister' alias images='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma images' -alias instance-asg='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-asg' -alias instance-az='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-az' -alias instance-console='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-console' -alias instance-dns='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-dns' -alias instance-health-set-unhealthy='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-health-set-unhealthy' -alias instance-iam-profile='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-iam-profile' -alias instance-id='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-id' -alias instance-ip='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-ip' -alias instance-profile='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-profile' -alias instance-profile-role='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-profile-role' -alias instance-rdp='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-rdp' -alias instance-ssh='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-ssh' -alias instance-ssh-details='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-ssh-details' -alias instance-ssm='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-ssm' -alias instance-ssm-platform-type='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-ssm-platform-type' -alias instance-ssm-port-forward='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-ssm-port-forward' -alias instance-stack='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-stack' -alias instance-start='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-start' -alias instance-state='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-state' -alias instance-stop='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-stop' -alias instance-stop-protection='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-stop-protection' -alias instance-stop-protection-disable='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-stop-protection-disable' -alias instance-stop-protection-enable='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-stop-protection-enable' -alias instance-subnet='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-subnet' -alias instance-tag='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-tag' -alias instance-tag-create='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-tag-create' -alias instance-tag-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-tag-delete' -alias instance-tags='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-tags' -alias instance-tags-v2='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-tags-v2' -alias instance-terminate='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-terminate' -alias instance-termination-protection='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-termination-protection' -alias instance-termination-protection-disable='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-termination-protection-disable' -alias instance-termination-protection-enable='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-termination-protection-enable' -alias instance-type='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-type' -alias instance-userdata='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-userdata' -alias instance-volumes='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-volumes' -alias instance-vpc='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instance-vpc' -alias instances='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma instances' alias keypair-create='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma keypair-create' alias keypair-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma keypair-delete' alias keypairs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma keypairs' @@ -195,128 +73,18 @@ alias lambda-function-memory-step='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma lambd alias lambda-functions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma lambda-functions' alias launch-configuration-asgs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma launch-configuration-asgs' alias launch-configurations='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma launch-configurations' -alias location='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma location' -alias location-each='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma location-each' -alias location-unset='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma location-unset' -alias locations='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma locations' alias log-group-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma log-group-delete' alias log-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma log-groups' -alias management-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma management-groups' -alias network-interfaces='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma network-interfaces' -alias nics='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma nics' -alias pcxs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma pcxs' -alias private-dns-zone-a-record-add='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma private-dns-zone-a-record-add' -alias private-dns-zone-a-record-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma private-dns-zone-a-record-delete' -alias private-dns-zone-record-sets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma private-dns-zone-record-sets' -alias private-dns-zones='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma private-dns-zones' -alias private-endpoint-custom-dns-configs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma private-endpoint-custom-dns-configs' -alias private-endpoints='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma private-endpoints' alias rds-db-clusters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma rds-db-clusters' alias rds-db-instances='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma rds-db-instances' -alias region-each='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma region-each' -alias regions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma regions' -alias resource-diff='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-diff' -alias resource-export='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-export' -alias resource-group='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-group' -alias resource-group-export='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-group-export' -alias resource-group-unset='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-group-unset' -alias resource-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-groups' -alias resource-show='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resource-show' -alias resourceids='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resourceids' -alias resources='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma resources' +alias region='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma region' alias secrets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma secrets' -alias service-principals='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma service-principals' -alias skim-stdin='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma skim-stdin' -alias skim-stdin-bma='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma skim-stdin-bma' -alias skim-stdin-tsv='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma skim-stdin-tsv' -alias ssm-association-execution-targets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-association-execution-targets' -alias ssm-association-executions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-association-executions' -alias ssm-associations='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-associations' -alias ssm-automation-execution='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-execution' -alias ssm-automation-execution-failures='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-execution-failures' -alias ssm-automation-executions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-executions' -alias ssm-automation-step-executions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-automation-step-executions' -alias ssm-instances='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-instances' -alias ssm-parameter-value='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-parameter-value' -alias ssm-parameters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-parameters' -alias ssm-send-command='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-send-command' -alias ssm-send-command-windows='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma ssm-send-command-windows' -alias stack-arn='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-arn' -alias stack-asg-instances='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-asg-instances' -alias stack-asgs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-asgs' -alias stack-cancel-update='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-cancel-update' -alias stack-create='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-create' -alias stack-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-delete' -alias stack-describe-drift='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-describe-drift' -alias stack-detect-drift='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-detect-drift' -alias stack-diff='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-diff' -alias stack-diff-drift='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-diff-drift' -alias stack-drift-detect='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-drift-detect' -alias stack-drift-resources='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-drift-resources' -alias stack-drift-status='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-drift-status' -alias stack-elbs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-elbs' -alias stack-events='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-events' -alias stack-exports='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-exports' -alias stack-failure='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-failure' -alias stack-instances='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-instances' -alias stack-outputs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-outputs' -alias stack-parameters='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-parameters' -alias stack-recreate='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-recreate' -alias stack-resources='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-resources' -alias stack-status='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-status' -alias stack-tag='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-tag' -alias stack-tags='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-tags' -alias stack-tags-text='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-tags-text' -alias stack-tail='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-tail' -alias stack-template='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-template' -alias stack-template-changeset-latest='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-template-changeset-latest' -alias stack-update='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-update' -alias stack-validate='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stack-validate' -alias stacks='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma stacks' alias sts-assume-role='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma sts-assume-role' -alias subnet-ips='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma subnet-ips' -alias subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma subnets' -alias subscription='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma subscription' -alias subscription-each='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma subscription-each' -alias subscription-unset='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma subscription-unset' -alias subscriptions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma subscriptions' -alias subscriptions-each='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma subscriptions-each' -alias tag-keys='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma tag-keys' -alias tag-split='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma tag-split' -alias tag-values='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma tag-values' alias target-group-targets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma target-group-targets' alias target-groups='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma target-groups' alias trim_date='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma trim_date' -alias vnet-dns-resolvers='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vnet-dns-resolvers' -alias vnet-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vnet-subnets' -alias vnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vnets' -alias vpc-az-count='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-az-count' -alias vpc-azs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-azs' -alias vpc-default-delete='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-default-delete' -alias vpc-dhcp-options-ntp='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-dhcp-options-ntp' -alias vpc-endpoint-policy='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-endpoint-policy' -alias vpc-endpoint-services='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-endpoint-services' -alias vpc-endpoints='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-endpoints' -alias vpc-igw='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-igw' -alias vpc-lambda-functions='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-lambda-functions' -alias vpc-nat-gateways='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-nat-gateways' -alias vpc-network-acls='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-network-acls' -alias vpc-rds='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-rds' -alias vpc-route-tables='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-route-tables' -alias vpc-subnets='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpc-subnets' -alias vpcs='${BMA_HOME:-$HOME/.bash-my-aws}/bin/bma vpcs' # We'll find a less suprising place for this in future # region() needs to be a function in order to let it # set AWS_DEFAULT_REGION in the current shell -function region() { - local inputs=$(skim-stdin "$@"); - if [[ -z "$inputs" ]]; then - echo "${AWS_DEFAULT_REGION:-'AWS_DEFAULT_REGION not set'}"; - else - export AWS_DEFAULT_REGION="$inputs"; - if [[ -n $AWS_REGION ]]; then - export AWS_REGION="$AWS_DEFAULT_REGION"; - fi; - fi -} +function region() diff --git a/bash_completion.sh b/bash_completion.sh index b85a8824..258366c0 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -172,19 +172,6 @@ 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 -complete -F _bma_buckets_completion bucket-size -complete -F _bma_buckets_completion buckets -complete -F _bma_certs_completion cert-chain -complete -F _bma_certs_completion cert-delete -complete -F _bma_certs_completion cert-ificate -complete -F _bma_certs_completion cert-resource-record-valid -complete -F _bma_certs_completion cert-users -complete -F _bma_certs_completion cert-verify -complete -F _bma_certs_completion certs -complete -F _bma_certs_completion certs-arn complete -F _bma_elbs_completion elb-azs complete -F _bma_elbs_completion elb-dnsname complete -F _bma_elbs_completion elb-instances @@ -199,87 +186,9 @@ complete -F _bma_elbv2s_completion elbv2-dnsname complete -F _bma_elbv2s_completion elbv2-subnets complete -F _bma_elbv2s_completion elbv2-target-groups complete -F _bma_elbv2s_completion elbv2s -complete -F _bma_instances_completion instance-asg -complete -F _bma_instances_completion instance-az -complete -F _bma_instances_completion instance-console -complete -F _bma_instances_completion instance-dns -complete -F _bma_instances_completion instance-health-set-unhealthy -complete -F _bma_instances_completion instance-iam-profile -complete -F _bma_instances_completion instance-id -complete -F _bma_instances_completion instance-ip -complete -F _bma_instances_completion instance-profile -complete -F _bma_instances_completion instance-profile-role -complete -F _bma_instances_completion instance-rdp -complete -F _bma_instances_completion instance-ssh -complete -F _bma_instances_completion instance-ssh-details -complete -F _bma_instances_completion instance-ssm -complete -F _bma_instances_completion instance-ssm-platform-type -complete -F _bma_instances_completion instance-ssm-port-forward -complete -F _bma_instances_completion instance-stack -complete -F _bma_instances_completion instance-start -complete -F _bma_instances_completion instance-state -complete -F _bma_instances_completion instance-stop -complete -F _bma_instances_completion instance-stop-protection -complete -F _bma_instances_completion instance-stop-protection-disable -complete -F _bma_instances_completion instance-stop-protection-enable -complete -F _bma_instances_completion instance-subnet -complete -F _bma_instances_completion instance-tag -complete -F _bma_instances_completion instance-tag-create -complete -F _bma_instances_completion instance-tag-delete -complete -F _bma_instances_completion instance-tags -complete -F _bma_instances_completion instance-tags-v2 -complete -F _bma_instances_completion instance-terminate -complete -F _bma_instances_completion instance-termination-protection -complete -F _bma_instances_completion instance-termination-protection-disable -complete -F _bma_instances_completion instance-termination-protection-enable -complete -F _bma_instances_completion instance-type -complete -F _bma_instances_completion instance-userdata -complete -F _bma_instances_completion instance-volumes -complete -F _bma_instances_completion instance-vpc -complete -F _bma_instances_completion instances complete -F _bma_keypairs_completion keypair-delete complete -F _bma_keypairs_completion keypairs -complete -F _bma_regions_completion region -complete -F _bma_stacks_completion stack-arn -complete -F _bma_stacks_completion stack-asg-instances -complete -F _bma_stacks_completion stack-asgs -complete -F _bma_stacks_completion stack-cancel-update -complete -F _bma_stacks_completion stack-delete -complete -F _bma_stacks_completion stack-describe-drift -complete -F _bma_stacks_completion stack-detect-drift -complete -F _bma_stacks_completion stack-diff -complete -F _bma_stacks_completion stack-diff-drift -complete -F _bma_stacks_completion stack-drift-detect -complete -F _bma_stacks_completion stack-drift-resources -complete -F _bma_stacks_completion stack-drift-status -complete -F _bma_stacks_completion stack-elbs -complete -F _bma_stacks_completion stack-events -complete -F _bma_stacks_completion stack-exports -complete -F _bma_stacks_completion stack-failure -complete -F _bma_stacks_completion stack-instances -complete -F _bma_stacks_completion stack-outputs -complete -F _bma_stacks_completion stack-parameters -complete -F _bma_stacks_completion stack-recreate -complete -F _bma_stacks_completion stack-resources -complete -F _bma_stacks_completion stack-status -complete -F _bma_stacks_completion stack-tail -complete -F _bma_stacks_completion stack-template -complete -F _bma_stacks_completion stack-template-changeset-latest -complete -F _bma_stacks_completion stack-update -complete -F _bma_stacks_completion stacks complete -F _bma_target-groups_completion target-group-targets complete -F _bma_target-groups_completion target-groups -complete -F _bma_vpcs_completion vpc-az-count -complete -F _bma_vpcs_completion vpc-azs -complete -F _bma_vpcs_completion vpc-endpoint-policy -complete -F _bma_vpcs_completion vpc-endpoints -complete -F _bma_vpcs_completion vpc-igw -complete -F _bma_vpcs_completion vpc-lambda-functions -complete -F _bma_vpcs_completion vpc-nat-gateways -complete -F _bma_vpcs_completion vpc-network-acls -complete -F _bma_vpcs_completion vpc-rds -complete -F _bma_vpcs_completion vpc-route-tables -complete -F _bma_vpcs_completion vpc-subnets -complete -F _bma_vpcs_completion vpcs complete -f stack-validate complete -F _bma_completion bma diff --git a/functions b/functions index 807253ad..153f540c 100644 --- a/functions +++ b/functions @@ -1,49 +1,6 @@ # DO NOT MANUALLY MODIFY THIS FILE. # Use 'scripts/build' to regenerate if required. -__bma-using-aws-cli-v1 -__bma_error -__bma_read_filters -__bma_read_filters-az -__bma_read_inputs -__bma_read_stdin -__bma_usage -_bma_derive_params_from_stack_and_template -_bma_derive_params_from_template -_bma_derive_stack_from_params -_bma_derive_stack_from_template -_bma_derive_template_from_params -_bma_derive_template_from_stack -_bma_stack_args -_bma_stack_capabilities -_bma_stack_diff_params -_bma_stack_diff_template -_bma_stack_name_arg -_bma_stack_params_arg -_bma_stack_template_arg -ad-app -ad-app-owners -ad-apps -ad-group-members -ad-groups -ad-user-group-diff -ad-user-groups -ad-user-names -ad-user-upns -ad-users -ad-users-graph -afd-custom-domains -afd-custom-domains-validation-request -afd-endpoints -afd-origin-groups -afd-routes -afd-waf-policies -afd-waf-policy -afd-waf-policy-rule-delete -afd-waf-policy-rule-match-condition-values -afd-waf-policy-rule-match-conditions -afd-waf-policy-rules -afds asg-capacity asg-desired-size-set asg-detach-instances @@ -64,53 +21,16 @@ aws-account-each aws-account-id aws-accounts aws-panopticon -az-account -az-cache-item -az-cache-item-delete -az-cache-items -az-user backup-jobs -bucket-acls -bucket-remove -bucket-remove-force -bucket-size -buckets -cert-chain -cert-delete -cert-ificate -cert-resource-record-valid -cert-users -cert-verify -certs -certs-arn cloudtrail-status cloudtrails -cloudwatch-alarm-actions-disable -cloudwatch-alarm-actions-enable -cloudwatch-alarm-delete -cloudwatch-alarms columnise -connector-group-apps -connector-group-members -connector-groups -connectors -debug deployment -deployment-delete-danger deployment-groups deployments -deployments-group distributions -domain-autorenew-disable -domain-autorenew-enable -domains ecr-repositories ecr-repository-images -ecs-clusters -ecs-scaling-actions -ecs-scaling-activities -ecs-services -ecs-tasks elasticache-replication-groups elasticaches elb-azs @@ -127,54 +47,12 @@ elbv2-dnsname elbv2-subnets elbv2-target-groups elbv2s -hosted-zone-a-records -hosted-zone-delete -hosted-zone-ns-records -hosted-zones iam-access-key-rotate iam-role-principal iam-roles iam-users image-deregister images -instance-asg -instance-az -instance-console -instance-dns -instance-health-set-unhealthy -instance-iam-profile -instance-id -instance-ip -instance-profile -instance-profile-role -instance-rdp -instance-ssh -instance-ssh-details -instance-ssm -instance-ssm-platform-type -instance-ssm-port-forward -instance-stack -instance-start -instance-state -instance-stop -instance-stop-protection -instance-stop-protection-disable -instance-stop-protection-enable -instance-subnet -instance-tag -instance-tag-create -instance-tag-delete -instance-tags -instance-tags-v2 -instance-terminate -instance-termination-protection -instance-termination-protection-disable -instance-termination-protection-enable -instance-type -instance-userdata -instance-volumes -instance-vpc -instances keypair-create keypair-delete keypairs @@ -195,114 +73,12 @@ lambda-function-memory-step lambda-functions launch-configuration-asgs launch-configurations -location -location-each -location-unset -locations log-group-delete log-groups -management-groups -network-interfaces -nics -pcxs -private-dns-zone-a-record-add -private-dns-zone-a-record-delete -private-dns-zone-record-sets -private-dns-zones -private-endpoint-custom-dns-configs -private-endpoints rds-db-clusters rds-db-instances -region -region-each -regions -resource-diff -resource-export -resource-group -resource-group-export -resource-group-unset -resource-groups -resource-show -resourceids -resources secrets -service-principals -skim-stdin -skim-stdin-bma -skim-stdin-tsv -ssm-association-execution-targets -ssm-association-executions -ssm-associations -ssm-automation-execution -ssm-automation-execution-failures -ssm-automation-executions -ssm-automation-step-executions -ssm-instances -ssm-parameter-value -ssm-parameters -ssm-send-command -ssm-send-command-windows -stack-arn -stack-asg-instances -stack-asgs -stack-cancel-update -stack-create -stack-delete -stack-describe-drift -stack-detect-drift -stack-diff -stack-diff-drift -stack-drift-detect -stack-drift-resources -stack-drift-status -stack-elbs -stack-events -stack-exports -stack-failure -stack-instances -stack-outputs -stack-parameters -stack-recreate -stack-resources -stack-status -stack-tag -stack-tags -stack-tags-text -stack-tail -stack-template -stack-template-changeset-latest -stack-update -stack-validate -stacks sts-assume-role -subnet-ips -subnets -subscription -subscription-each -subscription-unset -subscriptions -subscriptions-each -tag-keys -tag-split -tag-values target-group-targets target-groups trim_date -vnet-dns-resolvers -vnet-subnets -vnets -vpc-az-count -vpc-azs -vpc-default-delete -vpc-dhcp-options-ntp -vpc-endpoint-policy -vpc-endpoint-services -vpc-endpoints -vpc-igw -vpc-lambda-functions -vpc-nat-gateways -vpc-network-acls -vpc-rds -vpc-route-tables -vpc-subnets -vpcs From d22b41dbe49b025b4d546fbd4b31abbcaeb6d20f Mon Sep 17 00:00:00 2001 From: Andrew Lorien Date: Thu, 8 Jan 2026 12:46:48 +1100 Subject: [PATCH 44/44] build --- docs/command-reference.md | 205 +++++++++++++++++++++++++++----------- 1 file changed, 149 insertions(+), 56 deletions(-) diff --git a/docs/command-reference.md b/docs/command-reference.md index 132c63b0..701c1a01 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -1511,42 +1511,6 @@ List logging status of Cloudtrails USAGE: cloudtrail-status cloudtrail [cloudtrail] -## codedeploy-commands - - -### deployment - -List deployments - - -### deployments - -List all deployment IDs for a deployment group (not useful for the user, only internal) -# ?? if no deployment group, could we list all deployments for this application, with their groups and statuses? - - -### deployment-groups - -List all deployment groups for an application - - -## codedeploy-commands.bak - - -### deployment - -List deployments - - -### deployments - -List all deployment IDs for a deployment group (not useful for the user, only internal) -# ?? if no deployment group, could we list all deployments for this application, with their groups and statuses? - - -### deployment-groups - -List all deployment groups for an application ## cloudwatch-commands @@ -1580,6 +1544,25 @@ List Cloudwatch Alarms +## codedeploy-commands + + +### deployment + +List deployments + + +### deployments + +List all deployment IDs for a deployment group (not useful for the user, only internal) +# ?? if no deployment group, could we list all deployments for this application, with their groups and statuses? + + +### deployment-groups + +List all deployment groups for an application + + ## domain-commands @@ -1678,6 +1661,88 @@ ecs-scaling www 2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. +### ecs-scaling-actions + +List autoscaling actions - cron-based scheduled scaling +filter by environment (eg test1) or namespace (eg ecs) +if you pass an argument, it'll filter for clusters whose ARN contains your text + + $ scaling-ecs 'test.*down' # list the scale-down times of all our test environments + + +## ecs-commands~ + + +### ecs-clusters + +List ECS clusters +output includes clusterName,status,activeServicesCount,runningTasksCount,pendingTasksCount +if you pass an argument, it'll filter for clusters whose ARN contains your text + + $ ecs-clusters test + test-octopus-ecs-cluster ACTIVE 1 1 0 + test1-ecs-cluster ACTIVE 3 1 0 + test3-ecs-cluster ACTIVE 3 1 0 + test2-ecs-cluster ACTIVE 3 3 0 + + +### ecs-services + +List ECS services +output includes serviceName,status,desiredCount,runningCount,pendingCount,createdAt + +gets all clusters if no filter passed in +if you do pass a filter: +1. if your filter is the name of one of your clusters, it will list the services in that cluster (eg ecs-clusters test1 | ecs-services) +2. if your filter is not a cluster name, it will list the services in all clusters whose names match your filter (ie it filters on cluster name not service name) +3. if you do not pass a filter, it will list all services in all clusters + + $ ecs-clusters test1|ecs-services + test1-ecs-admin-7URaUr0YGJHi ACTIVE 0 0 0 2023-09-13T17:16:48.198000+10:00 + test1-ecs-public-wEaTAqGXqbpq ACTIVE 0 0 0 2023-09-13T16:54:54.162000+10:00 + test1-ecs-hangfire-YNIo1hlx8rjn ACTIVE 1 1 0 2023-09-13T16:39:06.218000+10:00 + + +### ecs-tasks + +List ECS tasks +output includes name:version, createdAt, cpu, memory + +gets all tasks if no filter passed in +if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) + + $ ecs-tasks test2 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 + + +### ecs-task-details + +List ECS tasks +output includes name:version, taskDefinitionArn, status, createdAt, cpu, memory + +gets all tasks if no filter passed in +if you do pass a filter, it filters on the task name. All clusters are included (I haven't worked out a way of passing a cluster name AND a filter) + + $ ecs-tasks test2 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-public:18 2023-09-19T17:51:56.418000+10:00 2048 4096 + 5d6a2107-5723-44ac-8cdc-2c0dbeb8f69e 10.156.46.146 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-admin:20 2023-08-29T10:03:36.956000+10:00 2048 4096 + 934e4ca3-3d11-42fb-aadf-483e88f59d7c 10.156.30.66 + arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:task-definition/test2-hangfire:22 2023-09-19T17:11:06.622000+10:00 1024 2048 + 6a37c83e-dc85-473c-8a79-7023f85bd052 10.156.54.40 + + +### ecs-scaling-activities + +List autoscaling activities - the actual scaling events that have happened +eg +ecs-scaling www +2023-11-22T06:24:50.937000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmLow-64de4512-d901-4b26-a6a2-184bb1e90bc6 in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 2. Change successfully fulfilled by ecs. +2023-11-22T05:25:48.611000+11:00 www-ecs-public-ServicePublic-OuN3rXBLvmx3-AlarmHigh-6408c172-647e-4c0e-aac9-a800cd83317d in state ALARM triggered policy www-ecs-public-target-tracking-mem70 Successfully set desired count to 3. Change successfully fulfilled by ecs. + + ### ecs-scaling-actions List autoscaling actions - cron-based scheduled scaling @@ -2180,9 +2245,17 @@ List CloudWatch Log Groups ### log-group-delete -List CloudWatch Log Groups +Delete CloudWatch Log Group + + $ log-group-delete /aws/lambda/stars + You are about to delete the following log groups? + /aws/lambda/stars + Are you sure? [y/N] y + Deleting: /aws/lambda/stars + Deleted: /aws/lambda/stars - $ log-group-delete [log-group-name] [log-group-name] [log-group-name] + You can also pipe the log group names to this command + $ log-groups | log-group-delete ## rds-commands @@ -2228,6 +2301,23 @@ Generate NS records for delegating domain to AWS bash-my-aws.org. 300 IN NS ns-1464.awsdns-55.org. +### hosted-zone-records + +List Records in a Route53 Hosted Zone +NOTE: AWS alias records are shown with a fake TTL of 86400. + + $ hosted-zones bash-my-aws.org + /hostedzone/ZJ6ZCG2UD6OKX 5 NotPrivateZone bash-my-aws.org. + + $ hosted-zones bash-my-aws.org | hosted-zone-records + bash-my-aws.org. 900 SOA ns-1549.awsdns-01.co.uk. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400 + bash-my-aws.org. 300 NS ns-1464.awsdns-55.org. + bash-my-aws.org. 300 A 185.199.108.153 + bash-my-aws.org. 300 A 185.199.109.153 + bash-my-aws.org. 300 TXT "google-site-verification=RbKejqu95y4Q78BkWnjaiM0rl6SYugtTdVLexK35b2k" + lb.bash-my-aws.org. 86400 ALIAS dualstack.lb-bmaorg-12345.us-east-1.elb.amazonaws.com + + ### hosted-zone-a-records Generate NS records for delegating domain to AWS @@ -2235,6 +2325,8 @@ Generate NS records for delegating domain to AWS $ hosted-zone-a-records bash-my-aws.org $ hosted-zones | hosted-zone-a-records + + ### hosted-zone-delete Delete Route53 hosted zones @@ -2405,24 +2497,24 @@ Run a command locally on EC2 instance(s) running Windows $ ssm-instances Windows | ssm-send-command-windows Get-Hotfix Command ID: a0eeeddc-2edf-42bc-b0c7-122f5bc50956 Waiting for command to complete... - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM - FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM - FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM - FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM - ---Output truncated--- - i-0fake1234abcd - Source Description HotFixID InstalledBy InstalledOn - ------ ----------- -------- ----------- ----------- - FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM - FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM - FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Update KB2345678 NT AUTHORITY\SYSTEM 1/9/2019 12:00:00 AM + FAKEAPP01234 Update KB3456789 NT AUTHORITY\SYSTEM 3/11/2021 12:00:00 AM + FAKEAPP01234 Security Update KB4567890 NT AUTHORITY\SYSTEM 4/21/2019 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 5/15/2019 12:00:00 AM + FAKEAPP01234 Security Update KB6789012 NT AUTHORITY\SYSTEM 6/12/2019 12:00:00 AM + ---Output truncated--- + i-0fake1234abcd + Source Description HotFixID InstalledBy InstalledOn + ------ ----------- -------- ----------- ----------- + FAKEAPP01234 Update KB1234567 NT AUTHORITY\SYSTEM 10/11/2023 12:00:00 AM + FAKEAPP01234 Update KB8901234 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM + FAKEAPP01234 Security Update KB5678901 NT AUTHORITY\SYSTEM 12/12/2018 12:00:00 AM See also: ssm-send-command-windows @@ -2756,6 +2848,7 @@ Print SSM Parameter Value "logs_collected": { "files": { +another way to avoid ThrottlingException is to use get-parameters which takes an array of up to 10 params ### instance-ssm-platform-type