Advertisement
Guest User

Untitled

a guest
May 26th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. ## Installation of aws-cli,jq is required
  2.  
  3. # get IP of EC2 instances
  4. getec2ip(){
  5. aws ec2 describe-instances --filters "Name=tag:Name,Values=$1" --region=$2 | jq '.Reservations | .[0] | .Instances | .[0] | .NetworkInterfaces | .[0] | .PrivateIpAddresses | .[0] | .Association | .PublicIp' | cut -d '"' -f 2
  6. }
  7.  
  8. getec2type(){
  9. aws ec2 describe-instances --filters "Name=tag:Name,Values=$1" --region=$2 | jq '.Reservations | .[0] | .Instances | .[0] | .InstanceType '
  10. }
  11.  
  12. getec2id(){
  13. aws ec2 describe-instances --filters "Name=tag:Name,Values=$1" --region=$2 | jq '.Reservations | .[0] | .Instances | .[0] | .InstanceId '
  14. }
  15.  
  16. stopec2(){
  17. aws ec2 stop-instances --instance-ids $(aws ec2 describe-instances --filters "Name=tag:Name,Values=$1" --region=$2 | jq '.Reservations | .[0] | .Instances | .[0] | .InstanceId ') --region $2
  18. }
  19.  
  20. detachfromalb(){
  21. aws elbv2 deregister-targets --target-group-arn $(aws elbv2 describe-target-groups --region $3 --names "$1" | jq '. | .[] | .[].TargetGroupArn' | cut -d '"' -f 2) --targets Id=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=$2" --region=$3 | jq '.Reservations | .[0] | .Instances | .[0] | .InstanceId ' | cut -d '"' -f 2) --region $3
  22. }
  23.  
  24. attachtoalb(){
  25. aws elbv2 register-targets --target-group-arn $(aws elbv2 describe-target-groups --region $3 --names "$1" | jq '. | .[] | .[].TargetGroupArn' | cut -d '"' -f 2) --targets Id=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=$2" --region=$3 | jq '.Reservations | .[0] | .Instances | .[0] | .InstanceId ' | cut -d '"' -f 2) --region $3
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement