How to securely hide an API key when calling a third-party HTTP API from a browser SPA?
A company is developing a publicly accessible single-page application. The application makes calls from a client web browser to backend services to provide a user interface to customers. The application depends on a third-party web service exposed as an HTTP API. The web client must provide an API key to the third-party web service by using the HTTP header as part of the HTTP request. The company's API key must not be exposed to the users of the web application. Which solution will meet these requirements MOST cost-effectively?
Community Votes
66% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
This question tests whether candidates know that API Gateway HTTP integrations can inject static headers server-side, eliminating the need for a Lambda function and keeping costs low while protecting secrets from the browser.
To hide a third-party API key from a public single-page application, use Amazon API Gateway REST API with an HTTP integration that injects the key in the integration request headers. This is the most cost-effective approach because it avoids the compute cost of an AWS Lambda proxy.
Many candidates choose option D (Lambda proxy integration) because it is a familiar pattern for calling external APIs, but it adds unnecessary Lambda invocation cost and complexity compared to a direct HTTP integration.
Community Discussion (7 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
The scenario describes a public SPA that must call a third-party HTTP API using a secret API key. Because the browser is untrusted, the key cannot be embedded in the client code or sent directly from the browser. A server-side component must inject the key before the request leaves AWS.
Option C is correct. A public Amazon API Gateway REST API with an HTTP integration can forward the browser's request directly to the third-party endpoint. In the integration request mapping template, the company's API key is added as a static HTTP header. The key is stored only in the API Gateway configuration, never reaching the client. Because there is no Lambda function, you pay only for API Gateway requests, making this the most cost-effective solution.
Option A is incorrect because a private REST API requires a VPC endpoint (AWS PrivateLink) to be reachable, which adds significant cost and is unnecessary for a public-facing SPA.
Option B is incorrect for the same reason as A (private API + VPC endpoint) and also adds Lambda cost.
Option D works functionally but is not the most cost-effective. A Lambda proxy integration introduces a Lambda invocation for every request, increasing both cost and latency compared to the native HTTP integration mapping available in API Gateway.
Community members correctly note that the private API options (A and B) imply a VPC endpoint, which is not cost-effective, and that Lambda adds unnecessary overhead compared to API Gateway's built-in header mapping.
Official Reference
Exam Strategy
When a question asks for the MOST cost-effective serverless solution, always compare native AWS integrations (such as API Gateway HTTP integrations) against Lambda-based solutions first. Native integrations usually win on cost and latency unless custom logic is required.
Related Analysis
Practice All DVA-C02 Questions
Access 100 questions with complete answers and detailed explanations.
View Full DVA-C02 Practice Test →