Is it possible to serve a static file from s3 on ingress-nginx?

7/27/2020

I am currently trying to implement an error page which doesn't touch/bloat the backend.

In theory, on a 503 it should proxy the request from the host to https://mybucketname.s3.amazonaws.com/folder/file.html.

The closest I have gotten was a redirect to the s3 page, however, in this case it must be proxied.

my server snippet at the moment consists of the following:

  server-snippet: |
    error_page 404 "https://mywebsite.com/notfound";
    proxy_intercept_errors on;
-- Dylan
amazon-s3
kubernetes
kubernetes-ingress
nginx
nginx-ingress

1 Answer

10/12/2020

You need to add some metadata to you Ingress manifest

metadata:
  annotations:
    nginx.ingress.kubernetes.io/upstream-vhost: <s3bucketname>
    nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
    nginx.ingress.kubernetes.io/use-regex: "true"

Also, you need to create a service that will be used by Ingress

Like something that:

kind: Service
apiVersion: v1
metadata:
  name: front-end-service
spec:
  type: ExternalName
  externalName: <s3bucket or cloudfront link>
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 80
-- Anton Oleynick
Source: StackOverflow