AWS::ApiGatewayV2::Route - AWS CloudFormation

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: String ApiKeyRequired: Boolean AuthorizationScopes: - String AuthorizationType: String AuthorizerId: String ModelSelectionExpression: String OperationName: String RequestModels: Json RequestParameters: Json RouteKey: String RouteResponseSelectionExpression: String Target: 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

AuthorizationScopes

The authorization scopes supported by this route.

Required: No

Type: Array of String

Update requires: No interruption

AuthorizationType

The authorization type for the route. For WebSocket APIs, valid values are NONE for open access, AWS_IAM for using AWS IAM permissions, and CUSTOM for using a Lambda authorizer. For HTTP APIs, valid values are NONE for open access, JWT for using JSON Web Tokens, AWS_IAM for using AWS IAM permissions, and CUSTOM for using a Lambda authorizer.

Required: No

Type: String

Update requires: No interruption

AuthorizerId

The identifier of the Authorizer resource 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