Lesson 4 of 4 AWS WAF, AWS Shield and Amazon CloudFront

Layering Controls on Amazon API Gateway Endpoints

This lesson explains the layered controls of Amazon API Gateway, who can call, from where, how often and with what credentials, and which API type supports which control.

Learning outcomes

After completing this lesson, you will be able to:

  • Combine resource policies, authorizers, mutual TLS and throttling.
  • Identify which controls each API type supports.
  • Explain how back-end services are protected from direct access and malformed requests.

Controls by layer

API Gateway offers several layers of control, and not every control is available for every API type. Two controls decide where calls may come from. Resource policies allow or deny calls by account, IP range, VPC or VPC endpoint, and private APIs can be reached only through interface VPC endpoints; both apply to REST APIs. Several authorisation options decide who may call. IAM authorisation requires requests signed with AWS credentials (SigV4) and works with all API types. Cognito user pool authorizers on REST APIs, and JWT authorizers on HTTP APIs, accept tokens issued to signed-in end users. Lambda authorizers run custom logic and cache the result.

Mutual TLS on custom domains requires clients to present certificates trusted by a trust store in S3. AWS WAF filters requests and applies rate limits at layer 7. It attaches directly to REST APIs and protects other types through CloudFront. Throttling limits request rates on every stage, and usage plans enforce per-client quotas on REST APIs. The following table summarises the controls.

ControlPurposeAPI types
Resource policiesAllow or deny by account, IP range, VPC or VPC endpointREST
Private APIsReachable only through interface VPC endpointsREST
IAM (SigV4) authorisationAWS principals call with signed requestsREST, HTTP, WebSocket
Cognito user pool authorizersEnd users with Cognito tokensREST
JWT authorizersTokens from any OIDC providerHTTP
Lambda authorizersCustom token or request logic, with result cachingREST, HTTP, WebSocket
Mutual TLSClients present certificates from a trust store in S3REST, HTTP (custom domains)
AWS WAFLayer 7 filtering and rate limitingREST (and through CloudFront for others)
Throttling and usage plansLimit abuse and enforce per-client quotasREST (usage plans), all (stage throttling)

The following diagram shows the three controls a request from a partner passes on its way to a private API.

Three controls on a partner API, each against a different threat. The resource policy denies calls from outside 198.51.100.0/24; the custom domain requires mutual TLS with certificates from the company's private CA; and the default execute-api endpoint is disabled so neither control can be bypassed.
The scenario is illustrative.
Sort into groups

Who, where or how often?

Exam skills 3.1.2 · 4.2.1

Classify each API Gateway control by what it limits.

Log in to try this activity Interactive activities are free with an account.

Protecting the back end

The services behind an API must be protected from direct access and malformed requests. The following list describes the relevant measures.

  • Back-end services should accept traffic only from API Gateway: a private integration through VPC Link, a Lambda resource policy naming the API's ARN, or a client certificate that API Gateway presents to an HTTP back end.
  • Disable the default execute-api endpoint when a custom domain with mutual TLS is used, so clients cannot bypass certificate checks.
  • Request validation rejects malformed input before it reaches code.
  • Access logs (with identity, IP and authorizer results) and execution logs go to CloudWatch Logs; avoid logging full request bodies containing personal data.
Select all that apply

Protecting what sits behind the API

Exam skills 3.1.2

Pick the measures that protect the back end of an API Gateway API.

Log in to try this activity Interactive activities are free with an account.
Worked example

An API restricted to a partner's network and certificate

A partner integration must be callable only from the partner's published IP range, only with a client certificate issued by the company's private CA, and never through the default endpoint. A resource policy handles the network restriction:

{
  "Version": "2012-10-17",
  "Statement": [
    { "Effect": "Allow", "Principal": "*", "Action": "execute-api:Invoke", "Resource": "execute-api:/*" },
    { "Effect": "Deny", "Principal": "*", "Action": "execute-api:Invoke", "Resource": "execute-api:/*",
      "Condition": { "NotIpAddress": { "aws:SourceIp": ["198.51.100.0/24"] } } }
  ]
}
aws apigateway create-domain-name --domain-name partners.api.example.com \
  --regional-certificate-arn $ACM_CERT_ARN --endpoint-configuration types=REGIONAL \
  --security-policy TLS_1_2 \
  --mutual-tls-authentication truststoreUri=s3://acme-truststores/partners.pem
aws apigateway update-rest-api --rest-api-id $API_ID \
  --patch-operations op=replace,path=/disableExecuteApiEndpoint,value=true

Each control covers a different threat: the IP condition stops unknown networks, mutual TLS proves the caller holds a valid certificate, and disabling the default endpoint prevents both being bypassed. A WAF web ACL adds rate limiting and managed rules for the request content.

Check yourself

Which REST API type is not reachable from the internet?

Show answer

A private REST API, reached through an interface VPC endpoint.

Exam Tips

Remember for the exam

  • To allow API calls only from certain IP ranges or VPC endpoints, use an API Gateway resource policy.
  • For APIs that must not be reachable from the internet, use private REST APIs.
  • For client certificate authentication, configure mutual TLS on a custom domain and disable the default endpoint.
  • HTTP APIs use JWT authorizers; REST APIs support Cognito authorizers, usage plans and WAF directly.
  • To make a Lambda back end callable only by one API, use a Lambda resource policy with the API's source ARN.