Skip to content
v0.2.8-beta

API Gateway

Create HTTP and REST APIs with Tarn.

Partial Support

Supported Operations

HTTP APIs (v2)

OperationStatusNotes
CreateApiSupported
DeleteApiSupported
GetApiSupported
ListApisSupported
UpdateApiSupported
CreateRouteSupported$default route, path parameters
DeleteRouteSupported
CreateIntegrationSupportedLambda (AWS_PROXY) and SQS (AWS)
DeleteIntegrationSupported
CreateStageSupported
DeleteStageSupported
GetStageSupported
ListStagesSupported

REST APIs (v1)

OperationStatusNotes
CreateRestApiSupported
DeleteRestApiSupported
GetRestApiSupported
GetResourcesSupported
CreateResourceSupported
CreateMethodSupportedGET, POST, PUT, DELETE, PATCH
PutIntegrationSupportedLambda proxy and SQS AWS integrations
CreateDeploymentSupported
CreateStageSupported

Examples

HTTP API with Lambda

JavaScript (AWS SDK)
javascript
import { ApiGatewayV2Client, CreateApiCommand } from "@aws-sdk/client-apigatewayv2";
import { LambdaClient, CreateFunctionCommand } from "@aws-sdk/client-lambda";

const apiGw = new ApiGatewayV2Client({ endpoint: "http://127.0.0.1:4566" });
const lambda = new LambdaClient({ endpoint: "http://127.0.0.1:4566" });

// Create API
const apiRes = await apiGw.send(new CreateApiCommand({
  Name: "my-api",
  ProtocolType: "HTTP"
}));

// Create Lambda function and integrate...

REST API with Terraform

HCL
hcl
resource "aws_api_gateway_rest_api" "example" {
  name = "example-api"
}

resource "aws_api_gateway_resource" "items" {
  rest_api_id = aws_api_gateway_rest_api.example.id
  parent_id   = aws_api_gateway_rest_api.example.root_resource_id
  path_part   = "items"
}

resource "aws_api_gateway_method" "items_get" {
  rest_api_id      = aws_api_gateway_rest_api.example.id
  resource_id      = aws_api_gateway_resource.items.id
  http_method      = "GET"
  authorization    = "NONE"
}

resource "aws_api_gateway_integration" "items_lambda" {
  rest_api_id      = aws_api_gateway_rest_api.example.id
  resource_id      = aws_api_gateway_resource.items.id
  http_method      = aws_api_gateway_method.items_get.http_method
  type             = "AWS_PROXY"
  integration_http_method = "POST"
  uri              = aws_lambda_function.example.invoke_arn
}

Invoke URLs

Once deployed, invoke your API:

bash
# HTTP API (v2)
curl https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/path

# REST API (v1)
curl https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/path

In Tarn:

bash
curl http://127.0.0.1:4566/_apigateway/{api-id}/{stage}/path

Known Limitations

  • HTTP APIs support ProtocolType=HTTP only
  • HTTP APIs support Lambda and SQS integrations only
  • REST APIs execute Lambda proxy and SQS AWS integrations only
  • No CORS configuration
  • No request/response transformations
  • No API keys or usage plans
  • No caching

Released under the Apache 2.0 License