Dynamic Input for mock integrated AWS API Gateway - amazon-web-services

I have created an API Gateway with mock integration for post and get method. I have also created a model for Post and added it in Method request under request Body. In integration response I want on 2 params (eg : name and Date of birth). But I want to pass all information while testing the API in Request Body and in response body should get values of Name and DoB (passed in request body). I have created application/json file with name and DoB, but I am not getting values defined in request body.
Is there any syntax or a way to take input from request body for API hooked up with mock integration.
info to be passed in request body while testing
application/json
Can anyone help me in this scenario ?

Related

How to override request id send to aws api gateway

AWS Api Gateway docs is crystal clear about the capacity of API Clients override de Request ID here:
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference
More specific on the $context.requestId description: "An ID for the request. Clients can override this request ID. Use $context.extendedRequestId for a unique request ID that API Gateway generates."
I'm trying to send an requestId to override the one generated inside Api Gateway, but i'm cant figure out how.
Any one knows hot to do that?
You do this by adding the same header to the ingoing request:
x-amzn-RequestId=ABC123
This will cause the $context.requestId to equal ABC123, and the extendedRequestId will be the shorter random char string value. There will not be a UUID type Id given.

How to test an AWS API gateway that accepts form parameters sent in Http POST?

I am creating an API gateway in AWS that should accept a POST request from a form.
I want to test the API gateway as if it is receiving a POST request with form parameters. What I should add to the request body to conduct the test assuming that I have two form parameters "name" and "age"?
The web service accepts the parameters as #Formparams
You can add a json body like this there.
{
"name": "Test",
"age": 25
}
Based on the target service the name could be different for the body.
For instance, if the target is a Lambda function based on Node.js, the body can be found in event.body.

How to send a POST request which has Content-Type "application/x-www-form-urlencoded' by using AWS API Gateway?

I'm trying to send a POST request to a REST service via AWS API Gateway.
The content-type of the request should be 'application/x-www-form-urlencoded'. It's an authentication service that I'm trying to access. I'm sending 'username' and 'password' in my request body.
When I send the the request via Postman, it works ( It's giving me the proper response ).
But I want to create an API from the API Gateway to access this endpoint.
When I create a POST method in the API Gateway and try to test it without specifying any content-type, the back-end server tells me to send the request by using the content-type 'application/x-www-form-urlencoded'.
Then when I try to put the content-type in 'Mapping Template' section in the 'Integration Request' of the API, the request doesn't even hit the backend. There's an error ( a JSON response ) comes when I test it, saying 'Unsupported Media Type'.
Does anyone out here knows any workaround for this?
I found the solution.
In order to access a POST service using the content-type ‘application/x-www-form-urlencoded’ in API Gateway, make sure you are doing the following in the API console.
Make sure you have enabled the ‘Use HTTP Proxy integration’ as the following in the ‘Integration Request’ section.
When you test the request, make sure you are putting the content type ‘application/x-www-form-urlencoded’ inside the Header’s box as in the following.
And the request body should be like the following as well.
username=user#wellcomww.com.au&password=123456

Amazon Gateway - access original request body in integration response

Good day everyone, my problem related with Amazon Gateway API. I have the following case:
Response received from 3rd party service and contains no query params (all necessary data stored in body)
I'am able to modify body and pass it to target URL via Integration Request
Integration Request finished, i receive some data from target endpoint
Now i need to create Integration Response, based on original data (received in 1.) and data, received from target endpoint.
Problem appears at stage 4. I can't find a way to access original body here ($input.body contains response from target endpoint, there is no original data).
I also tried to store necessary data in scope variables ($input/$context), but it seems like AWS Gateway allows only to read it.
As of now, you cannot access the $input.body in the integration response mapping. We will consider supporting this in the future.

AWS API Gateway - Change http proxy status code

I cretaed a http proxy method in my API Gateway to a remote CRM system I need to send data to.
The thing is that the CRM return all its responses as 200, and notifies for success or failure inside the response body, for example :
Hi wish to know, if there is any way inside the method to check the response using lambda function and change the status code accordingly.
You will have to modify your lambda to change the response and include an error message to model in API Gateway. This blog post is a great resource for configuring these mappings.