diff --git a/chalice/package.py b/chalice/package.py index 908f988b2..5558b39c9 100644 --- a/chalice/package.py +++ b/chalice/package.py @@ -770,7 +770,7 @@ def _generate_restapi(self, resource, template): template['resource'][ 'aws_api_gateway_rest_api'][ resource.resource_name][ - 'minimum_compression_size'] = ( + 'minimum_compression_size'] = int( resource.minimum_compression) template['resource'].setdefault('aws_api_gateway_stage', {})[ diff --git a/tests/unit/deploy/test_swagger.py b/tests/unit/deploy/test_swagger.py index 0934b94c8..0c39b8691 100644 --- a/tests/unit/deploy/test_swagger.py +++ b/tests/unit/deploy/test_swagger.py @@ -566,8 +566,7 @@ def foo(): } -def test_can_custom_resource_policy_with_cfn(sample_app): - swagger_gen = CFNSwaggerGenerator() +def test_can_custom_resource_policy(sample_app, swagger_gen): rest_api = RestAPI( resource_name='dev', swagger_doc={}, diff --git a/tests/unit/test_package.py b/tests/unit/test_package.py index f18cae077..1fca69f44 100644 --- a/tests/unit/test_package.py +++ b/tests/unit/test_package.py @@ -156,6 +156,11 @@ def generate_template(self, config, chalice_stage_name): 'info': {'title': 'some-app'}, 'x-amazon-apigateway-binary-media-types': [] } + if (isinstance(r, models.RestAPI) and + config.api_gateway_endpoint_type == 'PRIVATE'): + r.swagger_doc['x-amazon-apigateway-policy'] = ( + r.policy.document) + # Same for iam policies on roles elif isinstance(r, models.FileBasedIAMPolicy): r.document = self.EmptyPolicy @@ -236,6 +241,9 @@ def test_can_generate_scheduled_event(self): def test_can_generate_rest_api(self, sample_app_with_auth): config = Config.create(chalice_app=sample_app_with_auth, project_dir='.', + minimum_compression_size=8192, + api_gateway_endpoint_type='PRIVATE', + api_gateway_endpoint_vpce='vpce-abc123', app_name='sample_app', api_gateway_stage='api') template = self.generate_template(config, 'dev') @@ -251,6 +259,13 @@ def test_can_generate_rest_api(self, sample_app_with_auth): '${aws_api_gateway_rest_api.rest_api.execution_arn}/*/*/*') } assert resources['aws_api_gateway_rest_api'] + assert resources['aws_api_gateway_rest_api'][ + 'rest_api']['policy'] + assert resources['aws_api_gateway_rest_api'][ + 'rest_api']['minimum_compression_size'] == 8192 + assert resources['aws_api_gateway_rest_api'][ + 'rest_api']['endpoint_configuration'] == {'types': ['PRIVATE']} + # We should also create the auth lambda function. assert 'myauth' in resources['aws_lambda_function']