How to setup EC2 spot instances with elastic IP? [closed]

I would like to set up an EC2 spot instance with an elastic IP. Here's the catch: if a spot instance is interrupted and resurrected later,

  1. Is the ip reassociated to the new instance?
  2. Am I billed for the offline period when the ip address was not associated to any machine?

Solution 1:

The information supplied in bwight's answer is correct (+1) - here are a couple of details to back it up:

There is a respective FAQ at the the end of the Feature Guide: Amazon EC2 Elastic IP Addresses, see If an instance re-starts does the mapping of ElasticIP Address become invalid?:

A reboot or restart of an instance has no impact on the mapping of an Elastic IP to it. However, terminating an instance will remove the mapping and the Elastic IP will then be charged for each full hour it is not mapped to another instance. [emphasis mine]

Spot instances are simply terminated, no different then terminating a regular instance yourself or being terminated by AWS due to a hardware failure, see point 2) in section How Spot Instances Work within Amazon EC2 Spot Instances:

If you’re running Spot Instances and your maximum price no longer exceeds the current Spot Price, your instances will be terminated.

The charge only applies after the first full hour of being unattached, as detailed within the IP Information FAQ, see Will I be charged for the time when my IP address is unattached because my instance failed?:

You are not charged until your Elastic IP address has been unattached for a full hour. As long as you are monitoring your instances, you will have plenty of time to reattach your instance before the charge is metered.

While this applies to a slightly different scenario and instances in general, the following FAQ hints on respectively identical behavior for your spot instance scenario, see Will I be charged if my Spot Instance is terminated by Amazon EC2 before the hour is up?:

No. If the Spot Instance is terminated by Amazon EC2, you will not be charged for a partial hour of usage. However, if you terminate the instance yourself, you will be charged for any hour in which the instance ran.

I'd be surprised if AWS would apply a different pricing model for your scenario specifically, in particular given the comparatively small amount involved as well as the actual intention of pricing being unrelated to cost, see Why am I charged when my Elastic IP address is not associated with an instance?:

In order to help ensure our customers are efficiently using the Elastic IP addresses, we impose the $.01/hr charge for each address when it is not mapped to an instance.

Solution 2:

The elastic ip is not re associated with the resurrected instance and yes amazon charges a small fee while the ip is not attached to the instance.