Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Installation of aws-cli,jq is required
- # get IP of EC2 instances
- getec2ip(){
- 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
- }
- getec2type(){
- aws ec2 describe-instances --filters "Name=tag:Name,Values=$1" --region=$2 | jq '.Reservations | .[0] | .Instances | .[0] | .InstanceType '
- }
- getec2id(){
- aws ec2 describe-instances --filters "Name=tag:Name,Values=$1" --region=$2 | jq '.Reservations | .[0] | .Instances | .[0] | .InstanceId '
- }
- stopec2(){
- 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
- }
- detachfromalb(){
- 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
- }
- attachtoalb(){
- 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement