aws_apigatewayv2_api cost estimation
HTTP and WebSocket APIs. HTTP API is 70% cheaper than REST API: $1.00 per million requests vs $3.50. WebSocket connections billed separately by connection-minute and messages.
API Gateway v2 covers two API protocols: HTTP APIs and WebSocket APIs. The aws_apigatewayv2_api resource sets the protocol via the protocol_type attribute.
HTTP APIs are the modern replacement for REST APIs (aws_api_gateway_rest_api). Pricing: $1.00 per million requests for the first 300M/month, $0.90 for next 700M, $0.80 above 1B (us-east-1). Compared to REST APIs at $3.50/million, HTTP APIs are 70% cheaper.
The trade-off: HTTP APIs have fewer features. Missing from HTTP APIs vs REST: request/response transformations, AWS WAF native integration (only via CloudFront), private endpoints, X-Ray tracing fine-grained. For most workloads (auth + Lambda backend + CORS + simple routes), HTTP APIs cover the requirements.
WebSocket APIs pricing has three components: - Message count: $1.00 per million messages - Connection minutes: $0.25 per million connection-minutes - Data transfer: standard internet egress at $0.09/GB
A WebSocket app with 10,000 concurrent connections active for 8 hours = 4.8B connection-minutes = $1,200 just in connection minutes. Plus messages. WebSocket APIs are expensive at scale; consider alternatives (AppSync, Lambda@Edge) for high-volume real-time.
c3x estimates v2 API costs based on protocol_type and expected request/message volume from c3x-usage.yml.
Terraform example
A minimal but realistic configuration that C3X can estimate.
resource "aws_apigatewayv2_api" "http" {
name = "production-api"
protocol_type = "HTTP"
cors_configuration {
allow_origins = ["https://app.example.com"]
allow_methods = ["GET", "POST"]
allow_headers = ["content-type", "authorization"]
}
}
resource "aws_apigatewayv2_integration" "lambda" {
api_id = aws_apigatewayv2_api.http.id
integration_type = "AWS_PROXY"
integration_uri = aws_lambda_function.api.invoke_arn
payload_format_version = "2.0"
}
resource "aws_apigatewayv2_stage" "prod" {
api_id = aws_apigatewayv2_api.http.id
name = "prod"
auto_deploy = true
}Pricing dimensions
What you actually pay for when you provision aws_apigatewayv2_api.
| Dimension | Unit | What's being charged |
|---|---|---|
| HTTP API requests | per million requests | Requests billed in 512 KB increments. Tiered pricing reduces rate above 300M/month. $1.00/M up to 300M, $0.90/M next 700M, $0.80/M above 1B |
| WebSocket messages | per million messages | Messages sent or received over WebSocket connections. $1.00 per 1M messages |
| WebSocket connection minutes | per million connection-minutes | Connection time across all WebSocket connections. The bill driver for high-concurrency apps. $0.25 per 1M connection-minutes |
| Data transfer out | per GB | Internet egress from the API. Standard AWS data transfer rates. $0.09/GB tier 1 |
Optimization tips
Common ways to reduce aws_apigatewayv2_api cost without changing the workload.
Use HTTP API instead of REST API
70% on request feesHTTP APIs are 70% cheaper than REST APIs ($1/M vs $3.50/M). For most workloads (Lambda backend, JWT auth, simple routing), HTTP APIs are fully sufficient. Migrate REST → HTTP for substantial savings.
Front public APIs with CloudFront
50-95% on requestsCloudFront caching reduces API Gateway requests dramatically. A 95% cache hit rate cuts API requests to 5% of original. Plus CloudFront's egress pricing is lower for many regions.
Use AppSync for high-volume WebSocket
AppSync (managed GraphQL with subscriptions) is often cheaper than raw WebSocket APIs for real-time. AppSync bills $4 per million queries + $2 per million real-time updates, but has built-in caching and connection management.
Close idle WebSocket connections
$0.25 per million idle-minutes savedWebSocket connection minutes bill continuously. Idle connections (heartbeats only) still bill. Implement client-side connection close after N minutes idle. Saves on connection-minute fees for long-lived but unused connections.
FAQ
Why is HTTP API cheaper than REST API?
HTTP APIs are AWS's newer architecture, designed for the most common use cases (Lambda/HTTP backend, JWT auth, CORS, simple routes). They skip features that have low usage (transformations, complex auth). The simpler internal architecture lets AWS price them lower.
Can I migrate REST API to HTTP API?
Sometimes. If your REST API uses request/response transformations, AWS WAF, private endpoints, or other REST-only features, you can't migrate directly. For simple proxy-to-Lambda APIs, migration is straightforward — change protocol_type and update integration_type from AWS to AWS_PROXY.
Are WebSocket APIs ever cost-effective?
For modest-concurrency real-time apps (under a few thousand concurrent users), yes. At higher concurrency, the connection-minute fees grow linearly with users × time. Alternatives like AppSync subscriptions or self-hosted on EC2/ECS become competitive above 10K concurrent connections.
What's the AWS Free Tier for API Gateway v2?
1M HTTP API requests/month for 12 months for new accounts. WebSocket APIs have 1M messages and 750K connection-minutes/month for 12 months. After the free tier, standard rates apply.
Related resources
Estimate this resource in your own Terraform
Free, open source, no API key. C3X parses your Terraform and shows line-item cost for every resource, including aws_apigatewayv2_api.