How to integrate API Gateway with S3 AWS Service using greedy path proxy resource - amazon-s3

I have files in an S3 bucket that I am serving using AWS API Gateway
I have a resource GET /{file} that maps to mybucket:/{file}
ie http://myapigateway.com/test1.txt correctly returns mybucket:/test1.txt
Now I want to serve files with directory paths:
http://myapigateway.com/dirA/test2.txt should return the file mybucket:/dirA/test2.txt
I can not get this to work. The problem is that when I set the new API Gateway resource to use greedy path matches as a "proxy resource":
GET /{proxy+}
I no longer have the option to integrate with s3 (see image below)
I tried to pass the method.request.querystring.proxy var instead of method.request.path.proxy to prevent the slashes from being stripped but that didn't help.
If I can't integrate with s3 directly, is there any way I can work-around with a lambda function?
screen-shot: no option to integrate with AWS Service

Related

API Gateway to Redirect {client-hostname} to S3 bucket Folder (path overwride)

Was wondering about the integration between S3 and Api-Gateway. S3 is one of the integration you can set up on an HTTP endpoint.
I have a REST API, i'm trying to route traffic from to a specific bucket.
The idea is to serve multiple static sites from a single bucket.
The tree is simple: S3://{ bucket_name }/{ hostname }/{ index.html }. and when clients GET { project1.mydomain.com } the Gateway will redirect to a file on: { bucket_name }/{ hostname }/{ index.html }.
My research have pointed me that using a server is unavoidable reading here
but I still wonder about this integration. Thought to ask to expend my knowledge.
Is there any way to redirect a path url to a GetObject S3 API request?
Is there a way to map a header to API Gateway Service integration parameter? maybe by passthrough the request?
What is the Path override for?
How to set the bucket path?
Regarding "AWS Subdomain", it is mentioned to leave it blank on the main tutorial i found on this subject (here), but couldn't find a proper resource on what it is for, maybe on other services.
Would love to learn more.
< rant>
i'm really struggling with AWS documentation, was wondering if it's just me. I'm an experienced engineer and I feel terrible looking for information in there. I've learned how to list my S3 buckets to the whole world before I've learned how to fetch an item ✌️
< /rant>

AWS S3 Static hosing: Routing rules doesn't work with cloudfront

I am using AWS S3 static web hosting for my VueJs SPA app. I have setup routing rules in S3 and it works perfectly fine when I access it using S3 static hosting url. But, I also have configured CloudFront to use it with my custom domain. Since single page apps need to be routed via index.html, I have setup custom error page in cloudfront to redirect 404 errors to index.html. So now routing rules I have setup in S3 no longer works.
What is the best way to get S3 routing rules to work along with CloudFront custom error page setup for SPA?
I think I am a bit late but here goes anyway,
Apparently you can't do that if you are using S3 REST_API endpoints (example-bucket.s3.amazonaws.com) as your origin for your CloudFront distribution, you have to use the S3 website url provided by S3 as the origin (example-bucket.s3-website-[region].amazonaws.com). Also, objects must be public you can't lock your bucket to the distribution by origin policy.
So,
Objects must be public.
S3 bucket website option must be turned on.
Distribution origin has to come from the S3 website url, not the rest api endpoint.
EDIT:
I was mistaking, actually, you can do it with the REST_API endpoint too, you only have to create a Custom Error Response inside your CloudFront distribution, probably only for the 404 and 403 error codes, set the "Customize Error Response" option to "yes", Response Page Path to "/index.html" and HTTP Response Code to "200". You can find that option inside your distribution and the error pages tab if you are using the console.

AWS Lambda and S3 static file routing with custom domain

I have been trying to setup a simple Serverless App on AWS but am failing to understand how to put the pieces together with a custom domain.
The web app routes should looks something like this:
/ -> Serves static HTML / CSS / JS from S3 Bucket
/api/people/ -> Lambda Function call
/api/dogs/ -> Lambda Function call
/stats/ -> Lambda Function call
/backend/ -> Serves static HTML / CSS / JS from S3 Bucket
I have tried using API Gateway and CloudFront and hooking them up with Route53 to my custom domain but either seem to only support static S3 or Lambda JSON routing.
How would an AWS Architecture look where I can freely choose routes to route to different AWS resources (e.g / -> S3, /api/people/ -> Lambda, /api/dogs/ -> Lambda, /backend/ -> S3)`
Thank you very much in advance.
One of the main challenges in setting up a full stack web application with serverless technologies is that having a proxy layer to route messages both for compute (Lambda) and static files (HTML, JS, CSS, Images). Although API Gateway is using CloudFront internally, it won't help in serving both the static content from S3 and dynamic content using the same domain (Avoiding Cross Domain Access).
Therefore its needed to use AWS CloudFront to proxy messages both to API Gateway and Lambda which I have been using for most of the web projects. The tradeoff is, there is an added latency and cost (Which is not significant though) while accessing API Gateway through CloudFront which should be acceptable.
For more details, you can refer my article on Full Stack Serverless Web Apps with AWS.
I am relatively new to AWS, but I recently was successful in getting a static site running via S3 and accessing Lambda functions, so it is pretty fresh in my mind.
First of all, there is no way to direct particular paths of domains to particular AWS resources. So, if you use Route 53 to point your domain to an S3 bucket to serve static resources, all the paths of that domain will attempt to fetch resources in that S3 bucket only. Now, since your "backend" is also serving static files from an S3 bucket this could technically be in the same S3 bucket as you use for "/" just stored in the folder called "backend" if that is acceptable.
Otherwise, the real answer is to use sub-domains.
With this concept you could do the following:
www.yourdomain.com point to the S3 that contains the static site for "/"
api.yourdomain.com point to an AWS API Gateway that can act as a
proxy for accessing your Lambda functions
backend.yourdomain.com point to the S3 bucket for your "/backend"
site if needed
You can just add record sets to your hosted zone for your domain to create sub-domains. See documentation here.
Getting all of this set up is way out of the scope of this question and would be way to lengthy, but hopefully this information makes sense and helps to lead you in a direction that makes more sense.

S3 ACL Public-Read on Swisscom Cloud

AFAIK Swisscom does not support Uploads into the S3 Service with a public-read status. The only way to share a file is via presigned url. Is this correct? Already asked here:
How to serve user-uploaded files on Swisscom Application Cloud?
In the docs, it's written though that PUT Object ACLis supported. According to the Amazon Specs this should include public-read as well.
What is the current case now? What is the best workaround if it's not possible to store public readable binaries? For example to serve images for a website stored on Swisscom S3?
Swisscom Dynamic Storage currently does not support static web pages, which means every http request has to be signed. Workaround are shareable URLs with a very long expiration date so called Pre-signed Object URL.

Create my own error page for Amazon S3

I was wondering if it's possible to create my own error pages for my S3 buckets. I've got CloudFront enabled and I am using my own CNAME to assign the S3 to a subdomain for my website. This helps me create tidy links that reference my domain name.
When someone tries to access a file that has perhaps been deleted or the link isn't quite correct, they get the XML S3 error page which is ugly and not very helpful to the user.
Is there a way to override these error pages so I can display a helpful HTML page instead?
If you configure your bucket as a 'website', you can create custom error pages.
For more details see the Amazon announcement of this feature and the AWS developer guide.
There are however some caveats with this approach, a major one being that your objects need to be publicly available.
It also works with Cloudfront, but the same public access limitations apply. See https://forums.aws.amazon.com/ann.jspa?annID=921.
If you want, you can try these out
right away by configuring your Amazon
S3 bucket as a website and making the
new Amazon S3 website endpoint a
custom origin for your CloudFront
distribution. A few notes when you do
this. First, you must set your custom
origin protocol policy to “http-only.”
Second, you’ll need to use a tool that
supports CloudFront’s custom origin
feature – the AWS Management Console
does not at this point offer this
feature. Finally, note that when you
use Amazon S3’s static website
feature, all the content in your S3
bucket must be publicly accessible, so
you cannot use CloudFront’s private
content feature with that bucket. If
you would like to use private content
with S3, you need to use the S3 REST
endpoint (e.g., s3.amazonaws.com).