How to configure API Gateway in front of EKS: HTTP API, VPC link, and JWT with Cognito
Compare REST, HTTP, and WebSocket APIs, then publish a private EKS service through an internal ALB, a VPC link, a Cognito JWT authorizer, throttling, a custom domain, and access logs, in Terraform and the AWS CLI.
Kubernetes$ aws apigatewayv2 create-api --name orders-api --protocol-type HTTP▍A very common pattern among teams running on EKS: the whole cluster lives in private subnets, and the only public entry point is Amazon API Gateway. It terminates TLS, validates the JWT, enforces request limits, writes access logs, and only then forwards the traffic, inside the VPC, to an internal load balancer in front of the pods. In this guide we build that path end to end, with Terraform and with the AWS CLI, and test it with curl.
REST, HTTP, or WebSocket?
API Gateway comes in three “flavors.” They are different products, with different control-plane APIs (apigateway for REST, apigatewayv2 for HTTP and WebSocket).
| REST API | HTTP API | WebSocket API | |
|---|---|---|---|
| Focus | Full-featured API management | Simple, low-cost proxy to backends | Persistent bidirectional connections |
| Authorization | IAM, Lambda, COGNITO_USER_POOLS, and, more recently, JWT |
IAM, Lambda, and native JWT | IAM and Lambda |
| API keys and usage plans | Yes | No | No |
| Throttling | Account, stage/method, and per client (usage plan) | Account, stage, and route | Account and route |
| Caching, request validation, WAF | Yes | No | No |
| Deployment | Explicit deployments to stages | Auto-deploy and the $default stage |
Deployments to stages |
| Private integration | VPC link (ALB through VPC link V2, or NLB through legacy V1) | VPC link V2 to an ALB, NLB, or Cloud Map | VPC link to an NLB (check the docs) |
Rule of thumb: start with the HTTP API. Use REST when you need usage plans with per-client API keys, caching, request validation, WAF, or private/edge endpoints. Use WebSocket only if the application really keeps connections open (routes $connect, $disconnect, and $default).
One recent change: according to the documentation history (2026-11-17), REST APIs now accept JWT authorizers as well. The local AWS CLI help already shows --type JWT and --jwt-configuration on aws apigateway create-authorizer, but it is a new feature: check the current docs before swapping a COGNITO_USER_POOLS authorizer for one.
Architecture: private EKS behind API Gateway
client ──HTTPS──> API Gateway (HTTP API, JWT authorizer, throttling, logs)
│ VPC link V2 (ENIs in the private subnets)
▼
internal ALB (created by the AWS Load Balancer Controller)
│ target-type: ip
▼
pods behind the "orders" Service on EKS
1. Internal ALB with the AWS Load Balancer Controller
The AWS Load Balancer Controller turns an Ingress into an ALB. With scheme: internal, the ALB only gets private IPs and is not reachable from the internet. A type: LoadBalancer Service would give you an NLB instead, which also works with a VPC link. The annotation names belong to the controller; check the docs for the version you have installed.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: orders
namespace: shop
annotations:
alb.ingress.kubernetes.io/scheme: internal
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}]'
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:111122223333:certificate/abc
alb.ingress.kubernetes.io/healthcheck-path: /health
spec:
ingressClassName: alb
rules:
- host: orders.internal.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: orders
port:
number: 80
This manifest passed kubectl apply --dry-run=server in the lab (kind 1.37), but the lab has neither the controller nor AWS, so ALB creation was not tested. For a refresher on Services and Ingress, see the introduction to Kubernetes Services.
2. VPC link and integration
A VPC link V2 creates network interfaces in the private subnets you specify. The integration points at the ALB listener ARN (not its DNS name). Since the listener is HTTPS, set tls_config to a name the ALB certificate covers. The VPC link security group needs egress to the ALB, and the ALB security group must allow ingress from that security group.
Complete Terraform
Validated with terraform validate and terraform fmt -check using the hashicorp/aws 6.74.0 provider (no plan or apply, since the lab has no AWS account). You get the listener ARN after the controller has created the ALB, for example with aws elbv2 describe-listeners.
variable "private_subnet_ids" { type = list(string) }
variable "vpc_id" { type = string }
variable "alb_listener_arn" { type = string }
variable "cognito_issuer" { type = string } # https://cognito-idp.<region>.amazonaws.com/<userPoolId>
variable "cognito_client_id" { type = string }
variable "certificate_arn" { type = string }
resource "aws_security_group" "vpc_link" {
name = "apigw-vpc-link"
vpc_id = var.vpc_id
egress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["10.0.0.0/16"]
}
}
resource "aws_apigatewayv2_api" "this" {
name = "orders-api"
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_vpc_link" "eks" {
name = "eks-link"
subnet_ids = var.private_subnet_ids
security_group_ids = [aws_security_group.vpc_link.id]
}
resource "aws_apigatewayv2_integration" "eks" {
api_id = aws_apigatewayv2_api.this.id
integration_type = "HTTP_PROXY"
integration_method = "ANY"
connection_type = "VPC_LINK"
connection_id = aws_apigatewayv2_vpc_link.eks.id
integration_uri = var.alb_listener_arn
payload_format_version = "1.0"
tls_config {
server_name_to_verify = "orders.internal.example.com"
}
}
resource "aws_apigatewayv2_authorizer" "cognito" {
api_id = aws_apigatewayv2_api.this.id
name = "cognito"
authorizer_type = "JWT"
identity_sources = ["$request.header.Authorization"]
jwt_configuration {
issuer = var.cognito_issuer
audience = [var.cognito_client_id]
}
}
resource "aws_apigatewayv2_route" "orders" {
api_id = aws_apigatewayv2_api.this.id
route_key = "ANY /orders/{proxy+}"
target = "integrations/${aws_apigatewayv2_integration.eks.id}"
authorization_type = "JWT"
authorizer_id = aws_apigatewayv2_authorizer.cognito.id
authorization_scopes = ["openid"]
}
resource "aws_apigatewayv2_route" "health" {
api_id = aws_apigatewayv2_api.this.id
route_key = "GET /health"
target = "integrations/${aws_apigatewayv2_integration.eks.id}"
}
resource "aws_cloudwatch_log_group" "apigw" {
name = "/aws/apigateway/orders-api"
retention_in_days = 30
}
resource "aws_apigatewayv2_stage" "default" {
api_id = aws_apigatewayv2_api.this.id
name = "$default"
auto_deploy = true
default_route_settings {
throttling_burst_limit = 100
throttling_rate_limit = 200
}
route_settings {
route_key = "ANY /orders/{proxy+}"
throttling_burst_limit = 50
throttling_rate_limit = 100
}
access_log_settings {
destination_arn = aws_cloudwatch_log_group.apigw.arn
format = jsonencode({
requestId = "$context.requestId"
ip = "$context.identity.sourceIp"
route = "$context.routeKey"
status = "$context.status"
latency = "$context.integrationLatency"
sub = "$context.authorizer.claims.sub"
authError = "$context.authorizer.error"
})
}
}
resource "aws_apigatewayv2_domain_name" "api" {
domain_name = "api.example.com"
domain_name_configuration {
certificate_arn = var.certificate_arn
endpoint_type = "REGIONAL"
security_policy = "TLS_1_2"
}
}
resource "aws_apigatewayv2_api_mapping" "api" {
api_id = aws_apigatewayv2_api.this.id
domain_name = aws_apigatewayv2_domain_name.api.id
stage = aws_apigatewayv2_stage.default.id
}
The AWS CLI equivalent
The commands and flags were checked with aws apigatewayv2 <command> help.
API_ID=$(aws apigatewayv2 create-api --name orders-api --protocol-type HTTP \
--query ApiId --output text)
VPCLINK_ID=$(aws apigatewayv2 create-vpc-link --name eks-link \
--subnet-ids subnet-aaa subnet-bbb --security-group-ids sg-123 \
--query VpcLinkId --output text)
INTEG_ID=$(aws apigatewayv2 create-integration --api-id "$API_ID" \
--integration-type HTTP_PROXY --integration-method ANY \
--connection-type VPC_LINK --connection-id "$VPCLINK_ID" \
--integration-uri "$ALB_LISTENER_ARN" --payload-format-version 1.0 \
--tls-config ServerNameToVerify=orders.internal.example.com \
--query IntegrationId --output text)
AUTH_ID=$(aws apigatewayv2 create-authorizer --api-id "$API_ID" --name cognito \
--authorizer-type JWT --identity-source '$request.header.Authorization' \
--jwt-configuration "Audience=$CLIENT_ID,Issuer=https://cognito-idp.us-east-1.amazonaws.com/$POOL_ID" \
--query AuthorizerId --output text)
aws apigatewayv2 create-route --api-id "$API_ID" --route-key 'ANY /orders/{proxy+}' \
--target "integrations/$INTEG_ID" --authorization-type JWT --authorizer-id "$AUTH_ID"
aws apigatewayv2 create-route --api-id "$API_ID" --route-key 'GET /health' \
--target "integrations/$INTEG_ID"
FMT='{"requestId":"$context.requestId","status":"$context.status","route":"$context.routeKey"}'
aws apigatewayv2 create-stage --api-id "$API_ID" --stage-name '$default' --auto-deploy \
--default-route-settings ThrottlingBurstLimit=100,ThrottlingRateLimit=200 \
--access-log-settings "$(jq -nc --arg d "$LOG_GROUP_ARN" --arg f "$FMT" '{DestinationArn:$d,Format:$f}')"
JWT authorizer with Cognito
The authorizer reads the Authorization header, validates the signature, expiration, issuer, and audience, and only then calls the integration. The values come from the user pool you created in how to configure AWS Cognito:
- Issuer:
https://cognito-idp.<region>.amazonaws.com/<userPoolId>. - Audience: the app client ID. Cognito access tokens have no
aud, so API Gateway checks theclient_idclaim. - Scopes:
authorization_scopeson the route requires the token to carry at least one of the listed scopes. Scopes only exist in the access token, so send the access token, not the ID token.
The validated claims are available as $context.authorizer.claims.*, for example to write the sub into the access log. The backend on EKS receives a request that is already authenticated; if it also needs the groups, it can read the token forwarded in the header.
Stages, throttling, and usage plans
On an HTTP API, the $default stage with auto_deploy publishes every change automatically and is served at the root of the URL. Named stages (dev, prod) become part of the path.
Limits are evaluated in layers. Exceed any of them and the client gets a 429.
| Layer | REST API | HTTP API |
|---|---|---|
| Account, per Region | Yes (default of 10,000 RPS with a 5,000 burst; lower in some newer Regions) | Yes (same account limit) |
| Stage or method/route | Yes | Yes (default_route_settings and route_settings) |
| Per client (usage plan + API key) | Yes | No |
They apply in this order: usage plan, then stage/method, then account. Account limits can change, so check the current docs.
To meter or limit per client, only the REST API will do, with API keys and usage plans. Keep in mind that an API key identifies the client for quota purposes; it is not an authentication mechanism. Pair it with an authorizer.
KEY_ID=$(aws apigateway create-api-key --name client-a --enabled --query id --output text)
PLAN_ID=$(aws apigateway create-usage-plan --name basic \
--throttle burstLimit=20,rateLimit=10 \
--quota limit=100000,period=MONTH \
--api-stages apiId="$REST_API_ID",stage=prod \
--query id --output text)
aws apigateway create-usage-plan-key --usage-plan-id "$PLAN_ID" \
--key-id "$KEY_ID" --key-type API_KEY
Custom domain and access logs
The custom domain (aws_apigatewayv2_domain_name + aws_apigatewayv2_api_mapping) uses an ACM certificate in the same Region for REGIONAL endpoints. Then create a DNS record pointing at the domain’s target_domain_name. Once the domain is live, consider disable_execute_api_endpoint = true on the API so nobody bypasses the domain through the default execute-api URL.
Access logs go to a CloudWatch log group in the format you define. The format must include at least $context.requestId. Adding $context.authorizer.error helps a lot when debugging 401s and 403s. Set a retention period on the log group, or the logs are kept forever.
Testing with curl and a Bearer token
Get an access token through the Cognito sign-in (code flow with PKCE). For tests against a development pool, an app client with ALLOW_USER_PASSWORD_AUTH and a user without MFA let you fetch the token from the CLI. Never enable that in production.
TOKEN=$(aws cognito-idp initiate-auth --client-id "$TEST_CLIENT_ID" \
--auth-flow USER_PASSWORD_AUTH \
--auth-parameters [email protected],PASSWORD="$TEST_PASSWORD" \
--query 'AuthenticationResult.AccessToken' --output text)
curl -i https://api.example.com/health # public route: 200
curl -i https://api.example.com/orders/123 # no token: 401
curl -i -H "Authorization: Bearer $TOKEN" \
https://api.example.com/orders/123 # valid token: the pod's response
If you get a 401 with a token, check the issuer and audience; a 403 usually means a missing scope. A 503 or 504 means the problem sits between the VPC link and the ALB: security groups, the listener ARN, the name in tls_config, or pods failing health checks. These commands were not run in the lab, which has no AWS account.
Checklist
- HTTP API, unless you need REST-only features
- Internal ALB or NLB created by the AWS Load Balancer Controller
- VPC link V2 with security groups that only open the path to the ALB
- JWT authorizer with the Cognito issuer and client ID on every private route
- Throttling per stage and per route (plus usage plans on REST if you have external clients)
- Custom domain,
execute-apiendpoint disabled, and TLS 1.2 - Access logs with
requestId,status, and the authorizer error, with retention set
API Gateway is the cluster’s doorman: let it handle authentication and limits, and keep EKS off the internet.