how to make AWS api gateway accept http instead of https
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Amazon API Gateway is a powerful service provided by AWS that allows developers to create, deploy, and manage APIs at scale. API Gateway supports both RESTful APIs and WebSocket APIs, enabling a wide array of use cases. By default, API Gateway strictly enforces HTTPS, ensuring secure communication between clients and the API service. However, there are instances where you might want your API Gateway to accept HTTP traffic—typically in development and testing environments where encryption overhead is unnecessary.
In this article, we'll walk through how to configure an AWS API Gateway to accept HTTP traffic instead of HTTPS. Note that this practice is generally not recommended for production environments due to the security implications. The focus here is purely educational or for specific testing scenarios.
Before You Begin
- AWS Account: Ensure you have an AWS account with sufficient permissions to create and modify API Gateways and associated resources.
- AWS CLI or Console Access: Have access to AWS Management Console or AWS CLI configured for your account.
- Understanding of API Gateway: Basic familiarity with AWS API Gateway and its settings.
Technical Explanation and Setup
Key Steps to Accept HTTP Traffic
- Custom Domain Name: AWS API Gateway does not directly support HTTP for endpoints. However, you can use a custom domain name configured to support HTTP.
- Deploy API: Deploy your API normally via API Gateway.
- Route Traffic through a Load Balancer: Use AWS Elastic Load Balancer (ELB) to route HTTP traffic to the API Gateway.
- TLS Termination: Terminate the HTTPS traffic at the load balancer and forward the traffic to the API Gateway as HTTP.
Step-by-Step Setup
1. Create an API in API Gateway
- Log in to the AWS Management Console.
- Go to API Gateway, select "Create API," and choose HTTP API or REST API depending on your needs.
- Define your API, create resources and methods, and deploy it to a stage.
2. Set Up a Custom Domain
- In API Gateway, navigate to "Custom Domain Names."
- Choose "Create" and specify a domain name.
- Configure the custom domain with an HTTP endpoint. AWS requires validation of domain ownership which typically involves updating DNS records.
3. Configure an Elastic Load Balancer (ELB)
- Go to the EC2 section of the AWS Management Console and create an Elastic Load Balancer.
- Choose Application Load Balancer (ALB).
- Add a Listener for HTTP (port 80) to accept inbound HTTP traffic.
- Add a target group for your API Gateway.
- Register the API Gateway endpoint as a target for the load balancer. This setup essentially forwards HTTP requests received by the load balancer to the HTTPS endpoint of the API Gateway.
4. Update DNS Records
- Once the setup is in place, update your DNS records to point your domain to the ELB.
5. Test Your HTTP Endpoint
- Use a tool like `curl` to send HTTP requests to your domain and verify that they are correctly routed to your API Gateway. Example:
- Development/Testing: During development or testing, you might want to skip encryption to reduce complexity.
- Controlled Environments: In a secured and isolated network environment where encryption is not a concern.

