serverless-operations / serverless-apigateway-service-proxy

This Serverless Framewrok plugin supports the AWS service proxy integration feature of API Gateway.
260 stars 77 forks source link

manage 404 when proxy to an s3 bucket #63

Open fabien-h opened 4 years ago

fabien-h commented 4 years ago

Hi and thanks for the package :)

Is there a way to manage the 404 in API gateway when proxying to an s3 bucket?

like so:

    - s3:
        path: /{myKey}
        method: get
        action: GetObject
        bucket:
          Ref: S3Bucket
        key:
          pathParam: myKey
        cors: true

=> this one means that if there is a file for myKey, it will be served. But if there is no file for the requested key, how could we redirect everything to a 404 file ?

fabien-h commented 4 years ago

By the way, I tried to make the bucket a website host like this:

resources:
  Resources:
    S3Bucket:
      Type: AWS::S3::Bucket
      Properties:
        AccelerateConfiguration:
          AccelerationStatus: Enabled
        BucketName: __my-bucket-name__
        WebsiteConfiguration:
          ErrorDocument: index.html
          IndexDocument: index.html

It's working when I visit the s3 website endpoint. But not when I visit the API Gateway endpoint.

theburningmonk commented 4 years ago

@fabien-h if you have turned on website hosting on S3 why would you still need the API Gateway service proxy?

fabien-h commented 4 years ago

This would work only if I were to use api.ndd.tld for the api and ndd.tld for the website. But I would prefer having ndd.tld/api for the api.

(and I will have multiple domain names pointing on the same bucket, it would be annoying to have one bucket per domain)

    - s3:
        path: /
        method: get
        action: GetObject
        pathOverride: 'index.html'
        bucket:
          Ref: S3Bucket
        key:
          pathParam: myKey
        cors: true

Allow me to redirect / to /index.html. But not /anything.

theburningmonk commented 4 years ago

ok, you can probably customize the 404 response template to return a redirect, I don't think we let you do that at the moment though

fabien-h commented 4 years ago

Yep, that would work.

I tried a proxy+ resource pointing on the bucket, but aws did not like it.