Skip to content

403 Forbidden Error When Accessing API Gateway via Custom Domain with Regional Endpoint

0

I'm encountering a 403 Forbidden error when trying to access my AWS API Gateway using a custom domain. Here's a summary of the issue:

Configuration:

  1. API Gateway Endpoint Type: Regional
  2. Custom Domain: Configured with an AWS-managed SSL certificate and using TLS 1.2 as the minimum version.
  3. DNS: The custom domain's DNS CNAME record is pointing directly to the API Gateway’s regional domain.
  4. Stage: The API works fine when accessed directly via the API Gateway’s stage URL (https://abc123.execute-api.us-west-2.amazonaws.com/prod), and logs are generated as expected.
  5. Logging: Enabled full logging in API Gateway, and logs are successfully generated when accessing via the stage URL.
  6. No CloudFront Distribution: The API is using a regional endpoint, so there’s no CloudFront distribution involved.

Issue: When accessing the API using the custom domain URL (https://api.mydomain.com), I receive a 403 Forbidden error. The error is consistent across different clients (Postman, browser). The API Gateway logs do not show any logs for requests made through the custom domain, but logging works when accessed via the stage URL.

Steps Taken:

  1. Reconfigured the Custom Domain: 1. Deleted and recreated the custom domain in API Gateway. 2. Updated DNS records accordingly.
  2. Verified SSL and TLS: 1. Confirmed that the SSL certificate is correctly associated with the custom domain. 2. Ensured the TLS version is set to 1.2.
  3. Revalidated Custom Domain: Ensured the custom domain is validated in API Gateway.
  4. Tested Direct API Gateway URL: Confirmed that the API functions properly using the API Gateway stage URL.

Current Error: When accessing the API via the custom domain, I receive the following error in Postman:

403 Forbidden
The request could not be satisfied. Bad request. We can't connect to the server for this app or website at this time.

There are no IP restrictions, CORS issues, or custom VPCs involved. The API is hosted in the default VPC.

Questions:

  1. What could be causing the 403 Forbidden error when accessing via the custom domain?
  2. Are there any additional configurations or permissions I need to check?
  3. How can I troubleshoot this issue further, especially given that the API works fine via the stage URL?

Any guidance or suggestions would be greatly appreciated!

Edit 1: I deleted the old custom domain from API gateway, and also stages, and created a new custom domain on console, with the same subdomain and SSL Certificate as before, just edge endpoint instead of regional, and now the cloudfront issue is not showing up, but I'm still getting forbidden error:

{
    "message": "Forbidden"
}
3 Answers
0

Caching by browsers or intermediate proxies can cause old DNS resolutions to persist. Try clearing your browser cache or using a different browser/incognito mode to bypass caches. Additionally,

  1. Verify that your custom domain is correctly set up and mapped to your API.
  2. Verify in the API Gateway console that the correct SSL/TLS certificate is associated with the custom domain. Ensure that the certificate is valid and not expired.
AWS
EXPERT

answered 2 years ago

    1. In the DNS records, I have verified that the domain is correctly pointing to the CNAME record of API Gateway url(ending with .amazonaws.com)
    2. In the console I have enabled the setting of TLS 1.2 Minimum, and the certificate used for it is also showing as Valid on Certifcate Manager.

    Is there any thing else that I need to verify?

0

Hello.

What are the settings for the base path mapping mentioned in the document below?
I have seen this setting incorrectly resulting in a 403 error.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-regional-api-custom-domain-create.html#apigateway-regional-api-custom-domain-base-path-mapping

EXPERT

answered 2 years ago

  • I have removed the stages, and just pointing to the lambda, also I have set the path in the API mapping.

    So, let's say my custom domain is api.example.com, and it has an API mapping: API: send Path: verify

    So, I'm calling using postman:

    api.example.com/verify
    

    Where the send accepts POST as well as GET method

0

Can you tell me if you solved it? I have the same issue.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.