Bird
Raised Fist0
AWScloud~20 mins

Lambda with API Gateway pattern in AWS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Lambda API Gateway Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Architecture
intermediate
2:00remaining
Identify the correct architecture for Lambda with API Gateway

Which architecture diagram correctly represents the flow when using AWS Lambda with API Gateway to handle HTTP requests?

AClient sends HTTP request → API Gateway receives request → API Gateway stores request in S3 → Lambda polls S3 for requests → Lambda processes and writes response to DynamoDB → Client reads response from DynamoDB
BClient sends HTTP request → Lambda function receives request directly → Lambda processes and sends response to API Gateway → API Gateway forwards response to client
CClient sends HTTP request → API Gateway receives request → API Gateway triggers Lambda function → Lambda processes and returns response → API Gateway sends response back to client
DClient sends HTTP request → API Gateway receives request → API Gateway triggers EC2 instance → EC2 instance processes request and sends response back to API Gateway → API Gateway sends response to client
Attempts:
2 left
💡 Hint

Think about which component directly triggers the Lambda function in a typical serverless HTTP request flow.

❓ scaling
intermediate
2:00remaining
Scaling considerations for Lambda with API Gateway

When your API Gateway triggers Lambda functions under heavy load, which of the following is a correct statement about scaling?

AAPI Gateway scales automatically, but Lambda functions require manual scaling configuration
BBoth API Gateway and Lambda require manual scaling to handle increased traffic
CNeither API Gateway nor Lambda can scale beyond 100 concurrent requests
DLambda functions scale automatically with incoming requests, but API Gateway has a fixed limit and can throttle requests if exceeded
Attempts:
2 left
💡 Hint

Consider which AWS service is serverless and automatically scales, and which has limits that can cause throttling.

❓ tradeoff
advanced
2:00remaining
Tradeoff between synchronous and asynchronous invocation in Lambda with API Gateway

What is a key tradeoff when choosing synchronous invocation of Lambda via API Gateway versus asynchronous invocation?

ASynchronous invocation does not support retries; asynchronous invocation supports automatic retries and error handling
BSynchronous invocation reduces latency and provides immediate response; asynchronous invocation increases latency and provides immediate response
CSynchronous invocation provides immediate response but can increase latency; asynchronous invocation reduces latency but does not provide immediate response
DSynchronous invocation is cheaper than asynchronous invocation in all cases
Attempts:
2 left
💡 Hint

Think about how retries and error handling differ between synchronous and asynchronous Lambda calls.

🧠 Conceptual
advanced
2:00remaining
Understanding cold start impact in Lambda with API Gateway

Which statement best describes the impact of cold starts on user experience when using Lambda with API Gateway?

ACold starts improve Lambda function performance by preloading dependencies before invocation
BCold starts cause a delay in Lambda function execution, increasing API response time, especially for infrequently used functions
CCold starts only occur when Lambda functions are invoked asynchronously, not via API Gateway
DCold starts have no impact on API Gateway latency because API Gateway caches all responses
Attempts:
2 left
💡 Hint

Consider what happens when a Lambda function is invoked after being idle for some time.

❓ estimation
expert
2:00remaining
Estimating maximum requests per second for Lambda with API Gateway

Your API Gateway is configured with a default regional endpoint and triggers a Lambda function. The Lambda function has a concurrency limit of 1000. API Gateway has a soft limit of 10,000 requests per second (RPS). What is the maximum sustained RPS your system can handle without throttling?

ACannot determine without knowing Lambda function execution duration
B10,000 RPS, limited by API Gateway soft limit
C11,000 RPS, sum of Lambda concurrency and API Gateway limit
D1000 RPS, limited by Lambda concurrency
Attempts:
2 left
💡 Hint

Lambda concurrency limits concurrent executions, but sustained RPS = concurrency / average execution duration in seconds. Without duration, cannot determine the bottleneck.

Practice

(1/5)
1. What is the primary role of AWS API Gateway when used with Lambda in a serverless architecture?
easy
A. To receive HTTP requests and trigger Lambda functions
B. To store data permanently
C. To run long-running background tasks
D. To manage virtual machines

Solution

  1. Step 1: Understand API Gateway's function

    API Gateway acts as a front door to accept and process HTTP requests from clients.
  2. Step 2: Connect API Gateway to Lambda

    API Gateway triggers Lambda functions to execute backend logic upon receiving requests.
  3. Final Answer:

    To receive HTTP requests and trigger Lambda functions -> Option A
  4. Quick Check:

    API Gateway triggers Lambda = A [OK]
