Decision Making at API gateway Integration Request - amazon-web-services

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

Related

How to handle lambda retries invoked from api gateway?

The api gateway url is triggered/called by a form submit. Now, as this is a synchronous invocation, how do I handle a lambda retries and handle throttles?
Note: I am deploying api gateway along with lambda and use the url generated as webhook for form submit. So basically, it would be a one-way communication.
Flow:
form(payload)-> (api gateway)-> lambda-> lambda-> sqs-> lambda-> dynamoDb
There won't be an automatic Lambda retry when it's invoked from API Gateway afaik. If you are throttled or the request fails (perhaps because of a Lambda function error), your client is responsible for deciding how to recover and whether or not to retry, likely based on the HTTP response code.
Also worth reading:
A Detailed Overview of AWS API Gateway
How AWS Lambda Retry really works

AWS - API Gateway to SQS with full request as body

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).

How does AWS lambda get triggered by an api request?

Im assuming lambda is like the missing piece of the puzzle for a complete api request. So you create the apigateway and then write the lambda function which bridges the gap between taking a request and returning the output of the lambda function as the http response.
I've successfully followed guides on how to set up an API gateway that triggers AWS lambda to do something, but I still don't really understand what is being done.
How is the function def handler(event, context): being called by the aws apigateway? How does it get triggered and how is the output of handler sent back?
You do not need a Lambda "in the middle". Using Lambda Proxy integration in the API Gateway you can receive the full information about the request (endpoint URL, query parameters, etc) in your targeted Lambda event.
Have a look at the following Tutorial how to setup Lambda Proxy integration with API Gateway.
The tricky thing you should care about is the structure of the response that you will return from your lambda_handler. See the requirements here.
Answering the question of "how this happens"... In short, when an HTTP request comes to your API endpoint it is automatically routed to the mapped Lambda function. Behind the scenes a new container for the Function is spawned and your request comes to the event of the lambda_handler. API Gateway by default also creates a CloudFront distribution in front of itself to serve your requests more efficiently. Once your Lambda returns the response, API Gateway parses it and constructs the HTTP response out of it. The nice thing is that all of this is managed by AWS.

AWS API Gateway HTTP Request Interceptor

I'm not able to find any documentation about intercepting all HTTP requests passing through AWS API Gateway.
I'm trying to propose a Logging service for the backend APIs deployed on AWS API Gateway. The idea is all the HTTP requests will go through the API Gateway. If I'm able to intercept the request going through API Gateway, I can hook the logging service code.
The reason for this approach is, the logging code will be independent of the actual service code and service code won't have to be updated to include logging of request / response.
Any solutions for this?
You can put CloudFront in front of your API Gateway and then use Lambda#Edge Viewer Request to intercept all requests; we do this for logging for certain functions and it works flawlessly.
This is a good tutorial on how to setup API Gateway with CloudFront
https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-cloudfront-distribution/
It seems Claudia-bot-builder's intercept method will help you to intercept the API gateway requests. You can trigger an event for requests hitting to the API gateway.
`api.intercept(function (event) { ... });`

SNS - Get IP of Publisher?

I have an API Gateway endpoint that takes the bodies of requests to it and places them in an SQS queue. The API Gateway has the ability to transform the request and add requester meta, like the user agent and ip address, to the message it eventually sends to SQS.
I'd like to change this from API Gateway to SNS so that the requester would publish to an SNS topic that feeds into SQS or directly to SQS.
The issue i'm having with this is that while I can get the useragent from the requester pre-send, i can't get the ip of the user without making a call to an endpoint and having the endpoint return the ip it observed.
Is it possible for the aws SNS/SQS api to append the ip of the request to the messages they receive?
SQS actions SendMessage, SendMessageBatch and SetQueueAttributes will process messages as they are received. There is no SQS/SNS configuration that could be used to modify the message. It would make sense to use SQS directly but in my opinion using SNS instead of API Gateway won't make it any better from cost/performance/implementation point of view. API Gateway appears to be your best option.