Search code examples
amazon-web-servicesaws-lambdaaws-api-gateway

How to get api gateway key name in aws lambda function


I create the api in "Api-gateway" and set "API Key Required" to true in Method execution settings , But in lambda function i only get the "apiKeyId" from the request header. Is there any way to get the apiKeyName too?


Solution

  • In short, the ApiKey name is not available within the executing lambda. You can only use the SDK to query all keys and then filter manually with code.

    On a side note, you can also do this in a custom authorizer and map the name to the invocation context. This way you only have to code it once and all lambdas get the parameter as a context variable. Another bonus of this implementation is, that the result of custom authorizer is cached.

    nodejs implementation of custom authorizer with apikey name mapper