Skip to content

Instantly share code, notes, and snippets.

@kazu634
Created November 29, 2016 09:16
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 kazu634/df38c63db960ae43fcd3ebf17fceb5ee to your computer and use it in GitHub Desktop.
Save kazu634/df38c63db960ae43fcd3ebf17fceb5ee to your computer and use it in GitHub Desktop.
AWS CLI related scripts
#!/usr/bin/env ruby
instances = `aws ec2 describe-instances | \
jq -r -c '.Reservations[].Instances[] | [.InstanceId, (.Tags[]? | select(.Key == "Name")).Value, .PrivateIpAddress , .State.Name ] | @csv'`
instances.split().each do |instance|
id, name, ip, state = instance.gsub('"', '').split(',')
name = "NONAME" if name.empty?
puts "#{name}\t#{id}\t#{ip}\t#{state}"
end
exit 0
#!/bin/bash
# Check the # of arguments:
if [ $# -eq 0 ]; then
echo "Usage: $0 <ec2-instance-id>"
echo
echo "Or, you can specify the multiple instance ids, separated by space."
echo "Usage: $0 <ec2-instance-id> <ec2-instance-id> ..."
exit 0
fi
# Start the ec2 instances:
aws ec2 start-instances --instance-ids $@
exit 0
#!/bin/bash
# Check the # of arguments:
if [ $# -eq 0 ]; then
echo "Usage: $0 <ec2-instance-id>"
echo
echo "Or, you can specify the multiple instance ids, separated by space."
echo "Usage: $0 <ec2-instance-id> <ec2-instance-id> ..."
exit 0
fi
# Stop the ec2 instances:
aws ec2 stop-instances --instance-ids $@
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment