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 samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ class HttpApi(PushEventSource):
"ApiId": PropertyType(False, is_str()),
"Stage": PropertyType(False, is_str()),
"Auth": PropertyType(False, is_type(dict)),
"TimeoutInMillis": PropertyType(False, is_type(int)),
}

def resources_to_link(self, resources):
Expand Down Expand Up @@ -1064,6 +1065,8 @@ def _add_openapi_integration(self, api, function, manage_swagger=False):
editor.add_lambda_integration(self.Path, self.Method, uri, self.Auth, api.get("Auth"), condition=condition)
if self.Auth:
self._add_auth_to_openapi_integration(api, editor)
if self.TimeoutInMillis:
editor.add_timeout_to_method(api=api, path=self.Path, method_name=self.Method, timeout=self.TimeoutInMillis)
api["DefinitionBody"] = editor.openapi

def _add_auth_to_openapi_integration(self, api, editor):
Expand Down
14 changes: 14 additions & 0 deletions samtranslator/open_api/open_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@ def iter_on_path(self):
for path, value in self.paths.items():
yield path

def add_timeout_to_method(self, api, path, method_name, timeout):
"""
Adds a timeout to this path/method.

:param dict api: Reference to the related Api's properties as defined in the template.
:param string path: Path name
:param string method_name: Method name
:param int timeout: Timeout amount, in milliseconds
"""
normalized_method_name = self._normalize_method_name(method_name)
for method_definition in self.get_method_contents(self.get_path(path)[normalized_method_name]):
if self.method_definition_has_integration(method_definition):
method_definition[self._X_APIGW_INTEGRATION]["timeoutInMillis"] = timeout

def add_authorizers_security_definitions(self, authorizers):
"""
Add Authorizer definitions to the securityDefinitions part of Swagger.
Expand Down
6 changes: 6 additions & 0 deletions tests/translator/input/http_api_existing_openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Parameters:
Timeout:
Default: 15000
Type: Number
Resources:
HttpApiFunction:
Type: AWS::Serverless::Function
Expand All @@ -13,10 +17,12 @@ Resources:
Path: /basic
Method: post
ApiId: !Ref MyApi
TimeoutInMillis: 10000
SimpleCase: # path exists, integration doesn't
Type: HttpApi
Properties:
ApiId: !Ref MyApi
TimeoutInMillis: !Ref Timeout
MyApi:
Type: AWS::Serverless::HttpApi
Properties:
Expand Down
10 changes: 10 additions & 0 deletions tests/translator/output/aws-cn/http_api_existing_openapi.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"Parameters": {
"Timeout": {
"Default": 15000,
"Type": "Number"
}
},
"Resources": {
"HttpApiFunctionSimpleCasePermission": {
"Type": "AWS::Lambda::Permission",
Expand Down Expand Up @@ -100,6 +106,7 @@
"post": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"timeoutInMillis": 10000,
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations"
Expand Down Expand Up @@ -151,6 +158,9 @@
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"timeoutInMillis": {
"Ref": "Timeout"
},
"uri": {
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"Parameters": {
"Timeout": {
"Default": 15000,
"Type": "Number"
}
},
"Resources": {
"HttpApiFunctionSimpleCasePermission": {
"Type": "AWS::Lambda::Permission",
Expand Down Expand Up @@ -100,6 +106,7 @@
"post": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"timeoutInMillis": 10000,
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations"
Expand Down Expand Up @@ -151,6 +158,9 @@
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"timeoutInMillis": {
"Ref": "Timeout"
},
"uri": {
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations"
},
Expand Down
16 changes: 13 additions & 3 deletions tests/translator/output/http_api_existing_openapi.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"Parameters": {
"Timeout": {
"Default": 15000,
"Type": "Number"
}
},
"Resources": {
"HttpApiFunctionSimpleCasePermission": {
"Type": "AWS::Lambda::Permission",
Expand Down Expand Up @@ -99,7 +105,8 @@
"/basic": {
"post": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"httpMethod": "POST",
"timeoutInMillis": 10000,
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations"
Expand Down Expand Up @@ -147,9 +154,12 @@
]
}
],
"isDefaultRoute": true,
"isDefaultRoute": true,
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"httpMethod": "POST",
"timeoutInMillis": {
"Ref": "Timeout"
},
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations"
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 @@ -651,6 +651,7 @@ Path | `string` | Uri path for which this function is invoked. MUST start with `
Method | `string` | HTTP method for which this function is invoked.
ApiId | `string` | Identifier of a HttpApi resource which MUST contain an operation with the given path and method. Typically, this is set to [reference](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html) an `AWS::Serverless::HttpApi` resource defined in this template. If not defined, a default `AWS::Serverless::HttpApi` resource is created using a generated OpenApi document contains a union of all paths and methods defined by `HttpApi` events defined in this template that do not specify an ApiId.
Auth | [Function Auth Object](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-httpapifunctionauth.html) | Auth configuration for this specific Api+Path+Method. Useful for overriding the API's `DefaultAuthorizer` setting auth config on an individual path when no `DefaultAuthorizer` is specified.
TimeoutInMillis | `int` | Custom timeout between 50 and 29,000 milliseconds. The default value is 5,000 milliseconds, or 5 seconds for HTTP APIs.

##### Example: HttpApi event source object

Expand Down