I created an API Gateway of protocol HTTP to act as an API Gateway for webhook for some service. The service sends a signature in some header, as well as some information in the body. I want my gateway to pass the whole request object (headers + body) as the body of the SQS message but I'm not sure how to achieve this.
I created a new integration and chose SQS.SendMessage. I put in the SQS URL and the invocation role and for the message body I put: $request.body.MessageBody. However, I'm not sure how to include that special header (or the whole request as a whole).
Related
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.
I have an aws lambda function written in node. I have a HTTP API in API Gateway which calls this lambda function.
The "issue" that I'm having is that my request payload which is a JSON, is sent wrapped in a raw body along with a bunch of other fields which I don't really need in my lambda.
How can I have the HTTP API to only send my payload?
If I use a REST API, at least by default, it works the way I expect.
I have a API gateway connected to SQS service, currently it just forward all the incoming requests bodies to SQS by SendMessage action.
I hope at integration request step I can check if the request has a certain field. If so, return a custom response and do not call the SQS service, otherwise forward the request body to SQS as I am doing right now.
I can do this by using a lambda function triggered by API gateway but i am wondering if I can do this without using lambda.
You may achieve that by setting up a request validator on AWS Api Gateway as explained here
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
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.