Updating DNS Record Set for Dynamic EC2 Instances in a Cost-Efficient Manner

Dynamic DNS Record Set Update for Auto Scaling Group Instances

Prev Question Next Question

Question

You are working on a small project for your personal usage.

The application is hosted in an Auto Scaling group.

There is only 1 instance in the ASG and the EC2 instance may be terminated and recreated from time to time.

The EC2 DNS name and IP are changed when a new instance is launched in the ASG.

You own a hosted zone in Route 53 and plan to create a record set to route the traffic to the instance.

You have very limited budget.

Which method is the most cost-efficient to update the record set dynamically?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - C.

A cost-efficient method is required in this scenario.

The combinations of CloudWatch Event + Lambda function should be chosen.

Please check https://aws.amazon.com/blogs/compute/building-a-dynamic-dns-for-route-53-using-cloudwatch-events-and-lambda/ for the reference.

Option A is incorrect: This option needs to configure a network load balancer for the record set.

It is not the most cost-efficient method.

Option B is incorrect: Because the Alias record in Route 53 cannot configure the Auto Scaling group ARN as its target.

This option does not work.

Option C is CORRECT: Both CloudWatch Event rule and Lambda function are serverless and very cheap.

CloudWatch Event can capture the ASG event and notify the Lambda function to update the record set accordingly.

Option D is incorrect: Option C is more accurate as the Lambda function does not need to run periodically.

It should be invoked only when a new EC2 instance is launched.

Option A: Create a network load balancer to point to the Auto Scaling group. Create an Alias record that routes the traffic to the load balancer.

This option involves creating a network load balancer (NLB) to point to the Auto Scaling group (ASG). An alias record is then created in Route 53 to route the traffic to the NLB. This option has the advantage of not requiring the Route 53 record set to be changed dynamically as the NLB remains constant even when the EC2 instance is terminated and a new one is launched. However, it involves creating and managing an NLB, which may not be the most cost-efficient option for a small project.

Option B: Create an Alias record in Route 53 that has the Auto Scaling group ARN as its target. The Route 53 record set does not need to be changed dynamically.

This option involves creating an alias record in Route 53 that has the ASG ARN as its target. This option also does not require the Route 53 record set to be changed dynamically. However, this option assumes that the ASG DNS name remains the same even when the EC2 instance is terminated and a new one is launched. This may not always be the case, as the DNS name may change if the ASG is recreated.

Option C: Configure a CloudWatch Event rule to monitor the Auto Scaling events. The CloudWatch Event rule triggers a Lambda function to point the CNAME of the record set to the DNS of the new EC2 instance.

This option involves configuring a CloudWatch Event rule to monitor the ASG events. When a new EC2 instance is launched in the ASG, the CloudWatch Event rule triggers a Lambda function to point the CNAME of the record set to the DNS of the new EC2 instance. This option ensures that the Route 53 record set is always pointing to the correct EC2 instance. However, it requires the creation and management of a Lambda function, which may not be the most cost-efficient option for a small project.

Option D: Create a Lambda function to periodically check the Auto Scaling group. If there is a new EC2 instance launched, update the Route 53 record set with the new IP address.

This option involves creating a Lambda function to periodically check the ASG for new EC2 instances. If a new EC2 instance is launched, the Lambda function updates the Route 53 record set with the new IP address. This option also ensures that the Route 53 record set is always pointing to the correct EC2 instance. However, it requires the creation and management of a Lambda function, which may not be the most cost-efficient option for a small project.

Conclusion: Of the four options, Option B may be the most cost-efficient as it does not require the creation and management of additional resources such as an NLB or Lambda function. However, it assumes that the ASG DNS name remains the same even when the EC2 instance is terminated and a new one is launched, which may not always be the case. If this assumption cannot be made, then Option C or D may be a better choice as they ensure that the Route 53 record set is always pointing to the correct EC2 instance.