in my Integration Request I have Body Mapping Tempates for application/xml, application/json (the same template body - reads URL parameters and create JSON body as lambda input).
Client is requesting API with application/json or application/xml. How to make response body format depending on request Content-Type in API Gateway only?
Regards,
Radek
Create ANY integration and handle everything with Lambda. You can avoid all the mappings and handle everything in code and we found that much easier.
More details here on ANY Integration,
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html
Hope it helps.
Related
I have a POST request coming in with a header that I need to play back with the response (Example: "Validation: 123").
The integration returns synchronously, immediately.
The header is entirely non-functional and so doesn't need to be passed through to my integration. It just needs to be passed back with the response to the inbound request.
I am trying to do this by mapping the headers from the method request through to the method response, or via the integration request/response.
For example, I'd like to set the header mapping for the integration response to method.request.header.Validation (ie, identically to the integration request mapping). However, this is disallowed.
Is this the right approach?
This is a limitation of AWS API Gateway.
I have an api gateway that is pointed to s3 and it reads the document and sends back the contents, about 5 paragraphs. It works great, however the content-type on the response is binary\octet-stream. For app integration it would be better if this was text\plain as it is just plain text. I have tried to set this as a parameter on the request with response-content-type. I have also tried to map it within the api gateway integration response. If I leave off the Content-Type mapping I get application/json instead. I've followed the docs here: https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html
The Content-Type on the s3 object was set to binary/octet-stream. Set this to text/plain and works great now!
I'm trying to deploy a lambda function with aws api gateway. I was able to succesfully deploy and test POST and GET methods with Content-Type: application/json by following this blog: http://kennbrodhagen.net/2015/12/06/how-to-create-a-request-object-for-your-lambda-event-from-api-gateway/
I want my same lambda function to handle requests of content-type : text/plain, x-www-form-urlencoded also.
The problem with integration template is that we have to define the content-type before hand. So if I make a integration template of Content-type: text/plain how can I call that integration template when the api request of text/plain is made to the url.
How can I invoke different integration templates based on the Content-Type of the api request?
any tips on that?
Thanks.
I don't know whether I got your problem right r not.
From my understanding if you are passing any header information or query string parameters and the content type is text/plain you can map the template like this
{
"prod_Id" : "$input.params('prod_Id')"
}
where product id can be the header or query string parameter.
you can find it in my blog in 'how to pass query string section
Looking at the examples for AWS API Gateway in order to map a querystring to the Lambda function it shows examples of creating a template map for application/json in the integration request. How do I create a template for all requests no matter the Content-Type? I want it to fire the Lambda with the querystring params regardless of the Content-Type in the request.
This is not possible at the moment. There is no documented wild card available.
"application/json" is the default content type. This is used if no content type is specified in the request (source: https://forums.aws.amazon.com/thread.jspa?threadID=215471).
I am trying to use spring security in my application developing restful web services and not getting the way how to send request to j_spring_security_check directly so that i can provide same url as a web service to Authorization of username and password.
Currently i am using following request pattern:
URL: "http://localhost:8080/CabFMS/j_spring_security_check"
Content-type: application/x-www-form-urlencoded
Body: {'j_username':'user','j_password':'123'}
Response: is Bad credentials
I am not sure about Content-type and body parameters. Please provide suggestion. To send request i am using REST Client
Tarun Gupta
As you correctly noticed j_spring_security_checks expects application/x-www-form-urlencoded content, therefore you need to encode it as such:
j_username=user&j_password=123
Your request pattern should be :
/j_spring_security_check?j_username=user&j_password=123
with method "POST" type.
other then this you can change request action & parameters text "j_spring_security_check" and "j_username" ,"j_password" by configuring alternate text in attributes :
login-processing-url,
username-parameter,
password-parameter
of spring "form-login" tag in security configuration xml file.
Create an AuthenticationSuccessHadler for this, in the authenticationSuccess method, return base64 encoded authorization header with the pattern username:password
Then, on each request, set the header as Basic yourtokenhere