I am using AWS Api Gateway. I have created resource and method using API Gateway.
I have created Lambda function for generating signed URL in json format to access s3 bu
You cannot access the header using Lambda. But what you can do is in the Api Gateway create a mapping template that puts a header value in the event object.
The header should be in the $input.params(x)
variable that can be used in the mapping template. See the full documentation of how to exactly integrate this.
update: in your mapping template (under api gateway -> your endpoint -> integration request), add something like this:
#set($inputRoot = $input.path('$'))
{
"apikey" : "$input.params('X-Api-Key')"
}
Now you can access the api key in the lambda function under event.apikey
(I did not test this, but we use something similar in production). Note that you can do this for all header variables and also variables in the body.
Api Gateway team checking in, Luc's answer is correct. Your Lambda function context has access to the request body only, so any headers that your clients send to Api Gateway will have to be mapped in the request template. The example that Luc gave is a good one, but also check out the reference doc:
http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
Jack