Is it possible to automatically assign an Elastic IP address to a spot instance that has a persistent spot request using the 'Advanced' 'User Data' script box?
I'm thinking that I could craft a script like...
#!/bin/bash # Credentials export AWS_ACCESS_KEY=(insert key here) export AWS_SECRET_KEY=(insert key here) # EC2 Instance ID instanceid=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/instance-id` # Associate EIP with the captured instance ID. ec2-associate-address -i $instanceid (insert EIP here)
And stick this in the user data box (using web gui) before I finalize my spot request. Any thoughts or better methods for this? I don't need to autoscale, just using this one instance that comes up and down depending on spot prices but I'd like it to retain the same IP each time it comes back.