Skip to content

Instantly share code, notes, and snippets.

@kenzo0107
Last active April 18, 2017 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenzo0107/b79e05f6fc6692a1d631fd874ccb3e6b to your computer and use it in GitHub Desktop.
Save kenzo0107/b79e05f6fc6692a1d631fd874ccb3e6b to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Action
# checks AWS events and show lists of events.
#
# Precondition
# - Install aws cli
# - aws configured and create .aws/config.
# - Install jq
#
# Authored by @kenzo0107
set -eu
readonly AWS_CONFIG=~/.aws/config
function get_aws_events_by_profile() {
local _profile=$1
local _ret
local _ret_ec2
local _ret_rds
_ret_ec2=$(aws --profile $_profile ec2 describe-instance-status --query "InstanceStatuses[?Events!=null]" |
jq -r '.[] |
[
.InstanceId,
.AvailabilityZone,
.Events[].Code,
.Events[].Description,
.Events[].NotBefore,
.Events[].NotAfter
] | @csv')
_ret_rds=$(aws --profile $_profile rds describe-pending-maintenance-actions | jq -r '.PendingMaintenanceActions[]|[.ResourceIdentifier, .PendingMaintenanceActionDetails[].Action, .PendingMaintenanceActionDetails[].Description]|@csv')
if [ -z "$_ret_ec2" -a -z "$_ret_rds" ]; then
return
fi
if echo "$_ret_ec2" | grep -v 'Completed' >/dev/null; then
_ret_ec2=$(echo "$_ret_ec2" | grep -v 'Completed')
_ret="$_ret_ec2"
fi
if echo "$_ret_rds" | grep -v 'Completed' >/dev/null; then
_ret_rds=$(echo "$_ret_rds" | grep -v 'Completed')
_ret="${_ret}${_ret_rds}"
fi
if [ -z "$_ret" ]; then
return
fi
echo "$_ret"
}
profiles=$(grep 'profile' $AWS_CONFIG | sed -e "s/\[profile \(.*\)\]/\1/g")
for a in ${profiles[@]}; do
echo ">>> profile:$a"
get_aws_events_by_profile $a
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment