AWS - Link IP to domain - amazon-web-services

I have created a wordpress EC2 instance, but every time I restart the IP gets changed so I have to develop site on a new IP which is very inefficient.
My questions are:
Is there IP or something which is fixed so that I don't have to develop wordpress website in different IP every time. Since I am researching here free option is preferred?
Let's say once my website is complete, how can I point this IP to my domain?

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html -> you can use an elastic IP address and then reference that IP in your DNS. Costing for elastic IPs: https://aws.amazon.com/ec2/pricing/on-demand/#Elastic_IP_Addresses - in summary, in certain conditions an elastic IP is free.
Or you could put your EC2 behind a loadbalancer and then reference the load balancers DNS name (ie cname your web address to the load balancers DNS address). You probably want to use the Application Load Balancer. https://aws.amazon.com/elasticloadbalancing/ - this is not free but does present certain advantages over directly referencing the public IP in DNS.

Related

Using an elastic IP with an AWS Load Balancer

It sounds like I cannot use an elastic ip with AWS Application Load Balancer.
I currently own a domain through GoDaddy and the DNS server points to the load balancer via the CNAME. However, if the load balancer dies and gets recreated, its url changes and I then have to change the CNAME and wait for the change to propagate.
There must be a solution around this - what is it?
It looks like the solution might be to use two load balancers - https://aws.amazon.com/blogs/networking-and-content-delivery/using-static-ip-addresses-for-application-load-balancers/, but this seems really excessive - I have a small application right now.
As far as I know, the only way to have a fixed static-IP for a LB is to use a Network Load Balancer.
As stated here
Support for static IP addresses for the load balancer. You can also assign one Elastic IP address per subnet enabled for the load balancer.
An Elastic Load Balancer retains its DNS name as long as you don't replace it manually. If you still want to have a temporary, low-cost solution to this problem, you can consider the following approach:
Assuming the application is deployed in a private subnet, I would proxy the traffic through an EC2 instance until your primary DNS changes propagate.
Launch a small EC2 instance and attach an Elastic IP to it (consider your bandwidth requirements to determine which size).
Configure a proxy (nginx) to forward traffic to your application.
Configure active-passive DNS failover using ELB DNS name and EIP.

Assigning Static IP Address to AWS Load Balancer

