'create a record set to a spot instance on aws route 53

Is it possible to create a recordset to a spot instance using route 53?

I've created a fleet spot request and I want to be able to create an A name in route53 without using elastic IP.

Is that feature possible? because I know that when the instance will go down a new IP will be assigned to it.



Solution 1:[1]

I can think of two ways to accomplish this:

  1. You can configure the UserData option of the Launch Template for your Spot instances to register themselves to Route53, every time they are launched. An instance can get its assigned public IP by checking the following endpoint: http://169.254.169.254/latest/meta-data/public-ipv4. For this to work, you need to add Route53 write permissions to the EC2 instance. Here is the Launch Template documentation
  2. Use Cloudwatch Events and Lambda to update the DNS records when an EC2 instance changes its state. You can configure CloudWatch to receive changes to EC2 state changes, and trigger a Lambda function that reacts to them. For example, when an instance gets terminated you can remove them from the recordset, and add a new one when it goes from pending to running. Check this AWS Blog Post for more information on how to do this.

I hope it helps

Solution 2:[2]

Spot fleet and Spot requests both can use Launch Templates. In the launch template you can assign the spot instances roles that can allow you to modify the Route 53 zones. In the template use the user data feature to write a script that executes during the startup of the Instance. This script can get the IP address of the instances.

Example: curl http://169.254.169.254/latest/meta-data/local-ipv4 for private IP address or curl http://169.254.169.254/latest/meta-data/public-ipv4 for public IP address.

And this IP address then can be updated in the A record using AWS Cli.

Solution 3:[3]

I'm not sure if it's different with fleets but I was having a similar problem with test servers and persistent spot requests. We used some scripting, cron jobs on reboot and the AWS CLI that Yogesh_D referenced above. I'm not sure this would work for your case but here's the post just in case: Is there a way to have an AWS spot instance register with route53 on boot?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 guzmonne
Solution 2 Yogesh_D
Solution 3 darrin