Hint: API Gateway handles HTTP, Lambda runs code [OK]
Common Mistakes:
  • Confusing API Gateway with data storage
  • Thinking Lambda manages servers
  • Assuming API Gateway runs background tasks
2. Which of the following is the correct way to configure an API Gateway method to trigger a Lambda function?
easy
A. Set the integration type to HTTP and specify the Lambda URL
B. Set the integration type to VPC Link and attach Lambda
C. Set the integration type to Lambda Function and select the function ARN
D. Set the integration type to MOCK and provide Lambda code inline

Solution

  1. Step 1: Identify correct integration type

    API Gateway uses 'Lambda Function' integration to directly invoke Lambda functions.
  2. Step 2: Specify Lambda function ARN

    You must provide the ARN (Amazon Resource Name) of the Lambda function to link it properly.
  3. Final Answer:

    Set the integration type to Lambda Function and select the function ARN -> Option C
  4. Quick Check:

    Integration type Lambda Function + ARN = D [OK]
Hint: Use 'Lambda Function' integration with ARN [OK]
Common Mistakes:
  • Using HTTP integration instead of Lambda Function
  • Confusing MOCK integration with Lambda
  • Incorrectly using VPC Link for Lambda
3. Consider this AWS Lambda function triggered by API Gateway:
exports.handler = async (event) => {
  return { statusCode: 200, body: JSON.stringify({ message: event.queryStringParameters.name }) };
};
What will be the response body if the API Gateway is called with URL ?name=Alice?
medium
A. {"message":"Alice"}
B. {"message":null}
C. {"message":"name"}
D. Error: event.queryStringParameters undefined

Solution

  1. Step 1: Understand event object from API Gateway

    API Gateway passes query parameters inside event.queryStringParameters, so event.queryStringParameters.name equals 'Alice'.
  2. Step 2: Check Lambda return value

    Lambda returns JSON string with message key set to 'Alice', so response body is '{"message":"Alice"}'.
  3. Final Answer:

    {"message":"Alice"} -> Option A
  4. Quick Check:

    Query param 'name=Alice' -> message = 'Alice' [OK]
Hint: Query params in event.queryStringParameters [OK]
Common Mistakes:
  • Assuming queryStringParameters is null
  • Returning raw object instead of JSON string
  • Confusing parameter name with literal string
4. You deployed an API Gateway with Lambda integration but receive a 502 Bad Gateway error when calling the API. What is the most likely cause?
medium
A. API Gateway endpoint URL is incorrect
B. Lambda function is not returning a properly formatted response
C. Lambda function has no execution role assigned
D. API Gateway method is set to MOCK integration

Solution

  1. Step 1: Understand 502 Bad Gateway meaning

    502 error usually means API Gateway received an invalid response from Lambda.
  2. Step 2: Check Lambda response format

    Lambda must return an object with statusCode and body as string; missing or malformed response causes 502.
  3. Final Answer:

    Lambda function is not returning a properly formatted response -> Option B
  4. Quick Check:

    502 error = bad Lambda response format [OK]
Hint: 502 means Lambda response format error [OK]
Common Mistakes:
  • Assuming wrong API Gateway URL causes 502
  • Ignoring Lambda execution role issues (causes 403)
  • Confusing MOCK integration with Lambda integration
5. You want to design a serverless API using API Gateway and Lambda that handles high traffic with unpredictable spikes. Which design choice best ensures scalability and cost efficiency?
hard
A. Use API Gateway with Lambda proxy integration and enable Lambda reserved concurrency
B. Use API Gateway with HTTP integration to EC2 instances behind an autoscaling group
C. Use API Gateway with MOCK integration and pre-warm Lambda functions manually
D. Use API Gateway with Lambda proxy integration and rely on Lambda's default scaling without reserved concurrency

Solution

  1. Step 1: Understand Lambda scaling behavior

    Lambda scales automatically with incoming requests without needing reserved concurrency unless limiting concurrency is required.
  2. Step 2: Evaluate cost and scalability

    Relying on default Lambda scaling avoids paying for reserved concurrency and handles unpredictable spikes efficiently.
  3. Step 3: Compare other options

    EC2 autoscaling adds server management and cost; MOCK integration doesn't run real code; reserved concurrency limits scaling.
  4. Final Answer:

    Use API Gateway with Lambda proxy integration and rely on Lambda's default scaling without reserved concurrency -> Option D
  5. Quick Check:

    Default Lambda scaling + proxy integration = C [OK]
Hint: Default Lambda scaling handles spikes best [OK]
Common Mistakes:
  • Setting reserved concurrency unnecessarily limits scaling
  • Using EC2 adds complexity and cost
  • Using MOCK integration doesn't run Lambda code
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard