Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an AWS S3 Static Site access REST API in VPC?

I've read through quite a few pages of documentation and other StackOverflow questions/answers but can't seem to come across anything that can help me with my scenario.

I'm hosting a public, static site in an S3 bucket. This site makes some calls to an API that I have hosted in an EC2-instance in a VPC. Because of this, my API can only be called by other instances and services in the same VPC.

But I'm not sure how to allow the S3 Bucket site access to my API.

I've tried creating VPC Endpoints and going down that route, but all that did was restrict access to my S3 site from only the instances within my VPC (which is not what I want).

I would appreciate any help with this, thank you so much. Hopefully my question is clear.

like image 750
Chris Leyva Avatar asked Dec 24 '22 04:12

Chris Leyva


1 Answers

No, S3 Static Websites are 100% client side code. So it's basically just html + css + javascript being delivered, as-is from S3. If you want to get dynamic content into your website, you need to look at calling an API accessible from your user's browser, i.e. from the internet.

AWS API Gateway with Private Integrations could be used to accept the incoming REST call and send it on to your EC2 Server in your VPC.

My preferred solution to adding dynamic data to S3 Static Websites is using API Gateway with AWS Lambda to create a serverless website. This minimises running costs, maintenance, and allows for quick deployments. See The Serverless Framework for getting up and running with this solution.

like image 111
Matt D Avatar answered Jan 08 '23 22:01

Matt D