How to Configure AWS API Gateway with EC2 Backend
API Gateway is a powerful AWS service that helps expose REST APIs securely, with features like throttling, authentication, and monitoring.
In this guide, we’ll configure AWS API Gateway to connect with an EC2-hosted backend application, enable wildcard proxy, and secure it with an API Key.
Scenario:
Our backend service is hosted on an EC2 instance at
It has an endpoint
Our backend service is hosted on an EC2 instance at
http://feenixdv.com:8080.It has an endpoint
/health to check server status:http://feenixdv.com:8080/health
📌 Table of Contents
—
Step 1: Create a REST API in API Gateway
- Open the AWS Console → search for API Gateway.
- Click Create API → select REST API → Build.
- Choose New API, give it a name like
FeenixDV-API, and click Create API.
—
Step 2: Create a Proxy Resource
- Inside your API, go to Resources.
- Click Create Resource.
- Enable Configure as proxy resource.
- Set resource path as
/{proxy+}so wildcard*requests are supported.
—
Step 3: Setup Integration Request
- Select your
/{proxy+}resource. - Click ANY → Integration Request.
- Choose Integration type → HTTP.
- Enter your backend endpoint:
http://feenixdv.com:8080/{proxy} - Save changes.
—
Step 4: Deploy the API
- Click Actions → Deploy API.
- Create a new stage, e.g.,
dev. - Deployment URL will look like:
https://{api-id}.execute-api.{region}.amazonaws.com/dev/{proxy}
—
Step 5: Create & Attach an API Key
- In API Gateway, go to API Keys → Create API Key.
- Give it a name (e.g.,
FeenixKey) → save. - Go to Usage Plans → Create (e.g.,
FeenixPlan). - Set throttling (e.g., 10 req/sec) and quota (e.g., 1000 req/day).
- Attach the dev stage of your API to the usage plan.
- Add the FeenixKey to the plan.
—
Step 6: Test the Setup with API Key
# Direct EC2 URL (no key needed)
curl http://feenixdv.com:8080/health
# API Gateway URL (with API Key)
curl -H "x-api-key: YOUR_API_KEY_HERE" \
https://{api-id}.execute-api.{region}.amazonaws.com/dev/health
—
Final Thoughts
By using AWS API Gateway in front of your EC2 backend, you gain:
- Security (via API Keys & usage plans)
- Scalability & throttling
- Logging & monitoring via CloudWatch
- Seamless proxying with wildcard
*resources
This setup provides a production-ready gateway layer, making your services more robust and secure.