How can I assign a static IP address to a ELB. Seems like I cannot.
Some articles online asks to create a Route 53 record but this requires changing CNAME of domain which also redirect email traffic. I just want to change A record not CNAME.
Some articles also mention that I can use a EC2 instance as a reverse proxy. But will a single proxy be able to handle a lot of traffic?
Any solution for this?
AWS' Elastic Load Balancer is actually elastic on two levels as described here:
http://shlomoswidler.com/2009/07/elastic-in-elastic-load-balancing-elb.html
The first level is the load balancer itself. In order to make sure that ELB can scale to whatever volume you have and burst to whatever volume you suddenly encounter, AWS assigns a 'static' DNS hostname (e.g. MyDomainELB-918273645.us-east-1.elb.amazonaws.com). That hostname points to multiple IP addresses. You can see that (from a command line) by running
$ host MyDomainELB-918273645.us-east-1.elb.amazonaws.com
MyDomainELB-918273645.us-east-1.elb.amazonaws.com 172.31.7.2
MyDomainELB-918273645.us-east-1.elb.amazonaws.com 172.31.11.33
The second form of elasticity within the ELB is obviously then ELB directing the query to one of your EC2 instances in the pool.
So, you can see that trying to assign a static IP address to the load balancer would be self-defeating.
Using an EC2 instance as a reverse proxy would also seem self-defeating as you would then create a bottleneck before even getting to the ELB. Might as well just create your own load balancer.
The recommended solution (which you've pointed out) is to create a CNAME that points to the ELB hostname (which won't change).
i.e. my-app.mycompany.com ->
MyDomainELB-918273645.us-east-1.elb.amazonaws.com
This would allow you to integrate your scalable application, behind the ELB within your domain.
I'm not sure I fully understand why you cannot create a CNAME in your DNS or what that has to do with directing email traffic, can you explain?
A new feature in AWS (I believe it was announced at Re:Invent 2017) allows for static IPs with Network Load Balancers (NLB). NLB can only handle layer 4 (TCP) and not HTTP specifics (layer 7).
You can assign one Elastic IP address per availability zone.
For details see the AWS blog post or the NLB documentation.
The "Classic Load Balancer" and "Application Load Balancer" do not support static IPs. If you need a feature only provided by those, you have to fall back to the CNAME solution described above.
A blog was recently published by AWS support on this topic leveraging NLB to provide static IP to Classic and Application load balancer - https://aws.amazon.com/blogs/networking-and-content-delivery/using-static-ip-addresses-for-application-load-balancers/
Summary of solution as described by the post
We end up with a TCP listener on a NLB that accepts traffic and forwards it to an internal ALB. The ALB terminates TLS, examines HTTP headers, and routes requests based on your configured rules to target groups with your instances, servers, or containers. The AWS Lambda function keeps everything in sync by watching the ALB for IP address changes and updating the NLB target group. In the end we’ll have a few static IP addresses that are easy for whitelisting, and we won’t lose any of the benefits of ALB. Note that we will be sending all of the traffic through two load balancers
I found setting up AWS Global Accelerator very straight forward and simple. It created 2 static IP Addresses and a static DNS pointing to my Application load balancer.
Configuring Global Accelerator
Set listeners as TCP port 80, 443
Select your load balancer endpoint (AWS Global Accelerator Configuration)
Add cname record for your dns pointing to the static dns it created
(mywebsite.com > globalacceleratorDNS.com). If any client needs to
whitelist, give them the 2 static IP it created
Pricing is $18 per month + a few pennies per GB of data transfer.
I'm pretty sure its cheaper than the NLB, Nat Gateway, Elastic IP setup.
https://docs.aws.amazon.com/global-accelerator/latest/dg/about-accelerators.html
For little traffic, it might be a solution to set up an EC2 Instance running Nginx as a forwarding proxy.
So you can use the EC2's static IP Address to forward your traffic resolving the ALB's DNS name.
However, it's a kind of a hack, but using a Global Accelerator or an NLB seems to me also like a hack :-)
Unlike the Network Load Balancer, the Application Load Balancer (ALB) does not support Elastic IPs, but that's not the worst part. If you use Route 53 together with the ALB, the DNS automatically sets the TTL to 60 seconds. This appears to be causing problems for our institutional - mainly government - customers running older Windows DNS servers. They just can't keep up with the ALB's Listener changing its public-facing IP on such a short notice. Older DNS infrastructure is either not respecting or is not capable of handling such aggressive TTL.
While I don't like it, AWS recommends to put a Network Load Balancer in front of the Application Load Balancer, per here: https://aws.amazon.com/blogs/networking-and-content-delivery/using-static-ip-addresses-for-application-load-balancers/

How can I serve multiple sub-domains using a single Elastic IP Address in AWS using Route 53?

I have a single Elastic IP address on AWS and I want to use that IP address to route traffic to multiple distinct EC2 instances based on the sub-domain. Basically, in the same manner as virtual hosts in an Apache httpd server. For example:
example.com - ELB: xxx.xxx.xxx.xxx
test.example.com points to EC2 Instance ID 1
build.example.com point to EC2 Instance ID 2
All traffic for each of the domains would go to xxx.xxx.xxx.xxx and then based on the sub-domain name Route 53 would send traffic to the correct instance.
I've been through the documentation for Route 53 and I can't see how this is done. I also looked at Amazon ELB but was unsure if that would work.
Does anyone know how to set this up just using the AWS tools (Route 53 and/or ELB)? I'd rather not have to script it or use a reverse proxy if I can avoid it.
Any ideas or help would be great. Thanks in advance.
You don't need an elastic ip for each server. Each server already comes with an IP, so you can use that (if you actually want to address servers by ip address) - but what you likely should be doing is setting up a cname on your domain for each server, and then addressing the server's by the dns name, not by the ip address.
i.e.:
server1.example.com
server2.example.com
server3.example.com
etc
You don't need to use any EIP's.
Maybe you could explain better why you think all the traffic needs to go thru a single IP address?
I can't say for sure why AWS limits you to just 5 EIPs, but I am pretty sure its because if you find out you need hundreds of EIP's then you are probably doing it wrong - and forcing you to request more than 5 gives them the ability to open up a discussion with you and help you do it a better way.
You'll need 1 Elastic IP address for each distinct EC2 instance that you want to redirect traffic to.
Create your CNAME or ALIAS record for example.com and point it to your ELB.
For each distinct EC2 instance that you need a sub-domain for, do the following:
Allocate an Elastic IP address.
Assign that Elastic IP address to the EC2 instance.
Create an A record in Route 53 pointing subdomain.example.com to that Elastic IP address.
Note: Since your EC2 instances need to be accessed directly, they will need to reside inside a public subnet.

