2

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? Commented Feb 21, 2019 at 17:08
  • 1
    I 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. Commented 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 suffix Commented Feb 21, 2019 at 17:20
  • "Why through API gateway?" Well, custom domains is one great reason. Commented 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. Commented Mar 14, 2019 at 15:52

1 Answer 1

1

There are at least three approaches:

  1. 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.static from express. This way you don't need S3 at all and you can server either a static site or non-static server side rendering.
  2. Again, using aws-serverless-express, but this time create an express service which calls out to S3 using the aws-sdk.
  3. 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.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.