We use machine learning technology to do auto-translation. Click "English" on top navigation bar to check Chinese version.
Architecture patterns for consuming private APIs cross-account
This blog written by Thomas Moore, Senior Solutions Architect and Josh Hart, Senior Solutions Architect.
In microservice architectures, where multiple teams build and manage components, different Amazon Web Services accounts often consume private API endpoints.
This blog post shows how a service can consume a private API Gateway endpoint that is published in another Amazon Web Services account securely over

Consuming API Gateway private endpoint cross-account via Amazon Web Services PrivateLink.
This blog covers consuming API Gateway endpoints cross-account. For exposing cross-account resources behind an API Gateway, read
Overview
To access API Gateway private endpoints, you must create an interface VPC endpoint (named execute-api) inside your VPC. This creates an Amazon Web Services PrivateLink connection between your Amazon Web Services account VPC and the API Gateway service VPC. The PrivateLink connection allows traffic to flow over private IP address space without traversing the internet.
PrivateLink allows access to private API Gateway endpoints in different Amazon Web Services accounts, without VPC peering, VPN connections, or
The following diagram shows how interface VPC endpoints in a consumer account create a PrivateLink connection back to the API Gateway service account VPC. The resource policy applied to the private API determines which VPC endpoint can access the API. For this reason, it is critical to ensure that the resource policy is correct to prevent unintentional access from other Amazon Web Services account VPC endpoints.

Access to private API Gateway endpoints requires an Amazon Web Services PrivateLink connection to an Amazon Web Services service account VPC.
In this example, the resource policy denies all connections to the private API endpoint unless the aws:SourceVpce condition matches vpce-1a2b3c4d in account A. This means that connections from other execute-api VPC endpoints are denied. To allow access from account B, add vpce-9z8y7x6w to the resource policy. Refer to the
For more detail on how VPC links work, read
The following sections cover three architecture patterns to consume API Gateway private endpoints cross-account:
- Regional API Gateway to private API Gateway
- Lambda function calling API Gateway in another account
- Container microservice calling API Gateway in another account using mTLS
Regional API Gateway to private API Gateway cross-account
When building microservices in different Amazon Web Services accounts, private API Gateway endpoints are often used to allow service-to-service communication. Sometimes a portion of these endpoints must be exposed publicly for end user consumption. One pattern for this is to have a central public API Gateway, which acts as the front-door to multiple private API Gateway endpoints. This allows for central governance of authentication, logging and monitoring.
The following diagram shows how to achieve this using a VPC link. VPC links enable you to connect API Gateway integrations to private resources inside a VPC. The API Gateway VPC interface endpoint is the VPC resource that you want to connect to, as this is routing traffic to the private API Gateway endpoints in different Amazon Web Services accounts.

API Gateway Regional endpoint consuming API Gateway private endpoints cross-account
VPC link requires the use of a
You can deploy this pattern in your own account using the example
Lambda function calling private API Gateway cross-account
Another popular requirement is for
The following diagram shows how to achieve this using

Consuming API Gateway private endpoints from Lambda cross-account
Unlike the previous example, there is no NLB or VPC link required. The resource policy on the private API Gateway must allow access from the VPC endpoint in the account where the consuming Lambda function is.
As the Lambda function has a VPC attachment, it will use DNS resolution from inside the VPC. This means that if you selected the Enable Private DNS Name option when creating the interface VPC endpoint for API Gateway the https://{restapi-id}.execute-api.{region}.amazonaws.com endpoint will automatically resolve to private IP addresses. Note that this DNS configuration can block access from Regional and edge-optimized API endpoints from inside the VPC. For more information, refer to the
You can deploy this pattern in your own account using the sample CDK code found on
Calling private API Gateway cross-account with mutual TLS (mTLS)
Customers that operate in regulated industries, such as open banking, must often implement mutual TLS (mTLS) for securely accessing their APIs. It is also great for Internet of Things (IoT) applications to authenticate devices using digital certificates.

Mutual TLS (mTLS) verifies both the client and server via certificates with TLS
Regional API Gateway has
The following diagram shows how to use a combination of PrivateLink, an

Consuming API Gateway private endpoints cross-account with mTLS
In this architecture diagram,
server {
listen 443 ssl;
ssl_certificate /etc/ssl/server.crt;
ssl_certificate_key /etc/ssl/server.key;
ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
ssl_client_certificate /etc/ssl/client.crt;
ssl_verify_client on;
location / {
proxy_pass https://{api-gateway-endpoint-api};
}
}
The connecting client must supply the client certificate when connecting to the API via the VPC endpoint service:
curl --key client.key --cert client.crt --cacert server.crt https://{vpc-endpoint-service-url}
Use VPC security group rules on both the VPC endpoint and the NGINX proxy to prevent clients bypassing the mTLS endpoint and connecting directly to the API Gateway endpoint.
There is an example NGINX config and Dockerfile to configure this solution in the
Conclusion
This post explores three solutions to consume private API Gateway across Amazon Web Services accounts. A key component of all the solutions is the VPC interface endpoint. Using
For more serverless learning resources, visit
The mentioned AWS GenAI Services service names relating to generative AI are only available or previewed in the Global Regions. Amazon Web Services China promotes AWS GenAI Services relating to generative AI solely for China-to-global business purposes and/or advanced technology introduction.