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.
Related
I want to create a GET endpoint as a wrapper over an existing App Sync api for a specific query using AWS Service integration in API Gateway.
Eg. /employee/{id}/residenceCountry
In the mapping template I put the query as
{"query":"query MyQuery {getEmployeeDetails(id: \"$method.request.path.id\") {address {country}}}"}
However, I am getting a 500 Internal server error with no proper logs.
When I create a POST endpoint such that I pass the above body as request body to my rest api with passthrough, it works.
In the execution logs I see the exact same content for Endpoint request body after transformations:
In order to get the proper logs I tried getting $context.error.message and $context.integrationErrorMessage but I do not get any details.
Could someone please tell what I could be doing wrong or how to debug this better?
It turned out to be a very silly mistake of selecting App Sync as AWS Service in GET vs App Sync Data Plane in POST. It was only made apparent via another set of eyes. Thanks to my colleague Albert Hoxha.
So I am trying trying to execute a PutItem request from my AWS API Gateway. I am trying to do this by using the path /storeid/{username}/{password}. I have done the mapping as json and the test within the API works perfectly and I see my data show up in my DynamoDB table but when I deploy the API and try to invoke this request I receive the following response: {"message":"Missing Authentication Token"}. This request does not have any authorization or API key requirement. Why does the test work but not the url when invoked.
ps-yes I entered the correct url
Please help!
A few things to check
Verify that Authorization is set to None (i.e. not IAM) in your Method request settings.
Verify that you deployed your API changes to your stage. Using the console, click Actions -> Deploy API.
Once deployed the URL to use should be displayed when you select the Stage that you deployed to. Verify you are using the correct URL.
Also, side note, it is a really bad idea to be putting passwords in your URL path or query parameters. Consider doing sending the data in the request body as a POST and doing something like HTTPS and hashing to protect the password.
I've successfully setup AWS Gateway to validate the body of incoming POST requests using JSON Schema. I was so thrilled! Hooray I thought ... as I tested the functionality using the internal AWS tools ... but then I tested a POST request w/invalid data from a website using AJAX and then a CURL request, again using invalid data - and wouldn't you know it, both of them got through to my integration and triggered my AWS Lambda function, something JSON Schema was supposed to block! I've deployed the latest API to my endpoint and even set all of the "Content-Type" headers being called to the same JSON Schema AWS model. I'm at a loss for what's going on ... how do I enforce that all requests must be one content-type or return an error?
Thanks in advance for any help you could provide ...
The answer to my question for those of you who will stumble upon this issue.
By default, JQuery's ".post" method sets a Content-Type to "application/x-www-form-urlencoded." The model I set in AWs Gateway was only for "application/json" POST requests. I assumed that if I set the "request validator" to use JSON Schema models for a specific content-type that only the ones I defined would allowed to pass through ... oh no, no, no! AWS Gateway conveniently let any other Content-Type pass through unchecked, bypassing my JSON Schema model validator. Unbelievable actually. So the answer to enforce only application/json was to then move to the "integration request" and configure a body mapping for application/json setting the "When there are no templates defined (recommended)" option to true. And voila, problem solved. AWS Gateway will still allow your POST request to get to this stage, but it won't get to your "action (e.g. Lambda function).
I wanted to add ... it's no longer a problem, but even by setting multiple Content-Type patterns, the model was only enforced on the first one within AWS Gateway. Strange behavior ... maybe someone could help w/this?
This works fine using proper setting. Have your model set correctly including the validation you wish to apply.
For your method, go to Method Execution section and set
Settings -> Request Validator - select option as 'Validate Body'. Your may choose other appropriate options based on your requirement.
Request Body -> create new entry as 'application/json' and select your model.
Done. This will work as expected and throw 500 error for other Content-Type or if model validation fails.
Also, you can always validate request in Lambda's entry function. Though that is what you want to avoid to escape lambda trigger cost.
Additional Tip: Make sure you have API Rate limit set properly as you will get charged if your API is caught by spammers/attackers, though validation through model will protect you but you will still get charged by AWS. In case of API Key set, this is still applicable.
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.
I am using wso2 1.10.0 api manager for first time. I need to access the http backend with simple query parameter. I published the api and tried either by setting as queryparam or json object, it's not giving me the expected result. I will get binary response or method not allowed. When tried setting only http endpoint I never got response its just keeping processing for long time. Please suggest me how do I access simple http backend. Need to show demo in a week.
Please help to solve this.
You get 'method not allowed' when you try to access a resource which was not defined for that method (say backend has POST method supporting resource only and you try to do a GET request)
I guess the issue is with the way you have defined the resources for the api from the publisher application. (invalid HTTP methods for resources)
If you think you have defined them correctly, then the next step to identify the issue is wirelogs. wirelogs provide all the info in request passing through the api manager gateway (request headers, body etc)
Follow this article http://mytecheye.blogspot.com/2013/09/wso2-esb-all-about-wire-logs.html on how to enable and read them
You can then directly call the backend (say curl -v to the backend) and compare the request from the direct call vs the one going out from
gateway to the backend and check the difference. This would help you start finding the issue
Since you are new to API manager, I would recommend you to do following first
Try out a simple scenario similar to your one. You can google it. This is from official documentation. would recommend to try out a simple scenario first. say https://docs.wso2.com/display/AM1100/Convert+a+JSON+Message+to+SOAP+and+SOAP+to+JSON
Then use SOAP UI or similar app to directly call the backend web service (not the api manager) and get the SOAP request and SOAP response for the backend.
Then create the api in API manager. you need to do the same thing in the sample i provided. only difference is the soap payload. use the previously collected SOAP messages.
Enable wire logs. for that see the comments in the previous answer. In wirelogs you will see >> and << signs
To read the wire log, first we have to identify message direction.
DEBUG - wire >> - This represent the message coming into API manager from the wire (will notice two set of these. one coming in to the
gateway from the rest client and response coming in to the api manager from the backend. )
DEBUG - wire << - This represents the message going to the wire from API manager (again two sets. request going from api manager to the
backend service and the response sent to the rest client from the api manager.)
the soap message will be printed in this log. check for the request going from api manager to the backend and the response coming from the
backend to the api manager. you can compare that to the onces you collected in the step 2 and do modifications if needed to the sequnces.
the wirelogs will also print the http headers. so check that as well.
hope you could set up a working sample using these steps