How to access header in AWS Lambda?

I am using AWS Api Gateway. I created the resource and method using the Gateway API.

I created a Lambda function to create a signed json URL to access the s3 stuff via CloudFront.

When I call the lambda function using the GET method. I pass "channelekID" as the request. I want to send my own X-API-Key header, as well as for authorization.

I tried a lot of things but did not find any solution. How to send custom header to lambda function? and after accessing the header value in Lambda How do I enable the use of the x-api key?

+4
source share
3 answers

You cannot access the header using Lambda. But what you can do is to create a display template in Api Gateway that places the header value in the event object.

The header must be in a variable $input.params(x)that can be used in the mapping template. See the full documentation on how to integrate this accurately.

update: in the 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 have not tested this, but we use something similar in production). Please note that you can do this for all header variables as well as variables in the body.

+10

s3, URL-, URL-. ?

 getSignedURL(fileName: string): Observable<any> {
 // API gate way URL to get pre signed URL
 const apiGatewayUrl = 'https://oweoupload.dev.cosym-dev-internal.de'; 
    return this.http.get(apiGatewayUrl);
  }
Hide result

, URL .

0

Source: https://habr.com/ru/post/1620087/


All Articles