How to setup WSS Websockets on AWS EC2 Instance? - amazon-web-services

I am fairly new to AWS and I'm setting up an app on AWS that uses WebSockets.
I have an ECS Cluster sitting on an EC2 Instance in AWS. I can externally ping my instance and I can connect to it via plain ws:// however, I cannot connect to it through wss://.
I have allowed All Traffic (Plus all TCP) from Anywhere on my Security Group and Network ACL.
I have also set up an SSL certificate and set up an A record to point the domain to my instances public IP address in Route 53.
I had read a bit about load balancers and I've tried setting one up to get it working however this didn't work either.
Is there any way to achieve this without a Load Balancer?
I know I am probably missing something simple, however, I can't find any straight forward information on setting up wss:// on AWS.
If anyone could walk me through the steps or point me to some applicable instructions that would be greatly appreciated!
Let me know if you need more information.
Thanks
Here are my Security Group Rules:

Related

Unable to connect to AWS ALB through client VPN

I am creating a staging env using AWS and i want it to be accessible through VPN only.
The env was created using Fargate.
I have:
1 front lb connected to several front tasks.
1 back lb connected to several back tasks.
I created the VPN client endpoint.
I can connect to the VPN and ssh to instances in the same security group as my front and back lb. (I tried to start an ec2 instance with the same security group and it works).
But for some reason i am unable to connect to the albs using their dns name or the name used in the route 53 record.
Did i miss something that should be configured for dns to work on aws ressources through the VPN?
I hope this was detailed enough, Thanks in advance.
It sounds like you created a public, Internet-facing ALB. For the ALB to work internally in the VPC (and only in the VPC), you need to create an internal ALB.
See the "Scheme" setting in the documentation.

ECS with ALB makes requests to itself but times out?

I have a PHP + Apache application running in ECS with an Application Load Balance sitting in front of it. Everything works fine except when the application makes request to itself and the request times out.
Let's say the URL to reach the application is www.app.com and in PHP I use Guzzle to send requests to www.app.com but that request will always time out.
I suspect it is a networking issue with ALB but I do not know how I can go about fixing it. Any help please?
Thanks.
As you're using ECS I would recommend replacing calls to a public load balancer with a service mesh instead to allow your application to keep all HTTP(S) traffic internal to the network. This will improve both security and performance (latency is reduced). AWS has an existing product that integrates with ECS to allow this functionality named App Mesh/
Alternatively if you want to stick with what you currently have setup you will need to check the following functionality:
If the hosts are ECS hosts are private then they will need to connect outbound by using a NAT Gateway/NAT Instance in the routing table for the 0.0.0.0/0 route. For Fargate this will depend on if the container is public or private.
If the host/container is public it will need the internet gateway added to its route table for the 0.0.0.0/0 route. Even if inbound access from the ALB to the host is private the host will always speak outbound to the internet via an internet gateway.
Ensure that inbound/outbound security groups allow access to either HTTP or HTTPS

Pointing a domain to securely connect to an ec2 instance running a python app

Say I have an AWS ec2 instance that is running a python application on a certain port say 8000. Also imagine I have a domain name say www.abcd.com that I own. What does it take to make my website use https and securely redirect to the app on my ec2 that is listening on port 8000? Is this even possible to do or do I need something like nginx in between?
Firstly you will need to ensure that your EC2 is in a public subnet with a public IP, it will also need its security group open on whatever port you are hitting it on (8000). At this point you should be able to hit your application on public ip:port.
Now if you want to do the above while using a domain you will want to use AWS's Route 53 service. From this you can create a DNS routing using your domain. You will want to create a route from: application.example.com to your instances public ip. After doing so you should be able to visit: application.example.com and hit your application. In doing the following it is possible now to make your EC2 instance private.
Now if you wish to include HTTPS ontop of this, the best way would be to create a public load balancer with a certificate attached, this would accept HTTPS traffic from your user, then forward that traffic over HTTP to your EC2 on a selected port (8000).
After doing this you will want to change your Route53 entry to point to your load balancer instead of directly at your EC2.
Yes, it is totally possible.
Here is step wise procedure to do it :-
you need to create hosted zone on Route-53 services of amazon
Then it use ns to connect with your domain ( wherever you have registered)
Then you need to connect your ec2 instance ip with your hosted zone
Now you can access your ec2 instances using this domain, but it will be not https
For https, you need certificate, which you can avail from aws certificate-manager
After obtaining the certificate, Follow the steps from this blog How to set up HTTPS for your domain on AWS.
NOTE:- This is just uber point, follow it and look for more insight to how you exactly do it in your case. I followed this step while deploying using elastic-beanstalk.

TCP Relay functionality (like ngrok) in AWS

I have a website which is running on ec2 windows instance. I want to expose that to a public endpoint without opening any port on the ec2 instance. Only outbound connections are allowed on ec2 instance.
How can hook some cloud resource/application in front of my website so that it can be accessed by someone in public internet? What i am looking for is a tcp relay functionality that a call from public internet browser is just routed to my local website on ec2 with minimal effort. Something like what is explained here: https://serverfault.com/questions/760129/what-is-a-tcp-relay-and-when-is-it-used/760142
Can someone suggest something? Or if AWS doesnt expose such a relay functionality, can something be done using websockets in AWS-iot?
I found ngrok as a 3rd party tool, but I want to stick to AWS options only.
This is exactly what a Classic Elastic Load Balancer does. Usually, there's more than one instance (hence, "load balancer") but this works exactly as you describe with just one instance.
The ELB is globally-accessible, and then it forwards the traffic to the instance. Nobody connects directly to your instance.
Of course, you have to open a port on the instance for the ELB to access it, but you would have to do that with any "relay" solution. This access can be limited only to the ELB itself.

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.