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
http://feenixdv.com:8080.
It has an endpoint /health to check server status:
http://feenixdv.com:8080/health

Step 1: Create a REST API in API Gateway

  1. Open the AWS Console → search for API Gateway.
  2. Click Create API → select REST API → Build.
  3. Choose New API, give it a name like FeenixDV-API, and click Create API.

Step 2: Create a Proxy Resource

  1. Inside your API, go to Resources.
  2. Click Create Resource.
  3. Enable Configure as proxy resource.
  4. Set resource path as /{proxy+} so wildcard * requests are supported.

Step 3: Setup Integration Request

  1. Select your /{proxy+} resource.
  2. Click ANY → Integration Request.
  3. Choose Integration type → HTTP.
  4. Enter your backend endpoint:
    http://feenixdv.com:8080/{proxy}
  5. Save changes.

Step 4: Deploy the API

  1. Click Actions → Deploy API.
  2. Create a new stage, e.g., dev.
  3. Deployment URL will look like:
    https://{api-id}.execute-api.{region}.amazonaws.com/dev/{proxy}

Step 5: Create & Attach an API Key

  1. In API Gateway, go to API Keys → Create API Key.
  2. Give it a name (e.g., FeenixKey) → save.
  3. Go to Usage Plans → Create (e.g., FeenixPlan).
  4. Set throttling (e.g., 10 req/sec) and quota (e.g., 1000 req/day).
  5. Attach the dev stage of your API to the usage plan.
  6. 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.