I am trying to test POST method in my API gateway and i am getting error:
{"message": "Could not parse request body into json: Unexpected
character (\'}\' (code 125)): expected a value\n at [Source:
[B#11a9cb82; line: 5, column: 2]"}
the request body i am using:
"{\"DataTypes\":\"ADL\"}"
I guess you should not escape anything.
If you try with
{"DataTypes": "ADL"}
it should work.
Related
I've got an API Gateway in front of a Lambda.
Successful responses from the Lambda (HTTP 2xx) have the response body forwarded.
However, for error responses (HTTP 5xx and others), the API Gateway transforms the response body using response templates.
Is there a way to avoid this? To have the original error response body from the Lambda?
In my Lambda I have this:
return callback(generalError, {
statusCode: 500,
headers:{
"content-type": "application/json"
},
body: JSON.stringify({
error: 'INTERNAL_ERROR',
description: error.message,
})
});
However, as output from the Gateway I get this:
{ "error": "Internal server error" }
Which doesn't match. The Lambdas response. It does match the response template in API Gateway:
{"message":$context.error.messageString}
However, is there a way to just proxy the original Lambda response instead of having this transformation in place?
I've found the reason why it doesn't work.
If you set a callback to a 500 error, including an object with an error field, somehow this will become the full response, regardless of the other output or real error.
Avoiding using an error field does the trick! I renamed it to serviceError and now I'm getting the responses I expected.
I want to POST form data to api gateway which then sends it to lambda for processing. However, I get
{
"message": "Could not parse request body into json: Unexpected character (\'-\' (code 45))
in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value\n
at [Source: (byte[])\"----------------------------086228525798973846089611\r\nContent-
Disposition: form-data; name=\"first_name\"\r\n\r\nfake\r\n---------------------------
-086228525798973846089611\r\nContent-Disposition: form-data;
name=\"last_name\"\r\n\r\nname\r\n---------------------------
-086228525798973846089611\r\nContent-Disposition: form-data;
name=\"email\"\r\n\r\nfakename1#something.com\r\n---------------------------
-086228525798973846089611\r\nContent-Disposition: form-data; name=\"mobile\"\r\n\r\n\r\n-
---------------------------086228525798973\"[truncated 752 bytes]; line: 1, column: 3]"
}
In the cloudwatch logs I can see lambda gives this error: Lambda invocation failed with status: 400. Can't see any errors in lambda logs just api gateway logs.
My api gateway POST method looks like this:
Edit:
Adding image of form I am trying to submit that the API isn't liking:
Any ideas how to POST through to lambda without api gateway transformations or other issue?
Using the Postman tool, I'm trying to query a Couchbase bucket. I'm getting an error response 1065 that there is an "unrecognized parameter in request". The query will work fine within the Couchbase workbench, but I need to be able to do this from Postman.
I'm making a POST request with this body:
{
"statement" : "SELECT * from `myBucketName` where id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee""
}
There error message is:
"msg": "Unrecognized parameter in request: {\n\"statement\" : \"SELECT from `myBuckeyName` where _id "
I think this is just an issue with how my request body is formatted, I'm just new to this and not sure how it should be formatted based off the error I'm getting.
Here's how I did it:
Open Postman
Select POST
Use a URL of http://localhost:8093/query/service
Under "Authorization", use Basic Auth (with the username/password you've created for Couchbase)
Under "Body", select "x-www-form-urlencoded"
Add a KEY of statement and a value of your query
Click SEND
I got a 200 OK response with the results of the query. Screenshot:
You should definitely check out the Couchbase REST API documentation. It uses curl instead of Postman, but that's a translation you'll eventually get used to.
I'm sending a GET request via Lumen unit testing using
$this->get('api/cars/volvo/')
where volvo is a route parameter.
When this request reaches my controller, it returns a 500 response because I'm accessing the URI parameter through
$request->route('company')
Note that this only occurs when I send request through unit test, not the normal request if I send for example from Postman.
Example:
$response = $this->get('/api/v1/cars/volvo', $header);
$response->assertResponseStatus(200);
I get the following when I run this test:
1) Tests\ApiTest::test_get_cars
Expected status code 200, got 500.
Failed asserting that 500 matches expected 200.
I can't seem to set my integration response for errors using the amazon api gateway
I added an integration response but it does not return the 400 error, instead it continues to return 200 response with
{
"errorMessage": "foose",
"errorType": "Error",
"stackTrace": [
"exports.handler (/var/task/index.js:11:19)"
]
}
If you are using the Java, you need to throw an Exception. I made the mistake of trying to return the error information. The Lambda Error Regex parses the Exception message so if you throw this:
throw new Exception("Failed: Something bad happened!");
and replace your foo.* with Failed: .* it will use the 400 status code.
If you are using NodeJS, you can use context.fail('Failed: Something bad happened!'); to get the same result
.*"Failed:".*
This is the correct syntax for Lambda Regex.
Also, in nodeJS (as per your example above) it's easier to construct your own error object and add status for easier mapping, e.g.:
var myError = {}
myError.status = "userError"; //use this for 400 and "serverError" for 500
myError.message = err.stackTrace; //message body
Finally you need to return
context.fail(JSON.stringify(myError));
If you don't have response mapping set up properly.