API Gateway
Custom Domain
403 Error
AWS
Troubleshooting

Custom domain for API Gateway returning 403

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

In today's digital landscape, using APIs is crucial for seamless integration between different software systems. AWS API Gateway enhances this process by enabling developers to create, publish, maintain, or secure APIs. However, once in a while, issues arise, such as the dreaded HTTP 403 Forbidden error when using a custom domain name. This article explores the causes, solutions, and preventive measures to handle a 403 error when deploying APIs using a custom domain on AWS API Gateway.

Understanding HTTP 403 Forbidden

A 403 Forbidden error implies that the client does not have permission to access the requested resource. Unlike a 404 Not Found error, the server understands the request but refuses to authorize it. In the context of API Gateway and custom domains, this usually means there are permission or configuration issues related to resource access.

Causes of 403 when Using Custom Domains

  1. Missing or Incorrect IAM Roles:
    • API Gateway may require specific permissions, which are dictated by IAM policies. A missing or incorrect IAM role or policy associated with the gateway can result in a 403 error.
  2. Resource Policies Restrict Access:
    • Resource policies define who, or what can access resources in API Gateway. If these policies restrict access to the custom domain, clients can receive a 403 error.
  3. Incorrect Integration Setup:
    • Sometimes the backend integration, whether it’s AWS Lambda, AWS Elastic Beanstalk, or an HTTP endpoint, might not be correctly configured to accept requests from the API Gateway.
  4. Monetary Restrictions:
    • If AWS WAF (Web Application Firewall) rules or authentication settings like AWS Cognito or custom authorization are not appropriately configured to allow requests, a 403 may occur.
  5. Custom Domain Misconfiguration:
    • The custom domain might not be correctly set up. DNS settings, SSL/TLS certificates, and base mappings need a review to ensure everything is mapped, pointing, and secured correctly.

Troubleshooting Steps

Check IAM Permissions

  • Ensure the execution role associated with your API Gateway has the necessary permissions to invoke the backend resources.
  • Example IAM policy snippet for allowing API Gateway to invoke a Lambda function:
  • Identify the resource policy attached to your API Gateway and confirm it allows access to the intended user group or IP address ranges.
  • Example of a resource policy allowing access from a specific VPC:
  • Double-check the backend integration settings in the API Gateway console to validate that the integration request settings and configurations match the expected endpoints.
  • If using AWS Cognito, make sure the user pool and identity pool settings are correct and the policies are synchronized.
  • Ensure any custom authorizers with Lambda functions are correctly set up and deployed.
  • Verify your DNS settings point to the correct CloudFront distribution created by API Gateway while attaching a custom domain.
  • Ensure the SSL/TLS certificate registered with AWS Certificate Manager is correctly associated with the custom domain name.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design