How to prevent accesing AWS beanstalk application through IP address? - amazon-web-services

I have a docker application hosted on AWS beanstalk, and I have configured such application with R53 to access it via a domain name, let's say example.com. Also that application has an IP address for example 50.50.50.50.
What I need is that when a user types in the browser http://50.50.50.50, it gets redirected to http://example.com, how I can achieve that in AWS?
Thanks

The response here How to block accessing the beanstalk web app via ip address helped me to redirect an ip address to a domain name, using ELB rules.

It's not quite clear what you mean by "preventing access through IP".
If the IP is public, you can't do much. That's just how TCP/IP works.
However, if your intention is to keep the original name generated by Beanstalk hidden from public, then you can deploy Beanstalk application in a VPC with its load balancer being "internal". That prevents the load balancer from having a public IP. You can then have a public load balancer with a public IP to which the domain name gets resolved. You still have a public IP for the external load balancer, but there is no way to get to the load balancer created and managed by Beanstalk.
If you have an internal DNS zone in AWS that you'd like to use, then you won't need the externally reachable (from internet) load balancer. This way your application is not reachable from internet.

Related

Configure third party DNS to Static Public Ip attached to AWS ElasticBeanStalk

First of all, I am a beginner in this fields, so apologies If my questions is stupid or just too easy.
What do we want to configure? Well, we have a partnership with a website wwww.partner.com.
We have an application running on elastic beanstalk with an application load balancer. And we need to provide to our partner a STATIC IP for the to link wwww.partner.com/ourcarpet to it.
To sum up, we want this architecture:
DNS - www.partner.com/ourcarpet -------> OUR STATIC IP IN AWS
STATIC IP IN AWS -----> NLB --> EB
I created a Network Load Balancer, and attract to it a STATIC IP. What I do not know is how to access this IP through HTTPS.
Am I using the correct approach? Can I link my Statis IP to a CNAME or A in a DNS outside of AWS?
The "/ourcarpet" part of the URL is not visible for DNS.
The IP and other records can be set only for subdomain/domain names.
In that case www.partner.com/ourcarpet should be redirected to ourcarpet.partner.com (or another domain you control), so you can set the required IP.

How to run a ec2 instance as subdomain in siteground?

I have a Wordpress website with a GoDaddy domain being hosted on SiteGround using the nameservers. I am looking to switch to a React App which is currently running on an EC2 instance in AWS. I want to run the ec2 instance (aka the react app) on a subdomain like beta.domain.com inside SiteGround while still keeping the Wordpress website since its a part of my business. I tried creating a subdomain in SiteGround and then pointed it to my EC2 instance elastic IP (the public ipv4) using an A record but it is showing "This site can't be reached" error once I go to beta.domain.com.
What am I doing wrong? How do I run the EC2 instance in a subdomain hosted in SiteGround?
EDIT
Thank you, everyone, for your help. The problem was the SSL certificate for the HTTPS. The website wasn't coming on due to the HTTPS setup on the Nginx on the EC2 instance. After I put in the details of the certificate it runs properly with just the A record.
Any public address in the AWS environment are never accessible from outside the security groups. Even if you try to ssh from your own machine and if it is not in the inbound rule of the security group of your EC2 instance. I feel there are 3 ways out here.
1.) Adding an all traffic rule in your EC2 Security group inbound rule. This is not recommended as it opens all traffic to your machine.(additional tip: set up secure ssh key with the machine)
2.) Use an ELB to route traffic to your EC2 instance. ELB will provide you with a DNS record which can be used an a CNAME in godaddy(Point 3 shows how to map it as a A record in GoDaddy)
3.) Using Route 53 Hosted Zones - You could delegate your DNS to be managed by AWS Route 53. This way all traffic will be routed to your machine by AWS R53.
Another tip: Elastic IP can also be used which are like permanent static IP Addresses accessible from across internet. This provided a secure communication method to your instances.
Let me know what could be the favorable solution for you. I could help you out further
If you have registered your domain name with Goaddy, you can create subdomain in Godaddy as CNAME and point it to static IP address of your ec2 instance. Here is a link to guide you.
Also your main domain name will point to your Wordpress website on SiteGround.
Now that you have EC2 instance, you can also run a wordpress site on that instance if you like.

How can I specify IP address to my load balancer?

I have ECS service running in AWS and I am going to create application load balancer for this service. I have read through this doc: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-load-balancing.html but what I don't quite understand is how I can specify an entry endpoint IP address to my load balancer. This IP address will be used by client to send requests to my service. Based on my understanding, the IP should be configured in load balancer not my ECS service's task.
Using an IP address for connecting to an elastic load balancer is a bad idea. ELBs are elastic, which means there are multiple instances behind a single load balancer for fault tolerance. That's the reason AWS recommends to use the Hostname instead of IP address.
If you still want to test the connetivity using load balancer IP address, you can try the nslookup command
nslookup yourELBPublicDNS
This will give you multiple addresses back, you can try to hit one. But keep in mind that those IP addresses may change. The reason is simple, if the underlying host for the load balancer fails, it will be replaced by a new one, which most likely will have new IP. But what remains constant is the domain name, so using the hostname is recommended.
As mentioned in the answer IP is bad idea but not if its static IP. As NLB support static IP while application LB does not support static IP.
If you are looking for static IP, then you need to place network LB in the top of application LB, application LB will communicate with backend ECS services while the NLB will be for the client. The client will able to communicate using the static IP of NLB that will not change.
Against each availability zone, you have static IP for NLB, you can check further integration here.
If you are looking for allowing specific IP to use your Endpoint then you need AWS application firewall.

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.

Access AWS EC2 Webserver over own Domain via HTTPS and Load Balancer

I have a webserver running on a AWS EC2 instance (has an elastic IP) that can be accessed over my own domain (www.xy.ch) via http. Now, I need to access the webserver via https and so I created a certificate for my domain (www.xy.ch), uploaded it to AWS Certificate Manager and added the certificate to a Load Balancer connected with my EC2 instance.
This seems to work so far. When I target the DNS name of my Load Balancer (xyz.eu-central-1.elb.amazonaws.com) with a https in front, I can access my webserver. But the certificate is flagged invalid, because its common subject name (my domain name: www.xy.ch) does not match the input (DNS name of Load Balancer: xyz.eu-central-1.elb.amazonaws.com).
But now, I have no idea how to proceed so that I can access my webserver with https over my own domain (www.xy.ch). It does not work at the moment, so I obviously miss a configuration step, but I really don't understand what.
How can I connect my own domain with the Load Balancer's DNS?
I did some research and tried to understand the answers of similar cases (e.g. Assigning Static IP Address to AWS Load Balancer), but could not find a solution for my case.
The solution was indeed to delete all DNS entries pointing to the IP of the webserver and redirecting everything DNS wise over the Load Balancer. Credits to Mark B!