No luck requiring API Keys

api-gateway

#1

Can’t seem to get requiring API keys to work. We have a proxy event if that makes a difference. I have added the apiKeys object as follows.

provider:
name: aws
apiKeys:
- ${opt:stage}-schools

This works and creates the key and outputs it for me as well.

I then have a function as follows:

functions:
hello:
handler: Schools.App::Schools.App.LambdaEntryPoint::FunctionHandlerAsync
events:
- http: any {proxy+}
private: true

After executing this I look in API Gateway on the console. I see a newly created Usage Plan which I wasn’t expecting. If I go to the Method Request under the proxy resource there is a warning next to the API Key Required status which is still set to ‘false’.

The warning states: At least one stage of this API is associated with usage plan(s) but an API key is not required for this method.

What am I missing? I don’t really need to make use of Usage Plan and would just like the API key to be required on the ANY method.

Thanks!


#2

Try defining your function like this:

functions:
  hello:
    handler: Schools.App::Schools.App.LambdaEntryPoint::FunctionHandlerAsync
    events:
      - http:
          path: /{proxy+}
          method: any
          private: true

#3

Thank you that did the trick. I swear I tried this format before and had a problem with it but I’ll just chalk this up to YML being YML.