INTRODUCTION
While working on a high-throughput B2B FinTech integration platform, our engineering team was tasked with implementing strict Mutual TLS (mTLS) authentication. The system architecture required a multi-level Public Key Infrastructure (PKI). At the top was our root application (the Root CA). This root issued certificates to regional secondary applications (Intermediate CAs), which in turn issued leaf certificates to our third-party merchant integrators.
During the final staging phases, we encountered a frustrating situation. Integrators holding valid leaf certificates were attempting to make mTLS calls to our AWS API Gateway but were immediately rejected with a 403 Forbidden error. The requests never even reached our downstream AWS Lambda authorizers. The API Gateway itself was dropping the connection during the TLS handshake.
This challenge highlighted a critical nuance in how managed cloud gateways handle certificate chain validation. When companies hire software developers to build zero-trust environments, understanding the idiosyncrasies of cloud-native networking components is crucial to preventing production downtime. This article details why this mTLS failure occurred and how we engineered a robust solution.
PROBLEM CONTEXT
The business use case dictated that only verified third-party integrators could interact with our core financial APIs. To achieve this, we configured an AWS API Gateway Custom Domain Name with mTLS enabled, pointing to an Amazon S3 bucket containing our truststore.pem file.
In a standard TLS handshake, the server relies on a Root CA to establish trust. The client is typically expected to pass its leaf certificate along with any intermediate certificates in a bundled chain. Following this standard logic, we initially placed only our Root CA inside the API Gateway’s truststore.
Our PKI hierarchy looked like this:
- Level 1 (Root): Core Platform CA (Placed in S3 Truststore)
- Level 2 (Intermediate): Regional Gateway CA (Signed by Root)
- Level 3 (Leaf): Integrator Client Certificate (Signed by Intermediate)
The expectation was that the API Gateway would verify the integrator’s leaf certificate against the intermediate CA provided in the client’s payload, ultimately tracing the chain back to the trusted Root CA.
WHAT WENT WRONG
When the Level 3 integrator initiated a request, API Gateway terminated the connection. The response headers contained a ForbiddenException. CloudWatch logs confirmed that the failure happened at the gateway level before any backend integration was invoked.
We initially suspected the client was failing to send the intermediate certificate. We instructed the integrator to send a full certificate bundle (Leaf Certificate + Intermediate CA). Despite this adjustment, the connection still failed.
This led to a deep dive into AWS documentation. The official guides presented a somewhat ambiguous picture. In one section, it noted that API Gateway could process certificate chains up to four levels deep. However, another section strongly implied that all intermediate CAs needed to be explicitly defined in the truststore. Because AWS API Gateway utilizes its own underlying TLS termination infrastructure (based on highly optimized and strict security protocols), it enforces rigorous validation rules. If the intermediate CA is not pre-registered in the truststore, or if the client-side bundle is ordered incorrectly—a common issue with third-party software—the gateway will aggressively reject the handshake.
HOW WE APPROACHED THE SOLUTION
To diagnose the root cause, our team mapped out the exact TLS handshake using openssl s_client to simulate the integrator’s request. We realized that relying on third-party integrators to correctly format and transmit multi-level certificate bundles was an operational risk. Even a slight misordering (e.g., placing the Intermediate before the Leaf in their client config) would cause the AWS API Gateway to drop the connection.
We decided to pivot our architecture from a “client-provided chain” model to a “server-enforced chain” model. By explicitly seeding the API Gateway’s truststore with all valid Intermediate CAs, we could offload the chain resolution responsibility from the client to the API Gateway. This is a common architectural trade-off we evaluate when clients hire aws developers for secure api architectures: balancing strict standard compliance against operational reliability for external consumers.
FINAL IMPLEMENTATION
The technical fix involved reconstructing the truststore.pem file to include both the Root CA and the Level 2 Intermediate CAs.
We created a combined PEM file. The order in the truststore file is critical; we structured it to explicitly list the certificates so the API Gateway’s internal validation logic could seamlessly traverse the chain of trust.
-----BEGIN CERTIFICATE----- (Level 2: Intermediate CA Certificate Base64) -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- (Level 1: Root CA Certificate Base64) -----END CERTIFICATE-----
Deployment and Validation Steps:
- S3 Versioning: We uploaded the new
truststore.pemto our secure S3 bucket. Because API Gateway relies on S3 object versioning to detect changes to the truststore, we ensured versioning was enabled on the bucket. - API Gateway Update: We updated the Custom Domain Name configuration in API Gateway, passing the new S3 Object Version ID.
- Connection Testing: We executed the mTLS call using only the Level 3 Leaf certificate from the client side.
The result? The TLS handshake succeeded. API Gateway successfully matched the Leaf to the Intermediate in the truststore, traced it to the Root, and forwarded the request to our Lambda authorizer.
LESSONS FOR ENGINEERING TEAMS
When you hire backend developers for complex pki systems, it is vital to ensure they understand the practical boundaries of managed cloud services. Here are the key takeaways from this implementation:
- Do not rely solely on client-provided chains: While standard TLS allows clients to provide intermediate certificates, many third-party systems format these bundles incorrectly. Placing intermediates in the API Gateway truststore guarantees reliable resolution.
- Understand API Gateway Truststore nuances: AWS documentation can be interpreted in multiple ways. In practice, explicitly defining your intermediate CAs in the `truststore.pem` is the safest path to avoid
403 Forbiddenerrors. - Enable S3 Object Versioning: API Gateway will not automatically detect an updated truststore file in S3 unless you provide a new Object Version ID during the gateway configuration update.
- Distinguish TLS failures from App failures: A 403 from API Gateway during mTLS never reaches your backend logic. Always check CloudWatch execution logs for the Custom Domain Name, not just your Lambda logs.
- Automate Truststore management: As your platform issues new intermediate CAs for different regions or tenants, ensure your CI/CD pipeline automates the concatenation and deployment of the updated PEM file. This is a best practice we enforce when companies hire cloud security engineers for enterprise integrations.
WRAP UP
Implementing multi-tier mTLS in AWS API Gateway requires more than just theoretical PKI knowledge; it demands practical familiarity with how AWS terminates TLS connections. By moving our Intermediate CAs directly into the Gateway’s truststore, we eliminated integration friction for our partners while maintaining a zero-trust security posture. If your organization is struggling with complex cloud architecture or you are looking to scale your engineering capabilities, contact us.
Social Hashtags
#AWS #APIGateway #mTLS #MutualTLS #CloudSecurity #PKI #CertificateChain #AWSLambda #ZeroTrust #DevOps #BackendDevelopment #FinTech #SecureAPI #CloudArchitecture #AWSSecurity
Frequently Asked Questions
AWS API Gateway utilizes highly optimized, strict TLS termination libraries. If the client sends an improperly ordered bundle (e.g., Intermediate before Leaf), the gateway drops the connection. Pre-loading the Intermediate CA in the server truststore bypasses client-side formatting errors.
No. If you rely on the API Gateway to validate the chain without the client sending a perfectly formatted bundle, every new Intermediate CA must be appended to the truststore.pem and deployed to S3.
Yes. API Gateway caches the truststore. To force the gateway to reload the truststore, you must reference a new S3 Object Version ID in the API Gateway Custom Domain settings.
First, isolate the layer. Use curl -v --cert client.pem --key client.key to observe the TLS handshake. If it fails immediately, the issue is the truststore. If it succeeds but you still get a 403, check your API Gateway Resource Policies, WAF rules, or Lambda Authorizer responses.
AWS API Gateway supports a maximum certificate chain depth of four levels for mTLS validation. Ensure your PKI hierarchy (Root -> Intermediates -> Leaf) does not exceed this limit.
Success Stories That Inspire
See how our team takes complex business challenges and turns them into powerful, scalable digital solutions. From custom software and web applications to automation, integrations, and cloud-ready systems, each project reflects our commitment to innovation, performance, and long-term value.

California-based SMB Hired Dedicated Developers to Build a Photography SaaS Platform

Swedish Agency Built a Laravel-Based Staffing System by Hiring a Dedicated Remote Team

















