Api
The object describing an Api
event source type. If an AWS::Serverless::Api resource is defined, the path
and method values must correspond to an operation in the OpenAPI definition of the API.
If no AWS::Serverless::Api is defined, the function input and output are a representation of the HTTP request and HTTP response.
For example, using the JavaScript API, the status code and body of the response can be controlled by returning an object with the keys statusCode and body.
Syntax
To declare this entity in your Amazon Serverless Application Model (Amazon SAM) template, use the following syntax.
YAML
Auth:
ApiFunctionAuth
Method:String
Path:String
RequestModel:RequestModel
RequestParameters:List of [ String | RequestParameter ]
RestApiId:String
TimeoutInMillis:Integer
Properties
-
Auth
-
Auth configuration for this specific Api+Path+Method.
Useful for overriding the API's
DefaultAuthorizer
setting auth config on an individual path when noDefaultAuthorizer
is specified or overriding the defaultApiKeyRequired
setting.Type: ApiFunctionAuth
Required: No
Amazon CloudFormation compatibility: This property is unique to Amazon SAM and doesn't have an Amazon CloudFormation equivalent.
-
Method
-
HTTP method for which this function is invoked.
Type: String
Required: Yes
Amazon CloudFormation compatibility: This property is unique to Amazon SAM and doesn't have an Amazon CloudFormation equivalent.
-
Path
-
Uri path for which this function is invoked. Must start with
/
.Type: String
Required: Yes
Amazon CloudFormation compatibility: This property is unique to Amazon SAM and doesn't have an Amazon CloudFormation equivalent.
-
RequestModel
-
Request model to use for this specific Api+Path+Method. This should reference the name of a model specified in the
Models
section of an AWS::Serverless::Api resource.Type: RequestModel
Required: No
Amazon CloudFormation compatibility: This property is unique to Amazon SAM and doesn't have an Amazon CloudFormation equivalent.
-
RequestParameters
-
Request parameters configuration for this specific Api+Path+Method. All parameter names must start with
method.request
and must be limited tomethod.request.header
,method.request.querystring
, ormethod.request.path
.A list can contain both parameter name strings and RequestParameter objects. For strings, the
Required
andCaching
properties will default tofalse
.Type: List of [ String | RequestParameter ]
Required: No
Amazon CloudFormation compatibility: This property is unique to Amazon SAM and doesn't have an Amazon CloudFormation equivalent.
-
RestApiId
-
Identifier of a RestApi resource, which must contain an operation with the given path and method. Typically, this is set to reference an AWS::Serverless::Api resource defined in this template.
If you don't define this property, Amazon SAM creates a default AWS::Serverless::Api resource using a generated
OpenApi
document. That resource contains a union of all paths and methods defined byApi
events in the same template that do not specify aRestApiId
.This cannot reference an AWS::Serverless::Api resource defined in another template.
Type: String
Required: No
Amazon CloudFormation compatibility: This property is unique to Amazon SAM and doesn't have an Amazon CloudFormation equivalent.
TimeoutInMillis
-
Custom timeout between 50 and 29,000 milliseconds.
Note
When you specify this property, Amazon SAM modifies your OpenAPI definition. The OpenAPI definition must be specified inline using the
DefinitionBody
property.Type: Integer
Required: No
Default: 29,000 milliseconds or 29 seconds
Amazon CloudFormation compatibility: This property is unique to Amazon SAM and doesn't have an Amazon CloudFormation equivalent.
Examples
Basic example
YAML
Events: ApiEvent: Type: Api Properties: Path: /path Method: get RequestParameters: - method.request.header.Authorization - method.request.querystring.keyword: Required: true Caching: false