Search code examples
serverless-frameworkaws-serverlessserverless-plugins

MinimumSizeCompression is not working with serverless


I'm using the new serverless compression option using minimumCompressionSize = 1KB. Everything works fine on payloads > 1KB, yet payload <1KB are also compressed.

It's like the minimumCompressionSize remains 0 whatever value I choose (See image Below)

here is my serverless.yml:

  name: aws
  runtime: nodejs8.10
  region: eu-west-1
  apiGateway:
    minimumCompressionSize: 1024
...

Have you encountered this problem? How can I solve it without manually updating the api-gateway configuration on aws?

Thank you in advance.

I followed this guide: https://medium.com/@OneMuppet_/gzip-deflate-content-from-aws-api-gateway-using-serverless-36e208da4270

and tried what is in the official documentation: https://serverless.com/framework/docs/providers/aws/events/apigateway#compression

enter image description here


Solution

  • Have you tried to override the cloudformation template Override AWS CloudFormation Resource ?

    you can specify a custom ressource with your provider name where you override the properties MinimumCompressionSize of AWS::ApiGateway::RestApi

    Example (serverless.yaml) :

    service: my-awesome-project-to-duplicate-pizzas
    
    provider:
      name: aws
      ...
    

    you can add:

    Resources:
        aws:
            Type: AWS::ApiGateway::RestApi
            Properties:
                MinimumCompressionSize: 1024
    

    links that can help :

    https://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/transform-aws-serverless.html

    https://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-minimumcompressionsize