I am able to access the index.html of my webapp via API-Gateway, but how can it use the JS and CSS files, that are stored in the same S3-Bucket?
6
-
What's the use case?Deiv– Deiv2019-02-21 17:08:05 +00:00Commented Feb 21, 2019 at 17:08
-
1I have got an angular-app in a S3-Bucket. Via API-Gateway (URL) I access the index.html of the S3 Bucket, which works. However, it does not have access to the CSS and JS files.J. Doe– J. Doe2019-02-21 17:17:13 +00:00Commented Feb 21, 2019 at 17:17
-
Why through API gateway? You can simply make the objects public and access directly from S3. Either way, if you really need to go through API gateway, as long as your API gw has access to those objects then it should be able to access them all, regardless of their suffixDeiv– Deiv2019-02-21 17:20:02 +00:00Commented Feb 21, 2019 at 17:20
-
"Why through API gateway?" Well, custom domains is one great reason.John Vandivier– John Vandivier2019-03-14 15:46:34 +00:00Commented Mar 14, 2019 at 15:46
-
@JohnVandivier and why not use custom domains in combination with AWS S3? One can easily deploy a website statically using s3 and custom domains.Thales Minussi– Thales Minussi2019-03-14 15:52:10 +00:00Commented Mar 14, 2019 at 15:52
|
Show 1 more comment
1 Answer
There are at least three approaches:
- aws-serverless-express will allow you to serve an express api through Lambda, which can integrate with API Gateway. You can use this approach to statically serve a ui application with
express.staticfrom express. This way you don't need S3 at all and you can server either a static site or non-static server side rendering. - Again, using aws-serverless-express, but this time create an express service which calls out to S3 using the aws-sdk.
- A third option is you can set API Gateway up to use S3 proxy as pictured below
There may be other ways to do this using Cloudfront or Route 53 for orchestration instead of API Gateway, particularly if you are ok to have UI and back end on different domains then you allow some CORS requests. I personally prefer approach #1 because the infrastructure is simpler.
