This is the new AWS CloudFormation Template Reference Guide. Please update your bookmarks and links. For help getting started with CloudFormation, see the AWS CloudFormation User Guide.
AWS::ApiGatewayV2::Route
The AWS::ApiGatewayV2::Route resource creates a route for an
API.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::ApiGatewayV2::Route", "Properties" : { "ApiId" :String, "ApiKeyRequired" :Boolean, "AuthorizationScopes" :[ String, ... ], "AuthorizationType" :String, "AuthorizerId" :String, "ModelSelectionExpression" :String, "OperationName" :String, "RequestModels" :Json, "RequestParameters" :Json, "RouteKey" :String, "RouteResponseSelectionExpression" :String, "Target" :String} }
YAML
Type: AWS::ApiGatewayV2::Route Properties: ApiId:StringApiKeyRequired:BooleanAuthorizationScopes:- StringAuthorizationType:StringAuthorizerId:StringModelSelectionExpression:StringOperationName:StringRequestModels:JsonRequestParameters:JsonRouteKey:StringRouteResponseSelectionExpression:StringTarget:String
Properties
ApiId-
The API identifier.
Required: Yes
Type: String
Update requires: Replacement
ApiKeyRequired-
Specifies whether an API key is required for the route. Supported only for WebSocket APIs.
Required: No
Type: Boolean
Update requires: No interruption
-
The authorization scopes supported by this route.
Required: No
Type: Array of String
Update requires: No interruption
-
The authorization type for the route. For WebSocket APIs, valid values are
NONEfor open access,AWS_IAMfor using AWS IAM permissions, andCUSTOMfor using a Lambda authorizer. For HTTP APIs, valid values areNONEfor open access,JWTfor using JSON Web Tokens,AWS_IAMfor using AWS IAM permissions, andCUSTOMfor using a Lambda authorizer.Required: No
Type: String
Update requires: No interruption
-
The identifier of the
Authorizerresource to be associated with this route. The authorizer identifier is generated by API Gateway when you created the authorizer.Required: No
Type: String
Update requires: No interruption
ModelSelectionExpression-
The model selection expression for the route. Supported only for WebSocket APIs.
Required: No
Type: String
Update requires: No interruption
OperationName-
The operation name for the route.
Required: No
Type: String
Update requires: No interruption
RequestModels-
The request models for the route. Supported only for WebSocket APIs.
Required: No
Type: Json
Update requires: No interruption
RequestParameters-
The request parameters for the route. Supported only for WebSocket APIs.
Required: No
Type: Json
Update requires: No interruption
RouteKey-
The route key for the route. For HTTP APIs, the route key can be either
$default, or a combination of an HTTP method and resource path, for example,GET /pets.Required: Yes
Type: String
Update requires: No interruption
RouteResponseSelectionExpression-
The route response selection expression for the route. Supported only for WebSocket APIs.
Required: No
Type: String
Update requires: No interruption
Target-
The target for the route.
Required: No
Type: String
Update requires: No interruption
Return values
Ref
When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the Route resource ID, such as
abcd123.
For more information about using the Ref function, see Ref.
Fn::GetAtt
The Fn::GetAtt intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.
For more information about using the Fn::GetAtt intrinsic function, see Fn::GetAtt.
RouteId-
The route ID.
Examples
HTTP API route creation example
The following example creates a route resource called
MyRoute for an HTTP API called
MyAPI that already has an integration
resource called MyIntegration. The route accepts POST requests to /signup.
JSON
"MyRoute": { "Type": "AWS::ApiGatewayV2::Route", "Properties": { "ApiId": { "Ref": "MyAPI" }, "RouteKey": "POST /signup", "Target": { "Fn::Join": [ "/", [ "integrations", { "Ref": "MyIntegration" } ] ] } } }
YAML
MyRoute: Type: AWS::ApiGatewayV2::Route Properties: ApiId: !Ref MyAPI RouteKey: 'POST /signup' Target: !Join - / - - integrations - !Ref MyIntegration
WebSocket API route creation example
The following example creates a route resource called
MyRoute for a WebSocket API called
MyAPI that already has an integration
resource called MyIntegration. The route has a route key
value of routekey1.
JSON
{ "MyRoute": { "Type": "AWS::ApiGatewayV2::Route", "DependsOn": [ "MyIntegration" ], "Properties": { "ApiId": { "Ref": "MyApi" }, "RouteKey": "routekey1", "AuthorizationType": "NONE", "Target": { "Fn::Join": [ "/", [ "integrations", { "Ref": "MyIntegration" } ] ] } } } }
YAML
MyRoute: Type: 'AWS::ApiGatewayV2::Route' DependsOn: - MyIntegration Properties: ApiId: !Ref MyApi RouteKey: routekey1 AuthorizationType: NONE Target: !Join - / - - integrations - !Ref MyIntegration
See also
-
CreateRoute in the Amazon API Gateway Version 2 API Reference