Dynamic ip changing in amazon elastic load balancer creating issue

I have a sub domain and pointed this to an amazon elastic load balancer which includes a few EC2 instances. To point the sub domain we created a CNAME record and put the value of the DNS name of the load balancer.
Now my question is:
You know the IP address of elastic load balancer changes randomly.
So if I request to resolve DNS of my sub domain from any application is there any possibility that there will be a DNS propagation delay issue (which can cause to return me old IP address of the load balancer) if the load balancer's IP has changed.
Should I wait for the propagation of the new IP? Or will the new IP be propagated real time even if the elastic load balance changes just before the DNS request gets resolved?
You need not worry about the IP address of the ELB and its tendency of changing IP address. Instead of the IP address in the CNAME record you just need to put one of the DNS Names (IPv4 or IPv6) an ELB would provide ex: Test-ELB-12345678.us-east-1.elb.amazonaws.com
Quote from the ELB info page
Note: Because the set of IP addresses associated with a LoadBalancer
can change over time, you should never create an "A" record with any
specific IP address. If you want to use a friendly DNS name for your
load balancer instead of the name generated by the Elastic Load
Balancing service, you should create a CNAME record for the
LoadBalancer DNS name, or use Amazon Route 53 to create a hosted zone.
For more information, see Using Domain Names With Elastic Load
Balancing.
There seems to have been such concerns some years ago. You can read the following interesting article which describes some of the potential issues: Elastic Load Balancer: An Elasticity Gotcha
A new ELB IP is added to your ELB pool. The clients of another application that keep the old DNS entry will hit your application:
The problem is that DNS resolution is cached at many layers across the internet. When the ELB scales up and gets a new virtual appliance IP address from the global pool, some client somewhere might still be using that IP address as the resolution of a different ELB’s DNS name. This other ELB might not even belong to you. A few hours ago, another ELB with a different DNS name returned that IP address from a DNS lookup. Now, that IP address is serving your ELB. But some client somewhere may still be using that IP address to attempt to reach an application that is not yours.
An ELB IP is removed from your ELB pool and assigned to some other application's ELB pool. Your clients that keep the old DNS entry will end up hitting that other application:
The flip side occurs when the ELB scales down and releases a virtual appliance IP address back to the global pool. Some client somewhere might continue resolving your ELB’s DNS name to the now-relinquished IP address. When the address is returned to the pool, that client’s attempts to connect to your service will fail. If that same virtual appliance IP is then put into service for another ELB, then the client working with the cached but no-longer-current DNS resolution for your ELB DNS name will be directed to the other ELB virtual appliance, and then onward to back-end instances that are not yours.
Now, this article is from 2009 and as of March 2010, Amazon has partially addressed this concern:
ELB IP addresses will continue to direct traffic to the ELB for one hour after being withdrawn from that ELB’s DNS pool
Keep in mind that some clients that cache DNS entries for longer periods of time could still be affected.

Implement Load Balancer on AWS on existed server with Elastic IP

I'm a backend developer who is a very beginner in Server Administrative here.
I have ec2 instance sitting on AWS with Elastic IP assigned to it.
There are several domains point to this Elastic IP (from my clients).
The server then, response with appropriate content.
At this point, I would like to start using load balance as the number of traffics is increasing.
The question is
Would I be able to apply Load Balancer while still not changing IP Address (Elastic IP) that domains pointing to?
I would be a bit difficult to get to all clients and ask them to update the DNS record point to new IP Address.
So having the same IP would be an ideal solution for me.
It will be a big help if you guys could shed light for me on this.
No. The ELB has a DNS entry that you can setup on your DNS provider or on Route 53. This DNS is the only external link to the ELB and ELBs don't have elastic IPs. Also, keep in mind that the DNS doesn't change on your ELB but the IP can change at discretion of Amazon.
Also, Amazon uses it's own internal mechanism to access instances behind load balancer and I'm pretty sure it doesn't use external addresses (most likely internal)
Another alternative is to setup your own HAproxy instance in EC2 and configure it with an Elastic IP, but that's a little bit more work. (Also, you have to monitor it closely as you would have to manage it in case of changes in traffic patterns)
Hope it helps.