Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/globals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion samtranslator/model/api/http_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(
tags=None,
auth=None,
access_log_settings=None,
default_route_settings=None,
resource_attributes=None,
passthrough_resource_attributes=None,
):
Expand Down Expand Up @@ -54,6 +55,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

Expand Down Expand Up @@ -237,7 +239,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:
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
Expand All @@ -255,6 +262,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

return stage
Expand Down
2 changes: 2 additions & 0 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}

Expand All @@ -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(),
)
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}

Expand Down
7 changes: 7 additions & 0 deletions tests/translator/input/http_api_def_uri.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
Globals:
HttpApi:
DefaultRouteSettings:
ThrottlingRateLimit: 100.0

Resources:
MyApi:
Type: AWS::Serverless::HttpApi
Properties:
DefinitionUri: s3://bucket/key
StageName: !Join ["", ["Stage", "Name"]]
DefaultRouteSettings:
ThrottlingBurstLimit: 50

MyApi2:
Type: AWS::Serverless::HttpApi
Expand Down
11 changes: 9 additions & 2 deletions tests/translator/output/aws-cn/http_api_def_uri.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
"ApiId": {
"Ref": "MyApi"
},
"AutoDeploy": true,
"AutoDeploy": true,
"DefaultRouteSettings": {
"ThrottlingBurstLimit": 50,
"ThrottlingRateLimit": 100.0
},
"StageName": {
"Fn::Join": [
"",
Expand Down Expand Up @@ -96,7 +100,10 @@
"ApiId": {
"Ref": "MyApi2"
},
"AutoDeploy": true,
"AutoDeploy": true,
"DefaultRouteSettings": {
"ThrottlingRateLimit": 100
},
"StageName": "$default"
}
},
Expand Down
11 changes: 9 additions & 2 deletions tests/translator/output/aws-us-gov/http_api_def_uri.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
"ApiId": {
"Ref": "MyApi"
},
"AutoDeploy": true,
"AutoDeploy": true,
"DefaultRouteSettings": {
"ThrottlingBurstLimit": 50,
"ThrottlingRateLimit": 100.0
},
"StageName": {
"Fn::Join": [
"",
Expand Down Expand Up @@ -96,7 +100,10 @@
"ApiId": {
"Ref": "MyApi2"
},
"AutoDeploy": true,
"AutoDeploy": true,
"DefaultRouteSettings": {
"ThrottlingRateLimit": 100
},
"StageName": "$default"
}
},
Expand Down
11 changes: 9 additions & 2 deletions tests/translator/output/http_api_def_uri.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
"ApiId": {
"Ref": "MyApi"
},
"AutoDeploy": true,
"AutoDeploy": true,
"DefaultRouteSettings": {
"ThrottlingBurstLimit": 50,
"ThrottlingRateLimit": 100.0
},
"StageName": {
"Fn::Join": [
"",
Expand Down Expand Up @@ -96,7 +100,10 @@
"ApiId": {
"Ref": "MyApi2"
},
"AutoDeploy": true,
"AutoDeploy": true,
"DefaultRouteSettings": {
"ThrottlingRateLimit": 100
},
"StageName": "$default"
}
},
Expand Down
1 change: 1 addition & 0 deletions versions/2016-10-31.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ DefinitionBody | `JSON or YAML Object` | OpenApi specification that describes yo
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.
Tags | Map of `string` to `string` | A map (string to string) that specifies the [tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html) to be added to this HTTP API. When the stack is created, SAM will automatically add the following tag: `httpapi:createdBy: SAM`.
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

Expand Down