SAP-C02 practice question 29 of 35

A company is using Amazon API Gateway to deploy a private REST API that will provide access to sensitive dat a. The API must be accessible only from…

Full set: 689 questions

Domain Design for New Solutions

A company is using Amazon API Gateway to deploy a private REST API that will provide access to sensitive dat a. The API must be accessible only from an application that is deployed in a VPC. The company deploys the API successfully. However, the API is not accessible from an Amazon EC2 instance that is deployed in the VPC. Which solution will provide connectivity between the EC2 instance and the API?
Answer options
A: Create an interface VPC endpoint for API Gateway. Attach an endpoint policy that allows apigateway:* actions. Disable private DNS naming for the VPC endpoint. Configure an API resource policy that allows access from the VPC. Use the VPC endpoint's DNS name to access the API.
B: Create an interface VPC endpoint for API Gateway. Attach an endpoint policy that allows the execute-api:lnvoke action. Enable private DNS naming for the VPC endpoint. Configure an API resource policy that allows access from the VPC endpoint. Use the API endpoint's DNS names to access the API. Most Voted Correct answer
C: Create a Network Load Balancer (NLB) and a VPC link. Configure private integration between API Gateway and the NLB. Use the API endpoint's DNS names to access the API.
D: Create an Application Load Balancer (ALB) and a VPC Link. Configure private integration between API Gateway and the ALB. Use the ALB endpoint's DNS name to access the API.
Correct Answer:
B. Create an interface VPC endpoint for API Gateway. Attach an endpoint policy that allows the execute-api:lnvoke action. Enable private DNS naming for the VPC endpoint. Configure an API resource policy that allows access from the VPC endpoint. Use the API endpoint's DNS names to access the API. Most Voted
Explanation

To enable an EC2 instance within a VPC to access a private API Gateway REST API, you must create an interface VPC endpoint for API Gateway (execute-api). Enabling private DNS on this endpoint is the standard practice; it allows applications to use the API's public DNS name, which will resolve to the endpoint's private IP addresses within the VPC. The API's resource policy must be updated to explicitly grant access from the source VPC or VPC endpoint. Finally, the VPC endpoint policy should grant the execute-api:Invoke permission, following the principle of least privilege to allow the API to be called through the endpoint.

Why Incorrect

A. Disabling private DNS is not the recommended approach as it requires using the endpoint-specific DNS name, complicating configuration and potentially requiring code changes. The apigateway: permission is overly permissive.
C. A VPC Link is used for the opposite traffic flow: it allows API Gateway to integrate with private backend resources (like an NLB) within a VPC, not for clients to access the API.
D. Similar to option C, a VPC Link is for private backend integrations. The scenario requires a client in a VPC to invoke the API, not for the API to invoke a backend ALB. ---

References

1. AWS API Gateway Developer Guide, "Creating a private API in Amazon API Gateway": This document outlines the required steps. It states, "To allow your API clients to access your private API through the interface endpoint, you must create a resource policy and attach it to the API." It also explains, "If you enable private DNS, you can access your private API using a private DNS name..."

2. AWS API Gateway Developer Guide, "Use VPC endpoint policies for private APIs in API Gateway": This guide specifies the permissions needed. It provides an example policy and states, "The following example policy allows access to the specified API... with the execute-api:Invoke action." This confirms the correct, least-privilege action.

3. AWS VPC User Guide, "Access an AWS service using an interface VPC endpoint": This document details the function of private DNS. Under the "Private DNS for interface endpoints" section, it explains that when enabled, "you can make requests to the service using its default DNS hostname... instead of using the VPC endpoint-specific DNS hostnames." This supports the seamless integration described in the correct answer.

Scroll to Top