AWS ALB/Cloudfront file upload - returns status code 413

2/20/2020

Context

I am running my applications using CloudFront, S3, ALB, and Kubernetes. The backend(which is the API) is running in Kubernetes(EKS), exposed using a public ALB. The frontend runs as a static site hosted in S3 bucket and served via cloudfront. All this is managed via Terraform.

Problem

When I upload a file greater than 7MB, the upload fails. If I check the API logs in the k8s container, I see:

 Completed 413 Payload Too Large in 1651ms

As you can see status code of 413 is returned.

My ALB snippet is:

resource "kubernetes_ingress" "example" {
  metadata {
    name      = "example_name"
    namespace = "example_namespace"

    annotations = {
      "kubernetes.io/ingress.class"                = "alb"
      "alb.ingress.kubernetes.io/scheme"           = "internet-facing"
  ...
    }
...

Any idea why I'm getting this?

-- dckr9
amazon-cloudfront
amazon-elb
amazon-web-services
kubernetes-ingress

1 Answer

2/21/2020

This limitation can be related with current settings of your nginx ingress controller. As you can read in its documentation:

Custom max body size

For NGINX, an 413 error will be returned to the client when the size in a request exceeds the maximum allowed size of the client request body. This size can be configured by the parameter client_max_body_size.

To configure this setting globally for all Ingress rules, the proxy-body-size value may be set in the NGINX ConfigMap. To use custom values in an Ingress rule define these annotation:

nginx.ingress.kubernetes.io/proxy-body-size: 8m

So if you don't want to set this option globally in nginx ingress controller ConfigMap, you can adjust it by adding the following annotation to your ingress resource definition:

nginx.ingress.kubernetes.io/proxy-body-size: 8m

Let me know if it helps.

-- mario
Source: StackOverflow