Curl the webpage hosted on the same EC2 instance not working - amazon-web-services

I have the web application hosted on EC2 instance and created the DNS for it. The web page works fine when I hit the URL in browser. However, when I curl the URL from EC2 instance, there is no response or rather getting connection error.
curl: (7) Failed connect to dnsurl.com:80; Operation now in progress
Also, in my web application, I am calling a servlet inside another servlet using Apache Post method. This is not working as well. The same code works fine on non-EC2 servers.
Not working:-
curl dnsurl.com
curl elburl.com
Working:-
Curl to other http urls are working fine from EC2 instance
curl http://www.w3schools.com/Tags/ref_urlencode.asp

Your URLs are resolved to the public IP addresses. So the request goes outside your EC2 instance. For that to work you need the following:
Your security group should allow outbound traffic on port 80.
Your network ACL should allow outbound traffic on port 80.

Opening the ALB (Application Load Balancer) to allow inbound traffic from the EC2 instance on port 80 has resolved the issue.

Related

Proxy through EC2 Instance on lambda functions locally using squid

So I have a lambda function that sends a request to an API through the EC2 IP and everything works fine...
Except when I try to send the request locally while testing it doesn't work as the EC2 IP is the only whitelisted IP and my IP is dynamic so it changes alot
What I thought of doing is adding Squid and proxying through it which works fine if I use ssh to connect to it whether requests sent to http or https but that created another problem not all the developers will have access to that EC2 instance...
So I made it publically available and made basic authentication on it except now it doesn't requests to HTTPS unless its google or certain websites.
My question is that why do requests to HTTPS always not work when connecting to the proxy without the SSH tunnel but if it's on something like google it works instantly cause they have less redirects

Sending Requests from postman to AWS ec2 instance

I have my ec2 instance running a docker image and id like to test the functionality of my routes with postman, however whenever I ping the ec2 public dns, it says connection refused. I have the security group opened up for all traffic from my machine and am running the postman desktop app. The example route I'm trying to hit is
https://{IP address here}.compute-1.amazonaws.com:6000/register
and I'm sending a post request with some json in it. All of this works fine on my local machine. Please tell me what I'm missing?
You can't use https:. Instead you must use http: as default EC2 instance url does not support HTTPS. For valid https, the easiest way is to setup ALB or set it up on an instance directly.

AWS Load Balance not resolving to EC2 server

I have created an Ubuntu EC2 instance, and created a load balancer to point to that EC2 instance. The rules on the Listener for the load balancer look OK (ports 80 and 443). I can access the EC2 instance Apache2 HTTPD server in a Browser using the EC2 IP address and Domain (only port 80 is working, no HTTPS).
The inbound rules for the security group look OK, i.e. port 80 and port 443.
The health check is checking the server every 30 seconds, and is showing as healthy every time.
The main problem is that when I try to connect to the webserver in a browser using the DNS name for the load balancer, the page times out, and I do not see the request hit the Apache2 server logs. However, I can connect when using the EC2 instance domain name, and I also see the request hitting the Apache2 server logs.
I wondered if I could please ask if anyone else has had the same issue with the load balancer DNS name not resolving to the EC2 instance?
Many thanks,
Martin
EDIT: This was resolved by setting the correct security group.

aws Internal load balancer net::ERR_NAME_NOT_RESOLVED when calling a service

I have a 3 tier ECS containers application. In presentation tier I have a public subnet where there's an angular app running on nginx server. For that I have application internet-facing load balancer. In the private subnet I have Java Spring REST API service that runs on tomcat server on port 8080, for that there's application internal load balancer. In the other private subnet I have RDS database.
Application client sends requests to internal load balancer url, and renders the response in the application.
While I am able to ssh to ec2 in public subnet and curl to rest service in private subnet and get response:
curl -X POST http://internal-qa-XXXXX-XXXXXXX.eu-west-2.elb.amazonaws.com:8080/api/products/all
I am not able to receive response when accessing the client in the browser. The application runs correctly, however when inspecting in the browser console I see:
POST http://internal-qa-XXXXX-XXXXXXX.eu-west-2.elb.amazonaws.com:8080/api/products/all net::ERR_NAME_NOT_RESOLVED.
I checked containers with Docker logs <container_id> and they run just fine.
Seurity groups and NACL are configured correctly, I even checked with all traffic allowed
Based on the comments.
The issue is most likely caused by the fact that the url endpoint of the internet load balancer is called from the client side, i.e. browser.
Url of internal load balancer isn't publicly callable.
To solve this, either the application has to be modified to use only publicly available endpoints, or the internal load balancer changed into internet facing.

Elastic Load balancer returning empty reply

I have setup a elb instance that has 80 port open and forwarded to ec2 instance. healthcheck seems to be working fine and I do see request being made from elb to instance in instance's access logs.
However, when I try to access load balancer via its DNS name either via curl or via browsers - I get empty response.
curl http://DashApp-LB-417259830.us-west-2.elb.amazonaws.com
curl: (52) Empty reply from server
Looked everywhere but not able to identify what is going on in this case.
I can view default ubuntu apache2 introduction page while hitting to the URL and through curl. That means your ELB is working fine. But you may need to reconfigure your web server for view the index page or reconfigure your ELB which points to right apache2 pages.