I am setting up API Gateway for my lambda function and use Proxy integration. I also create usage plans & API Keys for this API and share the API keys k1 & k2, with two customers c1 & c2.
When customer makes call with key k2, is there a way to find from my lambda function that the request is made by c2?
I have a java handler implementing RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent>
but unfortunately I am not finding customer context in APIGatewayProxyRequestEvent
You will not get customer context in the event wth API keys
. API keys can be shared across multiple usage plans
for different APIs. So they cannot be tied to any one API deployment. If you want to do this, you will manage it on your own (e.g. restrict 1 API to 1 customer, API key mapping to customer).
I think one reason AWS does not provide this is because API keys
are meant purely for usage plans
. Any sort of authentication/authorization (where user identification is important) needs to be done using other techniques like IAM
, Cognito user pools
or custom authorizer
. Please see this.
To include API methods in a usage plan, you must configure individual API methods to require an API key. For user authentication and authorization, don't use API keys. Use an IAM role, a Lambda authorizer, or an Amazon Cognito user pool.