where to place web app server in AWS VPC ? - amazon-web-services

What is the best practice to place web app server in AWS VPC? In Private subnet with ELB or Public subnet?
As per my understanding the best practice is to place web app server in public subnet.

Do not place the web server in the public subnet. Launch them in a private subnet and front end them with ELB that runs in a public subnet. You do not want to deal with DDoS attacks on your web server, leave that to ELB which does an excellent job in addition to load balancing.
See:
How do I connect a public-facing load balancer to EC2 instances that have private IP addresses?
Scenario 2: VPC with Public and Private Subnets (NAT)

Related

auto assign public ip for ec2 webserver

I am going to deploy Nginx webserver to run my angular application in AWS ec2 and i have 2 subnets public and private. to reach my nginx web application I will use ALB which is in public subnet, now my question is
can i deploy the Nginx webserver(ec2) in private subnet.
in which case I should enable public IP to my nginx ec2 server
You should not assign a public IP address to the nginx EC2 server because:
It should only be accessed via the Load Balancer, and
It is in a private subnet, so the Public IP address will not work (that is, traffic will not be routed to the instance)
You should deploy the Load Balancer in the public subnet and the EC2 instance in the private subnet.
can i deploy the Nginx webserver(ec2) in private subnet.
Yes, you can. In ideal case the private webserver does not need any internet access.
in which case I should enable public IP to my nginx ec2 server
The server does not require public IP. If you place it in a private subnet, and you want your server to access internet (e.g. to install packages or updates) you have to setup NAT gateway in a public subnet.

Load balancers for a decoupled web application on AWS

I'm not completely familiar with the load balancers in AWS. So, the idea is to set up a VPC with a public subnet and a private subnet. The instances and the ASG for the front-end will be in the public subnet, and the instances and the ASG for the backend will be in the private subnet. My question is which load balancer should I place between the front-end and the backend, and is it supposed to go in the public or the private subnet?
Any help is appreciated.
Hello I recommend you to use S3 + CloudFront for your web if its react app ( html,JS...) you can earn a lot with S3 + Cloudfront to have a serveless web hosting high scalable, and security also !!!
Regarding the back end part, the best practice is to put an ELB in your public subnet wich redirect traffic api to your back-end to a target group ASG in your private subnet.
You can add a certificate https ACM to your Alb to perform the transit security.
and the traffic from your ALB and instances ASG is in the http (port 80)
Finally the query will come from the client device wich whill get the app from cloudfront/S3 and perform a call to your ELB in public wichi redirect to your instances in private subnet.

Application deployed only in Private Subnet

From AWS infrastructure side sometimes the client suggests on having their whole application to be in private subnet (both fronetend and backend), so that their application is secure . Now i do understand that for an Application to be in private subnet , we cant have internet facing App Load Balancer as AWS doesnt allow it . So in this kind of scenario , how this can be handled please. I know that we can make use of VPC endpoints so that the internal traffic doesnt leave AWS network. Is there any way this can be done that i am not aware. Thanks in advance
What you've described is a very broad topic and probably sits within the realms of "How do I architect a web app securely in AWS?"
As with most things, there isn't just one answer. Below is a common approach to deploying a simple web app behind a load balancer
Internet facing load balancer with application in private subnet
The application can be deployed in private subnets (so instances are not assigned public IP addresses). You can then deploy an internet facing load balancer to the public subnets which will be able to route traffic to your private subnets (assuming your VPC route tables are configured correctly)
If the instances deployed in the private subnets need and outbound Internet comnection you can deploy a NAT Gateway (with the appropriate routes in your VPC route table of course)
In this setup your inbound traffic goes:
Internet Gateway --> Load Balancer Node (Public Subnet) --> Target Group (Private Subnet)
And your outbound traffic (if needed) goes:
Instance (private subnet) --> NAT Gateway --> Internet Gateway
You can't have an internet facing load balancer in private subnets (Quote from your question)
That is true, but as described above you can deploy an internet facing load balancer into public subnets and still have it route traffic to your private subnets. Just make sure your VPC route table is setup correctly (i.e. there is a route in the route tables associated with your subnets for your VPC CIDR block)

AWS API gateway to load balancer on private subnet ecs connection for microservices

I have a VPC with public (With NAT gateway ) and private subnet.
As part of designing microservices on aws platform, my goal is
1. Ec2 in private subnet
2. load balancer pointing to ec2 in private subnet
3. Api gateway pointing to load balancer,
my problem is I can only use application load balancer when the instance is in public subnet but the load balancer is accessible publicly. however, I want my services to be accessed only using api gateway,
I have read using NLB + VPCLink, however, the ec2 instances should still be on public subnet. no luck trying on private subnet.
allow the traffic only from Network Loadbalancer to the instances in public subnet.
(or)
https://aws.amazon.com/premiumsupport/knowledge-center/public-load-balancer-private-ec2/
You can now provide access to HTTP(S) resources within your Amazon Virtual Private Cloud (VPC) without exposing them directly to the public Internet. You can use API Gateway to create an API endpoint that is integrated with your VPC. You create an endpoint to your VPC by setting up a VPC link between your VPC and a Network Load Balancer (NLB), which is provided by Elastic Load Balancing. The NLB send requests to multiple destinations in your VPC such as Amazon EC2 instances, Auto Scaling groups, or Amazon ECS services. NLBs also support private connectivity over AWS Direct Connect, so that applications in your own data centers will be able to connect to your VPC via the Amazon private network.
https://aws.amazon.com/about-aws/whats-new/2017/11/amazon-api-gateway-supports-endpoint-integrations-with-private-vpcs/

Using a NAT for Public Facing AWS Web Server

I have read articles describing placing a public facing web server in a public subnet and placing application servers in a private subnet. Furthermore, using a NAT Gateway to allow servers in a private subnet to communicate with the Internet, etc.
Alternatively, is it acceptable to also place your web server in the private subnet and flow all Internet traffic through the NAT Gateway?
If the webserver's in the private subnet, it won't be reachable from the Internet. NAT gateways give instances outgoing access, not incoming.
However, you can have webservers in a private subnet, and serve them via an Elastic Load Balancer placed in a public subnet.