Link to home
Start Free TrialLog in
Avatar of lhrslsshahi
lhrslsshahi

asked on

Unable to disassociate and associate elastic IP address EC2-VPC

I am trying to setup HA Proxy and KeepAlived in AWS using the following article http://www.devopstech.com/haproxy-failover-keepalived-aws-ec2/

The master script in the article is for EC2-Classic and not EC2-VPC.

I have attached the script that I am working on any help would be appreciated.




aws ec2 associate-address --instance-id i-b6dcf92f --allocation-id eipalloc-3e380501 --public-ip 23.22.679.245

An error occurred (InvalidParameterCombination) when calling the AssociateAddress operation: You may specify public IP or allocation id, but not both in the same call.
EC2-VPC-script.txt
Avatar of Phil Phillips
Phil Phillips
Flag of United States of America image

For EC2-VPC, you only need to specify the allocation id:

aws ec2 associate-address --instance-id i-b6dcf92f --allocation-id eipalloc-3e380501

Open in new window

Avatar of lhrslsshahi
lhrslsshahi

ASKER

I need to able to assign the specific public IP 23.22.679.245 from 1 instance to another the above assigns a random Elastic IP.  Also when you run the script the disassociate command works the first time around but when it changes the ASSOCIATION_ID=eipassoc-07a97e38 to another it fails as it doesnt recognise the new ASSOCIATION_ID.

Below is lb1
#!/bin/bash

EIP=23.22.679.245
INSTANCE_ID=i-b6dcf92f
ASSOCIATION_ID=eipassoc-07a97e38
ALLOCATION_ID=eipalloc-3e380501

/usr/bin/aws ec2 disassociate-address --association-id $ASSOCIATION_ID
/usr/bin/aws ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $ALLOCATION_ID

------------------------------
lb2
#!/bin/bash

EIP=23.22.679.245
INSTANCE_ID=i-b6dcf92f
ASSOCIATION_ID=eipassoc-07a97e38
ALLOCATION_ID=eipalloc-3e380501

/usr/bin/aws ec2 disassociate-address --association-id $ASSOCIATION_ID
/usr/bin/aws ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $ALLOCATION_ID
ASKER CERTIFIED SOLUTION
Avatar of Phil Phillips
Phil Phillips
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Phil worked a treat. The only other thing I had to do was to change from /usr/bin/aws to /bin/aws.
I'm glad it worked! Remember to close the question. Thanks!
Thank you very much again Phil.