0

I want to have two endpoints on a service, a publically accessible one and one that is exposed "for administrative" use, secured with an API key and other mechanisms.

The diagram shows the configuration I have created (using serverless, incidentally), like this:

    events:
      # The path "/" is needed to allow requests to "root"
      - http: {path: /, method: any, private: false}
      # Add private /admin path, that requires the api key
      - http: {path: /admin/{proxy+}, method: any, private: true}
      - http: {path: /{proxy+}, method: any, private: false}

The configuration seems to work to CREATE the api gateway. And requests to <domain>/ and to <domain>/<various>/paths seem to work fine when <various> is not "admin" -- NO api key required, and the lambda to which this API Gateway spins up.

BUT.. any requests to <domain>/admin/various/paths give me a 403/Forbidden instantly, indicating that API Gateway is blocking the request instantly, I think. LOgs on the lambda show no activity.

Here's a curl response

HTTP/2 403 
date: Wed, 24 Feb 2021 13:19:52 GMT
content-type: application/json
content-length: 23
x-amzn-requestid: aea11b1f-589d-42d2-9df2-44b53f1d543d
x-amzn-errortype: ForbiddenException
x-amz-apigw-id: XXXXXXX

I Am sending the correct api key with x-api-key header. Is there any way to diagnose exactly why this is failing for .../admin endpoints, only. Is there something about this approach that simply won't work?

Diagram of created API Gateway configuration

P.S. I looked on meta.stackexchange and it seems ambiguous if this sort of question is appropriate on stackoverflow, but there are lots of existing Q's and this seems to me to be part of sw development these days.

Marvin
  • 2,537
  • 24
  • 35
  • Does this answer your question? [Using an API key in Amazon API Gateway](https://stackoverflow.com/questions/39061041/using-an-api-key-in-amazon-api-gateway) – MyStackRunnethOver Feb 24 '21 at 15:00
  • If you are using serverless, can you share your complete serverless.yml file? – Sarthak Jain Feb 24 '21 at 17:54
  • we can enable api gateway logs at stage -> logs/tracing -> Log full requests/responses data and Enable CloudWatch Logs. Everything should show up on cloudwatch as long as `CloudWatch log role ARN` is setup at account level – Balu Vyamajala Feb 24 '21 at 23:51
  • doh. I think i was repeatedly sending my headers with curl wrong. need to get more sleep. – Marvin Feb 25 '21 at 03:26

0 Answers0