Skip to content

How do I troubleshoot 403 Forbidden, SSL certificate, and connection timeout errors with private API Gateway custom domain names?

6 minute read
Content level: Expert
0

When you set up a private custom domain name for Amazon API Gateway, connectivity issues can arise from misconfigurations in resource policies, VPC endpoint settings, domain associations, or DNS mappings. This article helps you identify and resolve the most common errors you encounter with private REST API custom domain names: 403 Forbidden responses, SSL certificate (SNI) errors, and connection timeouts. Follow the tasks in order to isolate and fix the root cause.

Issue statement

I followed the instructions to set up a private custom domain name for my REST API Gateway, and I'm receiving errors such as 403 Forbidden, SSL certificate errors, or connection timeouts.

Short description

When you set up a private custom domain name for API Gateway, connectivity issues can arise from misconfigurations in resource policies, VPC endpoint settings, domain associations, or DNS mappings. This guide helps you identify and resolve the most common errors.

Resolution

Task 1: Verify the custom domain resource policy

Problem

You receive a 403 Forbidden error with the message:

User: anonymous is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:REGION:ACCOUNT-ID:/domainnames/example.com+abcd1234ef with an explicit deny in a resource-based policy

Cause

The API Gateway resource policy denies access by default or doesn't allow access from your VPC endpoint.

Solution

Complete the following steps:

  1. Navigate to the API Gateway console and select your private API.
  2. Go to Resource Policy.
  3. Add or update the policy to allow access from your VPC endpoint using the following template:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "execute-api:Invoke",
            "Resource": [
                "execute-api:/*"
            ]
        },
        {
            "Effect": "Deny",
            "Principal": "*",
            "Action": "execute-api:Invoke",
            "Resource": [
                "execute-api:/*"
            ],
            "Condition": {
                "StringNotEquals": {
                    "aws:SourceVpce": "vpce-abcd1234"
                }
            }
        }
    ]
}

Important: Replace vpce-abcd1234 with your actual VPC endpoint ID. This restricts access to only requests coming through the specified VPC endpoint.

Task 2: Configure the VPC endpoint policy

Problem

You receive a 403 Forbidden error with the message:

User: anonymous is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:REGION:ACCOUNT-ID:/domainnames/example.com+abcd1234ef with an explicit deny in a VPC endpoint policy

Cause

The VPC endpoint policy doesn't allow execute-api actions, or network configuration blocks traffic.

Solution

By default, the VPC endpoint policy allows full access, which is the recommended configuration. Restricting the endpoint policy requires mandatory IAM authentication for all requests, which may not align with typical deployment patterns. Unless your security requirements explicitly mandate endpoint-level restrictions, maintain the default permissive policy to ensure seamless service connectivity.

Subtask: Verify network connectivity

Take the following actions:

  • Verify the VPC endpoint security group allows inbound HTTPS (port 443) traffic. If you receive an error such as Failed to connect to example port 443 after 129387 ms: Could not connect to server, update the security group inbound rules.
  • Check that subnet network ACLs permit traffic to and from your client.
  • Test DNS resolution to confirm the custom domain resolves to the VPC endpoint's private IP addresses.

Task 3: Associate the domain name with the VPC endpoint

Problem

You receive an SSL certificate error:

SSL: no alternative certificate subject name matches target hostname 'example.com'

Cause

The VPC endpoint is not associated with the custom domain name.

Solution

Complete the following steps:

  1. Navigate to API Gateway Console → Custom Domain Names → Your Domain.
  2. Go to the Resource sharing section.
  3. Under Domain name access associations, select Add VPC endpoint.
  4. Enter your VPC endpoint ID (vpce-abcd1234).
  5. Confirm the VPC endpoint is for the service com.amazonaws.region.execute-api.

Subtask: Configure cross-account access

If you need to share the custom domain across AWS accounts, take the following actions:

  • Provider account: Share the custom domain via AWS Resource Access Manager (AWS RAM).
  • Consumer account: Accept the AWS RAM invitation, then create a domain name access association manually by entering the shared domain ARN.

Note: When creating the association in a consumer account, you must manually enter the domain name ARN—it won't appear in the dropdown menu.

Subtask: Verify the association

Note: The private custom domain name commands require an AWS CLI v2 version released after the feature launch (November 2024). If get-domain-name-access-associations returns an "Invalid choice" error, upgrade to the latest AWS CLI v2.

Run the following AWS CLI command to confirm the association:

aws apigateway get-domain-name-access-associations \
    --resource-owner SELF

The response lists each association, including its accessAssociationSource (your VPC endpoint) and the domainNameArn it's associated with. Confirm that your VPC endpoint and custom domain name appear in the output. To list associations created by other accounts (cross-account sharing), use --resource-owner OTHER_ACCOUNTS instead.

Task 4: Resolve DNS mapping and SNI errors

Problem

DNS doesn't resolve to the correct IP addresses, or you receive Server Name Indication (SNI) errors.

Cause

DNS configuration doesn't point to the VPC endpoint's private IPs, or the host header doesn't match the custom domain.

Solution: Option A — Using a Route 53 private hosted zone

Complete the following steps:

  1. Create a private hosted zone for your custom domain.
  2. Associate it with the VPC containing the VPC endpoint.
  3. Create an A record (alias) pointing to your VPC endpoint.

Solution: Option B — Using third-party DNS

Complete the following steps:

  1. Configure an A record pointing to the VPC endpoint's private IP addresses.
  2. Retrieve the private IP addresses using the following AWS CLI command:
aws ec2 describe-network-interfaces \
    --filters "Name=vpc-endpoint-id,Values=vpce-abcd1234" \
    --query 'NetworkInterfaces[*].PrivateIpAddress'

Subtask: Enable VPC DNS requirements

Ensure the following DNS settings are enabled on your VPC:

  • enableDnsHostnames is set to true.
  • enableDnsSupport is set to true.

Subtask: Configure Server Name Indication (SNI)

API Gateway uses Server Name Indication (SNI) to select the correct SSL certificate. Ensure that:

  • The Host header in your requests matches your custom domain exactly.
  • Your client supports SNI (most modern clients do).
  • The custom domain certificate includes the domain in its Subject Alternative Names.

Task 5: Validate your configuration

Test your configuration from an Amazon EC2 instance or resource inside your VPC by running the following commands:

# Test DNS resolution
nslookup your-custom-domain.com

# Test HTTP connectivity
curl -v https://your-custom-domain.com/base-path/complete-resource-path

A successful test returns a 200 status code or the appropriate response from your API.

Related information