Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a Web Application Firewall (WAF) with an EC2 instance

I have a web app running on my Amazon EC2 instance. How can I integrate a Web Application Firewall with my EC2?

I have tried setting up the WAF, but it can only be associated with either a CloudFront distribution or an Elastic Load Balancer. Do I need to setup a CloudFront distribution and point it at my EC2 instance?

like image 381
qwerty Avatar asked Oct 16 '25 15:10

qwerty


2 Answers

I ended up setting up an elastic load balancer pointing to my single instance and then adding the web application firewall pointing to the load balancer. It works pretty well and doesn't cost too much more per month from AWS.

like image 164
qwerty Avatar answered Oct 18 '25 06:10

qwerty


The two approaches you can connect AWS WAF to your EC2 instance through,

  • AWS CloudFront
  • Application Load Balancer (ALB)

Each approach has its own pros and cons. If your application servers more of content that can be cached, then having AWS CloudFront along with WAF. If your application cluster needs to scale but most of it is dynamic content then going for ALB is more reasonable.

Note: There is an added fixed cost for ALB (In addition to the variable cost which is not significant though) for each month while CloudFront cost is variable and consumption driven.

It is also possible to have both CloudFront and ALB together where you can add the WAF to CloudFront only.

like image 32
Ashan Avatar answered Oct 18 '25 06:10

Ashan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!