I'm new to AWS and am having some difficulties understanding CloudFront. I have started off with one EC2 instance with NGINX, MySQL, and some PHP files within the public folder to expose APIs to the world. Then I was told CloudFront could be used to protect the instance from malicious attacks. I figured CloudFront required an Elastic Load Balancer. So I created an ELB, one more EC2 instance (two EC2 instances in total), created a "Target group" grouping these two EC2 instances. I also created a S3 bucket, which seemed to be required for CloudFront even though I didn't think I needed one since my app doesn't have any static contents. Now searching through internet, the general idea seemed that the PHP files should live in the EBS of EC2 instances rather than CloudFront S3 bucket since PHP files need to be executed. (and that S3 can't execute any files)
- In this case, do I need to deploy my PHP files to both EC2 instances?
- How do I make EC2 instances point to the same database so that all data is kept in once place? Right now, each EC2 instance holds its own MySQL database in its own EBS storage.
- How does the end to end request flow look like? e.g. The client hits CloudFront. CloudFront talks to ELB. ELB talks to one of my EC2 instances. The EC2 instance connects to the common MySQL database and fetch data. Response data is returned in reverse order.
Am I understanding this correclty?