Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access headers in AWS API Gateway using HTTP Proxy?

I'm using AWS API Gateway and it's HTTP Proxy,

I need to pass Authorization header to my endpoint through AWS API Gateway

Things I've tried:

Setting Method Request like so,

Method Request

Integration Request setup enter image description here

This doesn't work, my app doesn't receive the Authorization header,

Also I've tried using mapping template

{
  "method": "$context.httpMethod",
  "body" : $input.json('$'),
  "headers": {
    #foreach($param in $input.params().header.keySet())
    "$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end

    #end
  },
  "queryParams": {
    #foreach($param in $input.params().querystring.keySet())
    "$param": "$util.escapeJavaScript($input.params().querystring.get($param))" #if($foreach.hasNext),#end

    #end
  },
  "pathParams": {
    #foreach($param in $input.params().path.keySet())
    "$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end

    #end
  }  
}

This also doesn't worked.

Could Anyone give me some hint on how this might be accomplished ?

like image 995
ihoryam Avatar asked Jan 26 '16 15:01

ihoryam


People also ask

How do I pass headers in API gateway test?

To pass custom headers from an API Gateway API to a Lambda function, use a body mapping template. The API sends the updated API request to a Lambda function to process the headers. Then, the Lambda function returns one or more header values from the original API request.

Can API proxy can act as an API gateway?

An API proxy acts as a gateway between your developers and backend services, although it is limited in its capabilities when compared to an API gateway. It's an intermediary that makes requests on behalf of developers, sitting between application and backend services.

How do I use API gateway proxy?

To set up a proxy integration in an API Gateway API with a proxy resource, you perform the following tasks: Create a proxy resource with a greedy path variable of { proxy +} . Set the ANY method on the proxy resource. Integrate the resource and method with a backend using the HTTP or Lambda integration type.

What is HTTP proxy in API gateway?

An HTTP proxy integration enables you to connect an API route to a publicly routable HTTP endpoint. With this integration type, API Gateway passes the entire request and response between the frontend and the backend. To create an HTTP proxy integration, provide the URL of a publicly routable HTTP endpoint.

How to integrate API gateway with AWS service proxies?

Create an AWS service proxy execution role. Note the role's ARN for later in the setup. This AWS Identity and Access Management (IAM) role gives API Gateway permissions as a trusted entity to assume the service and perform the API action that you're integrating.

What is API gateway and should I use it?

If you haven’t used API Gateway, I suggest you start HERE. Amazon’s API Gateway provides a relatively simple way to put an HTTP endpoint in front of your resources (both AWS and on-prem). API Gateway gives you a few different ways to define and handle the various pieces of your API’s HTTP resources:

What is an HTTP proxy integration?

An HTTP proxy integration enables you to connect an API route to a publicly routable HTTP endpoint. With this integration type, API Gateway passes the entire request and response between the frontend and the backend. To create an HTTP proxy integration, provide the URL of a publicly routable HTTP endpoint.

How to access request headers sent to API gateway?

The event object contains "headers" in it, you can access request headers sent to API gateway by using: event.headers.<header key> The solution by kennbrodhagen worked great for me, see his answer and blog for the details.


1 Answers

API Gateway strips the AWS SigV4 Authorization header due to security reasons. If you are using other Authorization mechanism like OAuth, the header wouldn't be stripped.

like image 83
Balaji Avatar answered Oct 23 '22 04:10

Balaji