AWS API Gateway
Q1: Can you explain the difference between AWS API Gateway REST API and HTTP API, and when you would choose one over the other?
Ans: REST APIs provide advanced features like usage plans, API keys, request validation, and fine-grained throttling. HTTP APIs are lightweight, cheaper, and faster but with fewer features. In interviews, emphasize REST APIs for complex enterprise workloads and HTTP APIs for cost-effective microservices or simple Lambda/HTTP proxy integrations.
Q2: How would you secure an API Gateway endpoint in a production environment?
Ans: Security options include IAM authorization (for internal AWS services), Cognito User Pools (for user authentication), and Lambda authorizers (for custom logic). In production, combining Cognito with resource policies is common to ensure both authentication and fine-grained access control.
Q3: What role do usage plans and API keys play in API Gateway?
Ans: Usage plans define throttling and quota limits, while API keys map clients to those plans. In production, misconfigured limits can cause denial of service or unexpected cost spikes. Monitoring usage metrics is critical to balance performance and cost.
Q4: How do you troubleshoot 502 Bad Gateway errors in API Gateway?
Ans: 502 errors typically occur when the backend (Lambda, HTTP service) fails or returns an invalid response. Troubleshooting involves checking CloudWatch logs, validating integration response templates, and ensuring backend timeouts align with API Gateway limits.
Q5: What strategies would you apply to reduce latency in API Gateway?
Ans: Enable stage-level caching, use regional endpoints for localized traffic, minimize request/response transformations, and optimize backend services. Monitoring latency metrics in CloudWatch helps identify bottlenecks and guide tuning.
Q6: How do you configure custom error responses in API Gateway?
Ans: Gateway Responses allow customization of error payloads for codes like 403 or 429. Mapping templates can format responses to be client-friendly. In production, this improves user experience and debugging by providing meaningful error messages.
Q7: What is the purpose of stages and stage variables in API Gateway?
Ans: Stages represent environments (dev, test, prod). Stage variables allow dynamic configuration, such as pointing to different Lambda functions or endpoints without redeployment. This supports environment isolation and flexible configuration management.
Q8: How do you monitor API Gateway performance and detect issues?
Ans: Enable CloudWatch metrics for latency, 4XX/5XX errors, and integration latency. Use AWS X-Ray for request tracing. In production, dashboards and alarms help detect anomalies early and trigger automated remediation.
Q9: What are common production issues with private APIs in API Gateway?
Ans: Private APIs require VPC endpoints. Issues often stem from misconfigured security groups, NACLs blocking traffic, or missing endpoint policies. Troubleshooting involves verifying VPC endpoint connectivity and IAM permissions.
Q10: How can you optimize API Gateway costs in high-traffic environments?
Ans: Use HTTP APIs instead of REST APIs when advanced features arenβt required, enable caching to reduce backend calls, and consolidate endpoints to minimize request volume. Monitoring usage and applying throttling policies prevents runaway costs.