{"id":272,"date":"2025-08-21T12:06:32","date_gmt":"2025-08-21T12:06:32","guid":{"rendered":"https:\/\/ai.feenixdv.com\/?p=272"},"modified":"2025-08-21T12:20:59","modified_gmt":"2025-08-21T12:20:59","slug":"setting-up-aws-api-gateway-with-ec2-backend-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/ai.feenixdv.com\/index.php\/272\/32\/","title":{"rendered":"Setting Up AWS API Gateway with EC2 Backend (Step-by-Step Guide)"},"content":{"rendered":"<article class=\"post-content\">\n<style>\n  .post-content h2 {\n    color: #2a4d9c;\n    border-left: 5px solid #2a4d9c;\n    padding-left: 10px;\n    margin-top: 25px;\n  }\n  .post-content h3 {\n    color: #444;\n    margin-top: 20px;\n  }\n  .post-content code {\n    background: #f4f4f4;\n    padding: 3px 6px;\n    border-radius: 4px;\n    font-size: 90%;\n  }\n  .post-content pre {\n    background: #1e1e1e;\n    color: #f1f1f1;\n    padding: 12px;\n    border-radius: 6px;\n    overflow-x: auto;\n  }\n  .highlight-box {\n    background: #eef6ff;\n    border-left: 5px solid #2a4d9c;\n    padding: 12px;\n    margin: 20px 0;\n    border-radius: 6px;\n  }\n  .toc {\n    background: #f8f9fa;\n    border: 1px solid #ddd;\n    padding: 15px;\n    border-radius: 8px;\n    margin-bottom: 25px;\n  }\n  .toc h3 {\n    margin: 0 0 10px 0;\n    color: #2a4d9c;\n  }\n  .toc ul {\n    list-style-type: none;\n    padding: 0;\n  }\n  .toc ul li {\n    margin: 8px 0;\n  }\n  .toc ul li a {\n    text-decoration: none;\n    color: #2a4d9c;\n  }\n  .toc ul li a:hover {\n    text-decoration: underline;\n  }\n<\/style>\n<h1>How to Configure AWS API Gateway with EC2 Backend<\/h1>\n<p>\nAPI Gateway is a powerful AWS service that helps expose REST APIs securely, with features like throttling, authentication, and monitoring.<br \/>\nIn this guide, we\u2019ll configure <strong>AWS API Gateway<\/strong> to connect with an EC2-hosted backend application, enable wildcard proxy, and secure it with an API Key.\n<\/p>\n<div class=\"highlight-box\">\n<b>Scenario:<\/b><br \/>\nOur backend service is hosted on an EC2 instance at<br \/>\n<code>http:\/\/feenixdv.com:8080<\/code>.<br \/>\nIt has an endpoint <code>\/health<\/code> to check server status:<br \/>\n<code>http:\/\/feenixdv.com:8080\/health<\/code>\n<\/div>\n<p><!-- Table of Contents --><\/p>\n<div class=\"toc\">\n<h3>\ud83d\udccc Table of Contents<\/h3>\n<ul>\n<li><a href=\"#step1\">Step 1: Create a REST API<\/a><\/li>\n<li><a href=\"#step2\">Step 2: Create a Proxy Resource<\/a><\/li>\n<li><a href=\"#step3\">Step 3: Setup Integration Request<\/a><\/li>\n<li><a href=\"#step4\">Step 4: Deploy the API<\/a><\/li>\n<li><a href=\"#step5\">Step 5: Create &#038; Attach an API Key<\/a><\/li>\n<li><a href=\"#step6\">Step 6: Test the Setup with API Key<\/a><\/li>\n<li><a href=\"#final\">Final Thoughts<\/a><\/li>\n<\/ul>\n<\/div>\n<p>&#8212;<\/p>\n<h2 id=\"step1\">Step 1: Create a REST API in API Gateway<\/h2>\n<ol>\n<li>Open the <strong>AWS Console<\/strong> \u2192 search for <strong>API Gateway<\/strong>.<\/li>\n<li>Click <strong>Create API<\/strong> \u2192 select <strong>REST API<\/strong> \u2192 <em>Build<\/em>.<\/li>\n<li>Choose <strong>New API<\/strong>, give it a name like <code>FeenixDV-API<\/code>, and click <strong>Create API<\/strong>.<\/li>\n<\/ol>\n<p>&#8212;<\/p>\n<h2 id=\"step2\">Step 2: Create a Proxy Resource<\/h2>\n<ol>\n<li>Inside your API, go to <strong>Resources<\/strong>.<\/li>\n<li>Click <strong>Create Resource<\/strong>.<\/li>\n<li>Enable <strong>Configure as proxy resource<\/strong>.<\/li>\n<li>Set resource path as <code>\/{proxy+}<\/code> so wildcard <code>*<\/code> requests are supported.<\/li>\n<\/ol>\n<p>&#8212;<\/p>\n<h2 id=\"step3\">Step 3: Setup Integration Request<\/h2>\n<ol>\n<li>Select your <code>\/{proxy+}<\/code> resource.<\/li>\n<li>Click <strong>ANY<\/strong> \u2192 <strong>Integration Request<\/strong>.<\/li>\n<li>Choose <strong>Integration type<\/strong> \u2192 <strong>HTTP<\/strong>.<\/li>\n<li>Enter your backend endpoint:<br \/>\n    <code>http:\/\/feenixdv.com:8080\/{proxy}<\/code>\n  <\/li>\n<li>Save changes.<\/li>\n<\/ol>\n<p>&#8212;<\/p>\n<h2 id=\"step4\">Step 4: Deploy the API<\/h2>\n<ol>\n<li>Click <strong>Actions<\/strong> \u2192 <strong>Deploy API<\/strong>.<\/li>\n<li>Create a new stage, e.g., <code>dev<\/code>.<\/li>\n<li>Deployment URL will look like:<br \/>\n    <code>https:\/\/{api-id}.execute-api.{region}.amazonaws.com\/dev\/{proxy}<\/code>\n  <\/li>\n<\/ol>\n<p>&#8212;<\/p>\n<h2 id=\"step5\">Step 5: Create &#038; Attach an API Key<\/h2>\n<ol>\n<li>In API Gateway, go to <strong>API Keys<\/strong> \u2192 <strong>Create API Key<\/strong>.<\/li>\n<li>Give it a name (e.g., <code>FeenixKey<\/code>) \u2192 save.<\/li>\n<li>Go to <strong>Usage Plans<\/strong> \u2192 <strong>Create<\/strong> (e.g., <code>FeenixPlan<\/code>).<\/li>\n<li>Set <strong>throttling<\/strong> (e.g., 10 req\/sec) and <strong>quota<\/strong> (e.g., 1000 req\/day).<\/li>\n<li>Attach the <strong>dev<\/strong> stage of your API to the usage plan.<\/li>\n<li>Add the <strong>FeenixKey<\/strong> to the plan.<\/li>\n<\/ol>\n<p>&#8212;<\/p>\n<h2 id=\"step6\">Step 6: Test the Setup with API Key<\/h2>\n<pre>\n# Direct EC2 URL (no key needed)\ncurl http:\/\/feenixdv.com:8080\/health\n\n# API Gateway URL (with API Key)\ncurl -H \"x-api-key: YOUR_API_KEY_HERE\" \\\nhttps:\/\/{api-id}.execute-api.{region}.amazonaws.com\/dev\/health\n<\/pre>\n<p>&#8212;<\/p>\n<h2 id=\"final\">Final Thoughts<\/h2>\n<p>\nBy using <strong>AWS API Gateway<\/strong> in front of your EC2 backend, you gain:\n<\/p>\n<ul>\n<li>Security (via API Keys &#038; usage plans)<\/li>\n<li>Scalability &#038; throttling<\/li>\n<li>Logging &#038; monitoring via CloudWatch<\/li>\n<li>Seamless proxying with wildcard <code>*<\/code> resources<\/li>\n<\/ul>\n<p>\nThis setup provides a production-ready gateway layer, making your services more robust and secure.\n<\/p>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019ll configure AWS API Gateway to connect with an EC2-hosted backend application, enable wildcard proxy, and secure it with an API Key. Scenario: &#8230; <a href=\"https:\/\/ai.feenixdv.com\/index.php\/272\/32\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &#8220;Setting Up AWS API Gateway with EC2 Backend (Step-by-Step Guide)&#8221;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[],"class_list":["post-272","post","type-post","status-publish","format-standard","hentry","category-aws","category-cloud-computing"],"_links":{"self":[{"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":3,"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"predecessor-version":[{"id":275,"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/posts\/272\/revisions\/275"}],"wp:attachment":[{"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.feenixdv.com\/index.php\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}