-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Gateway Compression #676
Conversation
Hey, just wanted to follow up on this. Let me know if you see any issues or want anything else added/changed. Thanks! |
Please wait on this PR, I just saw that the API gateway swagger now supports compression with a value of |
So, unfortunately it looks like there is a bug in the AWS api. Using the >>> import boto3
>>> import json
>>> client = boto3.client('apigateway')
>>> swagger_doc_1 = {'info': {'version': '1.0', 'title': 'comp'}, 'paths': {'/': {'get': {'responses': {'200': {'description': '200 response', 'schema': {'$ref': '#/definitions/Empty'}}}, 'x-amazon-apigateway-integration': {'contentHandling': 'CONVERT_TO_TEXT', 'responses': {'default': {'statusCode': '200'}}, 'uri': 'arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:562628674386:function:comp-dev/invocations', 'httpMethod': 'POST', 'passthroughBehavior': 'when_no_match', 'type': 'aws_proxy'}, 'consumes': ['application/json'], 'produces': ['application/json']}}}, 'schemes': ['https'], 'x-amazon-apigateway-minimum-compression-size': 1000, 'x-amazon-apigateway-binary-media-types': ['application/octet-stream', 'application/x-tar', 'application/zip', 'audio/basic', 'audio/ogg', 'audio/mp4', 'audio/mpeg', 'audio/wav', 'audio/webm', 'image/png', 'image/jpg', 'image/gif', 'video/ogg', 'video/mpeg', 'video/webm'], 'definitions': {'Empty': {'type': 'object', 'title': 'Empty Schema'}}, 'swagger': '2.0'}
>>> response_1 = client.import_rest_api(body=json.dumps(swagger_doc_1, indent=2))
>>> rest_api_id = response_1['id']
>>> response_1['minimumCompressionSize']
>>> 1000
>>> response_1['ResponseMetadata']['HTTPStatusCode']
>>> 200
>>>
>>> swagger_doc_2 = {'info': {'version': '1.0', 'title': 'comp'}, 'paths': {'/': {'get': {'responses': {'200': {'description': '200 response', 'schema': {'$ref': '#/definitions/Empty'}}}, 'x-amazon-apigateway-integration': {'contentHandling': 'CONVERT_TO_TEXT', 'responses': {'default': {'statusCode': '200'}}, 'uri': 'arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:562628674386:function:comp-dev/invocations', 'httpMethod': 'POST', 'passthroughBehavior': 'when_no_match', 'type': 'aws_proxy'}, 'consumes': ['application/json'], 'produces': ['application/json']}}}, 'schemes': ['https'], 'x-amazon-apigateway-minimum-compression-size': 5000, 'x-amazon-apigateway-binary-media-types': ['application/octet-stream', 'application/x-tar', 'application/zip', 'audio/basic', 'audio/ogg', 'audio/mp4', 'audio/mpeg', 'audio/wav', 'audio/webm', 'image/png', 'image/jpg', 'image/gif', 'video/ogg', 'video/mpeg', 'video/webm'], 'definitions': {'Empty': {'type': 'object', 'title': 'Empty Schema'}}, 'swagger': '2.0'}
>>> response_2 = client.put_rest_api(restApiId=rest_api_id, mode='overwrite',
body=json.dumps(swagger_doc_2, indent=2))
>>> response_2['minimumCompressionSize']
>>> 1000
>>> response_2['ResponseMetadata']['HTTPStatusCode']
>>> 200 As you can see, the first time the gateway is created with a minimum compression size of If you want to merge the current pull request that works using the boto Thanks! |
Hey, just wanted to follow up on this. Let me know if you see any issues or want anything else added/changed. Thanks! |
Any news on this? |
@nplutt I tried to reproduce your problem but for me it is working everything as expected. Maybe they fixed it? |
Thanks for the feedback @gallmerci. When I created this it was less than a week after they released the compression feature to API Gateway. I'm happy to hear that the issue that I was running into was fixed. If you have the ability to merge this pull request I would be happy to make the changes. If not I'm probably not going to touch this, I have several pull requests that have been open since around January and none of them have recieved any feedback from any of the maintainers despite me reaching out multiple times. |
@nplutt I would love to be able to do this, but unfortunately, I am not :( |
Is how the compression handled documented? I need to post a large json from an ETL process. The compression should help. |
a400a47
to
820d119
Compare
Also added support for CloudFormation.
Codecov Report
@@ Coverage Diff @@
## master #676 +/- ##
==========================================
+ Coverage 95.54% 95.58% +0.03%
==========================================
Files 27 27
Lines 4606 4645 +39
Branches 582 587 +5
==========================================
+ Hits 4401 4440 +39
Misses 134 134
Partials 71 71
Continue to review full report at Codecov.
|
@nplutt Thanks for the submission. I rebased this off of the current state of the master branch and updated it to use the new deployer. Added support for cloudformation as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Had a minor formatting thing but it's not a blocker.
chalice/deploy/validate.py
Outdated
@@ -146,6 +149,18 @@ def _validate_cors_for_route(route_url, route_methods): | |||
) | |||
|
|||
|
|||
def validate_minimum_compression_size(config): | |||
# type: (Config) -> None | |||
if config.minimum_compression_size is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super important, but it would be nice to reduce the indentation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good just had a small comment
docs/source/topics/configfile.rst
Outdated
the minimum compression size to apply to the API gateway. If | ||
this key is specified in both a stage specific config option | ||
as well as a top level key, the stage specific key will | ||
override the top level key for the given stage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth linking the service docs for this as well (e.g. https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-gzip-compression-decompression.html)
Completes feature for issue #672.
I was disappointed that there is no way to do this using the API Gateway Extensions to Swagger, so I had to use the update_rest_api method and set the compression level after the API Gateway is deployed.
The new functionality can is enabled by using an optional configuration parameter of
minimum_compression_size
in theconfig.json
file. The parameter can be set at either the global level or the stage level and if both exist the stage level overrides the global level. Below is an example:In this example
dev
would have aminimum_compression_size
of 0 andtest
would have aminimum_compression_size
of 1000.Let me know if you would like anything changed, thanks!