AWS API Gateway header for request in Authorizer - amazon-web-services

I am using AWS API Gateway for Communicating with Action on Google Console to AWS Lambda. In this scenario I am making a post call and I want to find the user in this call. I came to know that this is sent in the header. So I did the Following Steps:
Created a resource and method and that's working fine data is being passed successfuly between each other.
Now I want to pass the header to find the user so what I did was I use the authorizer from AWS API gateway console and then clicked on Create a authorizer.
Now I am confused in this scenario I want a header and body so what should I send it has in Lambda Event Payload.
Either Token or payload in case of token it's only sending the authorization part as a header.
So According to my understanding In my scenario I'll be needing Request. But in request what should I add as Identity Sources for header in the console.

Actually for the Above Problem We need to do the Implementation in Integration request in the AWS API Console. Go to the Mapping template in Integration request.
For Futher references use this article

Related

Changing Rest API Endpoint Url dynamically in AWS Api Gateway

I'm looking after solution where AWS Api Gateway changes method endpoint Url dynamically.
I am familiar with stage variables and in Integration request I can change endpoint per method like (https://${stageVariables.Url}/api/DoSomething).
What I need is that information how parse endpoint is included in requests.
https://${RequestData.Url}/api/DoSomething
I have same Api in different locations and to implement centralized Api keys and logging services I try to forward all traffic through this one Api Gateway.
After first request client gets its endpoint information, but I don't know how to solve that clients next requests to Gateway should forward to that endpoint which client get earlier.
I got an answer from AWS support. They told that I have to make a lambda function to process all requests or just use Stage variables.

API Gateway does not pass Authorization header to Lambda

I am trying to use SAM to configure an api gateway and a lambda. However, looking at the event passed to the Lambda, Authorization header is missing. Authorization is suppose to be the JWT from Cognito. When using standard Cloudformation templates, this token is passed as part of the event.
I cannot find anything in SAM documentation or examples, that points me on how to solve this issue.

AWS API Gateway + Lambda: No Auth Header -> Error Message; Auth Header -> No Response

I'm trying to set up a very basic API, before taking the additional step of integrating Cognito. Testing the API endpoint within the AWS console works fine. However, I'm not able to get things working in Postman.
In API Gateway, I've connected an endpoint with no parameters to a Lambda function. The Lambda function returns a hard-coded, static JavaScript object. Clicking the test button here works as expected.
In the Method Execution screen, I've selected AWS_IAM for authorization and don't require an API key.
In IAM I created a user named postman and attached the AmazonAPIGatewayInvokeFullAccess policy (covering all ExecuteAPI resources, for now).
The API seems to be published correctly, since it complains when I try to access it without an Authorization header.
But when I use the AWS Signature Authoriztion type and enter postman's AccessKey and SecretKey, I get no response at all.
I'm trying to find access logs to debug, but I'm new to this part of AWS and haven't found anything yet... What am I missing? Thanks in advance.

401 ERROR AWS API Gateway with Custom Authorizer for Auth0

I'm currently building a simple API with AWS API Gateway. I'll use Auth0 for the authentification. I've created a simple lambda function which will deliver some JSON content on a GET request. Without authentication, it's working. So I've created a custom authorizer for the API using a lambda call. Testing only this lambda call with valid token is working. Testing the custom authorizer with token is working and also testing the specific GET request with valid token is working. Now I want to use postman to check the API but there I get an 401. Anybody an idea what could be the problem ? Thanks for your help.
Initially check Token Source in your API gateway. The value of it should be 'Authorization' not 'method.request.header.Authorization'
If above settings is correct then see how to invoke it from POSTMAN
To call an API with the custom TOKEN authorizer
Open Postman, choose the GET method and paste the API's Invoke URL
into the adjacent URL field.
Add the custom authorization token header and set the value to allow. Choose Send.
Worth read - http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html#call-api-with-api-gateway-custom-authorization

Rejecting an application/x-www-urlencoded call from Slack with AWS Api gateway if field doesn't match

I have POST requests coming from Slack's outgoing webhooks, which are going through the API Gateway to an AWS Lambda function.
I want to filter requests with the API gateway before they ever make it to my lambda function, to reduce the number of times the lambda function will be called, for security purposes.
Technically, it doesn't matter where the call comes from, or where it's going.
The core of my problem is that I want to know how to filter/reject an API call with the AWS Api Gateway if a field doesn't match what I expect.
For example, consider this json.
{
"body": "token=specificToken&someOtherField=someValue"
}
I want to reject the request if the token field doesn't match the expected "specificToken" value.
You can use a custom authorizer of the REQUEST type to do that. A REQUEST-type custom authorizer can use the request body for authorizing the request.
Reference: Create an API Gateway Custom Authorizer Lambda Function (Scroll down to the REQUEST type)
Basically, you write another Lambda that serves as a middleware between your API Gateway. This custom authorizer will decide whether to allow the request or to return Unauthorized to API Gateway.
We had the same requirement (verifying a request from slack with a lambda authorizer), and sadly the REQUEST type does NOT have access to the body of the request. Headers, path, querystring... but not body. This appears to be by design. See Access POST Request body from Custom Authorizer Lambda Function.
We experimented with a custom body mapping template to pull values out of the body and put them into headers, but the mapping is applied after authorisation so this does not work.
Finally, we decided to put our own token in the querystring of the webhook called by our slash command, and verify that instead, which is possible inside a REQUEST authorizer. Not as secure, but it works.