How To List Running AWS Instances in all Regions Sorted by LaunchTime and Email in a Monospaced Font
erics, Posted July 1st, 2019 at 11:42:02am
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#!/bin/sh DATE=`date` ( echo "From: Your Full Name <you@yourdomain.com>" echo "To: you@yourdomain.com" echo "Subject: AWS Instances Report for All Customers as of $DATE" cat <<EOT MIME-Version: 1.0 Content-Type: text/html Content-Disposition: inline <html> <body> <pre style="font: monospace"> EOT for profile in customer1 customer2 customer3; do for region in `aws ec2 describe-regions --output text | cut -f3`; do echo -e "\nListing Instances for profile $profile in region: '$region'..." aws ec2 describe-instances \ --filters "Name=instance-state-name,Values=running" \ --query 'Reservations[*].Instances[*].[InstanceId, PublicIpAddress, LaunchTime, InstanceType, Tags[?Key==`Name`] | [0].Value]| sort_by(@, &@[0][2])' \ --region $region \ --profile $profile \ --output table done done cat <<EOT </pre> </body> </html> EOT ) | /usr/sbin/sendmail -t |
Leave Your Comment
All fields marked with "*" are required.