跳至內容

How to include an API Key in the API GW invoke URL without manually including in header

0

Hello Team...

How do we include an API Key in the API GW invoke URL to be used via browser without having to configure it in the header using with a curl command etc...?

已提問 2 年前檢視次數 436 次

3 個答案
1
已接受的答案

This is actually expected behavior and relates to how API Gateway handles static website content versus API endpoints. Let me explain:

When you deploy static files (like index.html) through API Gateway's S3 integration:

  1. These files are typically served through a special "GET /" integration
  2. API Gateway treats these as public static content by default
  3. The API key requirement is often bypassed for these static asset routes

When you hit the base URL (/stage/):

  1. This is treated as an actual API endpoint
  2. API key requirements are enforced as expected
  3. Hence you get the "forbidden" error

API keys are generally better suited for backend API access rather than securing web content.

AWS

已回答 2 年前

專家

已審閱 2 年前

1

To include an API Key in the API Gateway invoke URL for use in a browser without configuring it in the header, you can use the x-api-key query parameter. This method allows you to pass the API Key directly in the URL.

Here's how you can structure the URL:

https://your-api-gateway-url.com/stage/resource?x-api-key=your-api-key-here

However, please note that this approach is less secure than sending the API Key in the header, as the key will be visible in the URL. Use this method with caution and consider the security implications for your specific use case.

AWS

已回答 2 年前

0

It's weird...when I create the API key and enable as "API key required" as True and I put this in the browser: https://your-api-gateway-url.com/stage/index.html it still works without the API key. Why??

but doesn't work if I have in the browser: https://your-api-gateway-url.com/stage --> so here API key kicks in and the site gets "forbidden"...but with index.html appended along with API key, works even though there is API key is enforced...

已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。