From e19df3bdc04580c8e75d12aba056409da80e5289 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Fri, 21 Feb 2020 11:06:52 -0800 Subject: [PATCH 1/4] Add default route settings --- samtranslator/model/api/http_api_generator.py | 5 ++++- samtranslator/model/sam_resources.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/samtranslator/model/api/http_api_generator.py b/samtranslator/model/api/http_api_generator.py index 0643db3322..e5908ce238 100644 --- a/samtranslator/model/api/http_api_generator.py +++ b/samtranslator/model/api/http_api_generator.py @@ -25,6 +25,7 @@ def __init__( tags=None, auth=None, access_log_settings=None, + default_route_settings=None, resource_attributes=None, passthrough_resource_attributes=None, ): @@ -53,6 +54,7 @@ def __init__( self.auth = auth self.tags = tags self.access_log_settings = access_log_settings + self.default_route_settings = default_route_settings self.resource_attributes = resource_attributes self.passthrough_resource_attributes = passthrough_resource_attributes @@ -206,7 +208,7 @@ def _construct_stage(self): """ # If there are no special configurations, don't create a stage and use the default - if not self.stage_name and not self.stage_variables and not self.access_log_settings: + if not self.stage_name and not self.stage_variables and not self.access_log_settings and not self.default_route_settings: return # If StageName is some intrinsic function, then don't prefix the Stage's logical ID @@ -224,6 +226,7 @@ def _construct_stage(self): stage.StageName = self.stage_name stage.StageVariables = self.stage_variables stage.AccessLogSettings = self.access_log_settings + stage.DefaultRouteSettings = self.default_route_settings stage.AutoDeploy = True if self.tags is not None: diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 8683dba3d9..7b3078de1f 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -854,6 +854,7 @@ class SamHttpApi(SamResourceMacro): "StageVariables": PropertyType(False, is_type(dict)), "Cors": PropertyType(False, one_of(is_str(), is_type(dict))), "AccessLogSettings": PropertyType(False, is_type(dict)), + "DefaultRouteSettings": PropertyType(False, is_type(dict)), "Auth": PropertyType(False, is_type(dict)), } @@ -879,6 +880,7 @@ def to_cloudformation(self, **kwargs): tags=self.Tags, auth=self.Auth, access_log_settings=self.AccessLogSettings, + default_route_settings=self.DefaultRouteSettings, resource_attributes=self.resource_attributes, passthrough_resource_attributes=self.get_passthrough_resource_attributes(), ) From cbfeedc2acec668f7750bce58e5d879e5f91a997 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Fri, 21 Feb 2020 11:37:40 -0800 Subject: [PATCH 2/4] Add tests for DefaultRouteSettings --- samtranslator/model/api/http_api_generator.py | 7 ++++++- tests/translator/input/http_api_def_uri.yaml | 2 ++ tests/translator/output/aws-cn/http_api_def_uri.json | 5 ++++- tests/translator/output/aws-us-gov/http_api_def_uri.json | 5 ++++- tests/translator/output/http_api_def_uri.json | 5 ++++- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/samtranslator/model/api/http_api_generator.py b/samtranslator/model/api/http_api_generator.py index e5908ce238..ef5dd87872 100644 --- a/samtranslator/model/api/http_api_generator.py +++ b/samtranslator/model/api/http_api_generator.py @@ -208,7 +208,12 @@ def _construct_stage(self): """ # If there are no special configurations, don't create a stage and use the default - if not self.stage_name and not self.stage_variables and not self.access_log_settings and not self.default_route_settings: + if ( + not self.stage_name + and not self.stage_variables + and not self.access_log_settings + and not self.default_route_settings + ): return # If StageName is some intrinsic function, then don't prefix the Stage's logical ID diff --git a/tests/translator/input/http_api_def_uri.yaml b/tests/translator/input/http_api_def_uri.yaml index 4e6c80316d..e153fbda0c 100644 --- a/tests/translator/input/http_api_def_uri.yaml +++ b/tests/translator/input/http_api_def_uri.yaml @@ -6,6 +6,8 @@ Resources: Tags: Tag: value StageName: !Join ["", ["Stage", "Name"]] + DefaultRouteSettings: + ThrottlingBurstLimit: 50 MyApi2: Type: AWS::Serverless::HttpApi diff --git a/tests/translator/output/aws-cn/http_api_def_uri.json b/tests/translator/output/aws-cn/http_api_def_uri.json index 2bb57f180c..a65de9ba66 100644 --- a/tests/translator/output/aws-cn/http_api_def_uri.json +++ b/tests/translator/output/aws-cn/http_api_def_uri.json @@ -48,7 +48,10 @@ "ApiId": { "Ref": "MyApi" }, - "AutoDeploy": true, + "AutoDeploy": true, + "DefaultRouteSettings": { + "ThrottlingBurstLimit": 50 + }, "StageName": { "Fn::Join": [ "", diff --git a/tests/translator/output/aws-us-gov/http_api_def_uri.json b/tests/translator/output/aws-us-gov/http_api_def_uri.json index c800370291..f55bd4157c 100644 --- a/tests/translator/output/aws-us-gov/http_api_def_uri.json +++ b/tests/translator/output/aws-us-gov/http_api_def_uri.json @@ -48,7 +48,10 @@ "ApiId": { "Ref": "MyApi" }, - "AutoDeploy": true, + "AutoDeploy": true, + "DefaultRouteSettings": { + "ThrottlingBurstLimit": 50 + }, "StageName": { "Fn::Join": [ "", diff --git a/tests/translator/output/http_api_def_uri.json b/tests/translator/output/http_api_def_uri.json index ea5493bd81..c42f85c42f 100644 --- a/tests/translator/output/http_api_def_uri.json +++ b/tests/translator/output/http_api_def_uri.json @@ -48,7 +48,10 @@ "ApiId": { "Ref": "MyApi" }, - "AutoDeploy": true, + "AutoDeploy": true, + "DefaultRouteSettings": { + "ThrottlingBurstLimit": 50 + }, "StageName": { "Fn::Join": [ "", From 0f26f6f4bd18f9e5bdf479d23eb689ac85193b55 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Wed, 26 Feb 2020 11:46:12 -0800 Subject: [PATCH 3/4] Update docs, add DefaultRouteSettings to globals --- docs/globals.rst | 3 +++ samtranslator/plugins/globals/globals.py | 2 +- tests/translator/input/http_api_def_uri.yaml | 5 +++++ tests/translator/output/aws-cn/http_api_def_uri.json | 8 ++++++-- tests/translator/output/aws-us-gov/http_api_def_uri.json | 8 ++++++-- tests/translator/output/http_api_def_uri.json | 8 ++++++-- versions/2016-10-31.md | 1 + 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/docs/globals.rst b/docs/globals.rst index 54fd94df73..ea526eddb7 100644 --- a/docs/globals.rst +++ b/docs/globals.rst @@ -96,6 +96,9 @@ Currently, the following resources and properties are being supported: # Properties of AWS::Serverless::HttpApi # Also works with Implicit APIs Auth: + AccessLogSettings: + Tags: + DefaultRouteSettings: SimpleTable: # Properties of AWS::Serverless::SimpleTable diff --git a/samtranslator/plugins/globals/globals.py b/samtranslator/plugins/globals/globals.py index 568620333f..4b9b2fa21c 100644 --- a/samtranslator/plugins/globals/globals.py +++ b/samtranslator/plugins/globals/globals.py @@ -64,7 +64,7 @@ class Globals(object): "OpenApiVersion", "Domain", ], - SamResourceType.HttpApi.value: ["Auth", "AccessLogSettings", "StageVariables", "Tags"], + SamResourceType.HttpApi.value: ["Auth", "AccessLogSettings", "StageVariables", "Tags", "DefaultRouteSettings"], SamResourceType.SimpleTable.value: ["SSESpecification"], } diff --git a/tests/translator/input/http_api_def_uri.yaml b/tests/translator/input/http_api_def_uri.yaml index e153fbda0c..cd7016f2e2 100644 --- a/tests/translator/input/http_api_def_uri.yaml +++ b/tests/translator/input/http_api_def_uri.yaml @@ -1,3 +1,8 @@ +Globals: + HttpApi: + DefaultRouteSettings: + ThrottlingRateLimit: 100.0 + Resources: MyApi: Type: AWS::Serverless::HttpApi diff --git a/tests/translator/output/aws-cn/http_api_def_uri.json b/tests/translator/output/aws-cn/http_api_def_uri.json index a65de9ba66..31dc5c76da 100644 --- a/tests/translator/output/aws-cn/http_api_def_uri.json +++ b/tests/translator/output/aws-cn/http_api_def_uri.json @@ -50,7 +50,8 @@ }, "AutoDeploy": true, "DefaultRouteSettings": { - "ThrottlingBurstLimit": 50 + "ThrottlingBurstLimit": 50, + "ThrottlingRateLimit": 100.0 }, "StageName": { "Fn::Join": [ @@ -105,7 +106,10 @@ "ApiId": { "Ref": "MyApi2" }, - "AutoDeploy": true, + "AutoDeploy": true, + "DefaultRouteSettings": { + "ThrottlingRateLimit": 100 + }, "StageName": "$default", "Tags": [ { diff --git a/tests/translator/output/aws-us-gov/http_api_def_uri.json b/tests/translator/output/aws-us-gov/http_api_def_uri.json index f55bd4157c..a1664dab8f 100644 --- a/tests/translator/output/aws-us-gov/http_api_def_uri.json +++ b/tests/translator/output/aws-us-gov/http_api_def_uri.json @@ -50,7 +50,8 @@ }, "AutoDeploy": true, "DefaultRouteSettings": { - "ThrottlingBurstLimit": 50 + "ThrottlingBurstLimit": 50, + "ThrottlingRateLimit": 100.0 }, "StageName": { "Fn::Join": [ @@ -105,7 +106,10 @@ "ApiId": { "Ref": "MyApi2" }, - "AutoDeploy": true, + "AutoDeploy": true, + "DefaultRouteSettings": { + "ThrottlingRateLimit": 100 + }, "StageName": "$default", "Tags": [ { diff --git a/tests/translator/output/http_api_def_uri.json b/tests/translator/output/http_api_def_uri.json index c42f85c42f..27dfa5dcaf 100644 --- a/tests/translator/output/http_api_def_uri.json +++ b/tests/translator/output/http_api_def_uri.json @@ -50,7 +50,8 @@ }, "AutoDeploy": true, "DefaultRouteSettings": { - "ThrottlingBurstLimit": 50 + "ThrottlingBurstLimit": 50, + "ThrottlingRateLimit": 100.0 }, "StageName": { "Fn::Join": [ @@ -105,7 +106,10 @@ "ApiId": { "Ref": "MyApi2" }, - "AutoDeploy": true, + "AutoDeploy": true, + "DefaultRouteSettings": { + "ThrottlingRateLimit": 100 + }, "StageName": "$default", "Tags": [ { diff --git a/versions/2016-10-31.md b/versions/2016-10-31.md index c9ec6b5b24..bdf29c3e78 100644 --- a/versions/2016-10-31.md +++ b/versions/2016-10-31.md @@ -279,6 +279,7 @@ DefinitionUri | `string` | [S3 Location Object](#s3-location-o DefinitionBody | `JSON or YAML Object` | OpenApi specification that describes your API. If neither `DefinitionUri` nor `DefinitionBody` are specified, SAM will generate a `DefinitionBody` for you based on your template configuration. Auth | [HTTP API Auth Object](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-httpapi-httpapiauth.html) | Configure authorization to control access to your API Gateway API. AccessLogSettings | [AccessLogSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-stage-accesslogsettings.html) | Settings for logging access in a stage. +DefaultRouteSettings | [RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-stage-routesettings.html) | The default route settings for this HTTP API. ##### Return values From cb3a969abcad0dbf040d4eeb29c35f7de5423724 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Wed, 26 Feb 2020 12:25:24 -0800 Subject: [PATCH 4/4] Fix test errors --- tests/translator/output/aws-cn/http_api_def_uri.json | 8 +------- tests/translator/output/aws-us-gov/http_api_def_uri.json | 8 +------- tests/translator/output/http_api_def_uri.json | 8 +------- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/tests/translator/output/aws-cn/http_api_def_uri.json b/tests/translator/output/aws-cn/http_api_def_uri.json index e1d0cb07e2..f285640fc4 100644 --- a/tests/translator/output/aws-cn/http_api_def_uri.json +++ b/tests/translator/output/aws-cn/http_api_def_uri.json @@ -104,13 +104,7 @@ "DefaultRouteSettings": { "ThrottlingRateLimit": 100 }, - "StageName": "$default", - "Tags": [ - { - "Value": "value", - "Key": "Tag" - } - ] + "StageName": "$default" } }, "MyApi2": { diff --git a/tests/translator/output/aws-us-gov/http_api_def_uri.json b/tests/translator/output/aws-us-gov/http_api_def_uri.json index 171e36bd8f..5190687504 100644 --- a/tests/translator/output/aws-us-gov/http_api_def_uri.json +++ b/tests/translator/output/aws-us-gov/http_api_def_uri.json @@ -104,13 +104,7 @@ "DefaultRouteSettings": { "ThrottlingRateLimit": 100 }, - "StageName": "$default", - "Tags": [ - { - "Value": "value", - "Key": "Tag" - } - ] + "StageName": "$default" } }, "MyApi2": { diff --git a/tests/translator/output/http_api_def_uri.json b/tests/translator/output/http_api_def_uri.json index bbcc4c67ed..e6a1041ffa 100644 --- a/tests/translator/output/http_api_def_uri.json +++ b/tests/translator/output/http_api_def_uri.json @@ -104,13 +104,7 @@ "DefaultRouteSettings": { "ThrottlingRateLimit": 100 }, - "StageName": "$default", - "Tags": [ - { - "Value": "value", - "Key": "Tag" - } - ] + "StageName": "$default" } }, "MyApi2": {