Description
Set MinimumCompressionSize on AWS::Serverless::Api to the smallest response worth compressing, in bytes. Omit it to leave compression disabled.
Potential impact
Compression can save bandwidth on large responses and add latency on small ones. Use HTTPS for transport encryption.
Remediation
Choose a threshold from 0 to 10485760 bytes. After deployment, request a typical response with Accept-Encoding: gzip and compare transfer size and latency.
Examples
The example uses 114 bytes. Supply your own threshold and log group ARN.
Before
yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
TracingEnabled: true
CacheClusterEnabled: true
AccessLogSetting:
DestinationArn: arn:aws:logs:us-east-1:123456789012:log-group:my-log-group
Format: '{"requestId":"$context.requestId"}'
After
yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
TracingEnabled: true
CacheClusterEnabled: true
AccessLogSetting:
DestinationArn: arn:aws:logs:us-east-1:123456789012:log-group:my-log-group
Format: '{"requestId":"$context.requestId"}'
MinimumCompressionSize: 114