0Pricing
AWS Solutions Architect · Lesson

Integrations: Lambda, HTTP, and Mock

Wire API Gateway methods to Lambda proxy integrations, upstream HTTP endpoints, and mock integrations for testing.

Integrations: Lambda, HTTP, and Mock is a free AWS Solutions Architect lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

API Gateway Integration Types Overview

Every API Gateway method needs a backend integration—the system that processes the request and returns a response. API Gateway supports five integration types: Lambda Proxy, Lambda Custom, HTTP Proxy, HTTP Custom, and Mock. HTTP APIs support only Lambda Proxy and HTTP Proxy. REST APIs support all five. Choosing the right integration determines how much control you have over the request and response transformation.

Lambda Proxy Integration

With Lambda Proxy integration, API Gateway passes the entire HTTP request to Lambda as a structured event object including headers, query strings, path parameters, body, and context. Your Lambda function is responsible for returning a properly formatted response object with statusCode, headers, and body. This is the simplest and most common pattern—no mapping templates needed, and your Lambda controls the full response.

def lambda_handler(event, context):
    # event.httpMethod, event.path, event.queryStringParameters
    # event.headers, event.body
    user_id = event['pathParameters']['userId']
    return {
        'statusCode': 200,
        'headers': {'Content-Type': 'application/json'},
        'body': '{"userId": "' + user_id + '", "name": "Alice"}'
    }

Lambda Non-Proxy (Custom) Integration

With Lambda Non-Proxy (custom integration), API Gateway uses mapping templates (Apache Velocity Template Language, VTL) to transform the request before sending it to Lambda, and transforms Lambda's response before returning it to the client. Your Lambda function receives a clean, custom payload—not the raw API Gateway event. This separates transport concerns from business logic, but requires maintaining VTL templates. Use custom integration when you want strict API-to-backend contract separation.

## Integration Request Mapping Template (VTL)
#set($inputRoot = $input.path('$'))
{
  'userId': '$input.params('userId')',
  'action': '$inputRoot.action',
  'timestamp': '$context.requestTime'
}

HTTP Proxy Integration

HTTP Proxy integration forwards requests directly to an external HTTP endpoint (could be an EC2 instance, ALB, on-premises server, or any public URL) without transformation. API Gateway passes the request through and returns the backend's response to the client. This is ideal for migrating existing REST backends behind API Gateway to add throttling, monitoring, and API keys without changing the backend code. Supports HTTPS backends with certificate verification.

# Create HTTP proxy integration via REST API
aws apigateway put-integration \
  --rest-api-id 'abc123' \
  --resource-id 'xyz789' \
  --http-method GET \
  --type HTTP_PROXY \
  --integration-http-method GET \
  --uri 'https://my-backend.example.com/api/users/{userId}'

HTTP Custom (Non-Proxy) Integration

HTTP Custom integration also forwards to an external HTTP endpoint, but uses mapping templates to transform both the request going to the backend and the response coming back. This is useful when the API Gateway interface and the backend API have different contracts—you can translate a REST API call into a legacy SOAP or custom format, and transform the backend response back to a clean JSON structure for the client. This adds complexity but provides the most control for legacy integrations.

AWS Service Integration

AWS Service integration connects API Gateway directly to AWS services without a Lambda intermediary. For example, you can configure a POST endpoint that directly writes a message to SQS, publishes to SNS, or starts a Step Functions execution. This reduces latency and eliminates Lambda function costs for simple routing operations. The integration requires IAM role configuration and mapping templates to format the AWS API call correctly.

# Direct API Gateway → SQS integration
# Integration Request URI:
https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue

# Integration Request Body Mapping Template:
Action=SendMessage&MessageBody=$input.body

Mock Integration for Development and Testing

Mock integration configures API Gateway to return a predefined response without calling any backend. You define the response in the integration response mapping template. Mock integrations are perfect for: API development before the backend is built (frontend teams can start immediately), unit testing API configurations, returning standard CORS headers, or providing a stub for third-party partners during development. Mock endpoints can also be used to block deprecated API versions by returning 410 Gone.

# Integration Response for Mock
# Integration Response Mapping Template:
{
  'statusCode': 200,
  'message': 'This is a mock response',
  'timestamp': '$context.requestTime'
}

# Method Response: map status code 200 to this template

CORS Configuration in API Gateway

CORS (Cross-Origin Resource Sharing) must be enabled when a browser client on one domain calls your API on another domain. HTTP API has one-click CORS configuration; REST API requires you to create an OPTIONS method with a Mock integration that returns the required CORS headers (Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers). Lambda proxy integration also requires your Lambda to return CORS headers in its response.

# HTTP API CORS config (simple)
aws apigatewayv2 update-api \
  --api-id 'abc123' \
  --cors-configuration '{
    "AllowOrigins": ["https://myapp.example.com"],
    "AllowMethods": ["GET", "POST", "OPTIONS"],
    "AllowHeaders": ["Content-Type", "Authorization"]
  }'

Request Validation in REST API

REST API supports request validation: API Gateway can validate that required query string parameters, headers, and request body schema are present and correctly formatted—before invoking the backend. This reduces unnecessary Lambda invocations from malformed requests and returns standardised 400 errors automatically. Define a request model using JSON Schema and attach it to the method to enable body validation. Request validation is not available in HTTP API.

Integration Timeouts

API Gateway has a default integration timeout of 29 seconds for REST API and HTTP API (maximum for REST API, fixed for HTTP API proxy). If your backend takes longer than 29 seconds, API Gateway returns a 504 Gateway Timeout error. This means Lambda functions invoked synchronously through API Gateway must complete within 29 seconds—even though Lambda itself supports 15-minute timeouts. For long-running operations, use an asynchronous pattern: API Gateway triggers Lambda which starts an async job and returns a job ID immediately.

Choosing the Right Integration Type

Decision guide for integration types: Lambda Proxy: most common, simplest, full request control in Lambda; Lambda Custom: when you need request/response transformation in the gateway layer; HTTP Proxy: for existing HTTP backends, migration scenarios; HTTP Custom: for legacy API format translation; AWS Service: to eliminate Lambda for simple routing to SQS/SNS/DynamoDB; Mock: for development stubs and CORS preflight. For the SAA-C03 exam, Lambda Proxy and HTTP Proxy are the most commonly tested patterns.

Quick Check

Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.

Lesson Recap

In this lesson you learned: Lambda Proxy integration passes the full request to Lambda which controls the response—the simplest and most common integration, HTTP Proxy forwards requests to existing HTTP backends to add API Gateway features without changing the backend, and Mock integration returns predefined responses for frontend development and testing without any backend infrastructure. Next up we explore API Gateway authorisation with IAM, Lambda authorisers, and Cognito.

Frequently asked questions

Is the “Integrations: Lambda, HTTP, and Mock” lesson free?

Yes — the full text of “Integrations: Lambda, HTTP, and Mock” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.

What will I learn in “Integrations: Lambda, HTTP, and Mock”?

Wire API Gateway methods to Lambda proxy integrations, upstream HTTP endpoints, and mock integrations for testing. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Solutions Architect?

No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Integrations: Lambda, HTTP, and Mock” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Solutions Architect lesson?

Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. REST API vs HTTP API vs WebSocket API
  2. Integrations: Lambda, HTTP, and Mock
  3. Authorization: IAM, Lambda Authorizers, and Cognito
  4. Throttling, Caching, and Usage Plans
← Back to AWS Solutions Architect