AWS Websocket API return error "Output mapping refers to an invalid method response: 200" when testing to connect from wscat - aws-api-gateway

I am trying to build realtime chat and notification using AWS Websocket API. i have setup the $connect route to integrate to http endpoint. when testing the websocket URL using wscat, request successfully received on my endpoint, but wscat got "Unexpected server response: 500". inspecting associated log on CloudWatch, i found an error said "Output mapping refers to an invalid method response: 200". anyone can please help me to figure out what am i doing wrong here?

This stems from a missing Method Response on the method.
Select the API Gateway Method
Select Method Response
Ensure that a mapping exists for a 200 response (either 200 or 2**)

For me the problem was that despite having configured the response routes correctly with a $default response (as a catchall), the deployment did not contain these integration responses.
This was due to the deployment resource being created before the actual routes. I solved it by adding making the stage DependsOn the route, and the deployment DependsOn the stage (this I did by using an implicit dependsOn via a StageResource.ref for the stageName attribute on the deployment).
You can check out my answer here for more details.

Related

AWS - API Gateway - HTTPS Request returning 404 Not Found

I am working on creating a new request in AWS API Gateway. I am having issues with a 404 not found on the URL request.
The request (had to create fake one for the question):
GET https://hello.stackoverflow.com/services/misc/myroute/v1/swagger.json
I created a route in API Gateway ANY /services/misc/myroute/{proxy+}
I attached the route to a Load Balancer Listener integration
I set up the listener rule in the Load Balancer:
IF Path is /services/misc* Then Forward to Target
IF Requests otherwise not routed Then Forward to Default
Created logs for this system in the AWS API Gateway: Monitor -> Logging -> Set Log Destination
Set variables for the log format using the $context variables, Context Variables
Ex Log:
{ "requestId":"QWRHQKWFHWAFZ=",
"routeKey":"ANY /services/misc/myroute/{proxy+}",
"path":"/services/misc/myroute/v1/swagger.json",
"domain":"hello.stackoverflow.com",
"domain_prefix":"hello",
"httpMethod":"GET", "status":"404","protocol":"HTTP/1.1", "endpoint":-" }
One final check I have done to make sure its completing its "route" was see the requests in the monitoring and seeing the 4xx come from this ALB listener.
I can send the request via localhost and get a response with the json body
GET https://localhost:8080/v1/swagger.json --> Status 200 OK with body filled
In my quest to solve the issue, it has lead me to many older (2019) stack overflow questions that seem to be outdated with the AWS Console, same with the AWS documentation. See links below...
AWS API Gateway Method request path parameter not working
AWS API Gateway 404 page not found error when invoking endpoint url
AWS API Gateway Method request path parameter not working
With this being my first project in the AWS cloud space, I am not sure where else to turn. My guess would be the authentication headers from the API Gateway are being lost, but not sure where I can see this loss happening.
From my understanding of how the AWS Request Flow goes, I created this diagram:

amazon api gateway returns 403

I am calling a serverless api(apigateway+lambda) from lambda from another aws account with axios, returns 403 http status with payload { message: "Forbidden" }. the get http call returns data when used in chrome
looking at the comments which say that the headers included "x-amzn-errortype: ForbiddenException", that happened for me when I had not deployed the api yet. After deploying the api, that error went away

UnrecognizedClientException while testing API Gateway with integration type Kinesis

I have created an API using API gateway with integration type 'Kinesis'. I am trying to access ListStreams method. I have created a role with AmazonKinesisFullAccess policy and trusted identity is set to apigateway.amazonaws.com. I have provided arn to the execution role field but while testing this API using console, getting following error:
<UnrecognizedClientException>
<Message>The security token included in the request is invalid</Message>
</UnrecognizedClientException>
Thanks
This was a classic example of wrong/incomplete exception detail.
My fault was that I was looking for kinesis in a wrong region. But rather than returning some error like "Resource not found", api gateway returned "Invalid security token".

AWS API Gateway - error 403 on resource not found

It seems an HTTP response of 403 is accepted as the norm and correct handling of any calls made to a resource or endpoint that does not exist on an API Gateway setup (this post).
Example: a call to a non-existing endpoint on my Gateway would be;
GET -- https://{{MyGatewayDomain}}/api/v1/blah
This would return a 403 forbidden. Which can be rather confusing and misleading.
I'd like to know if anyone has managed to configure their API Gateway so that any call to a non-existing endpoint / resource, returns what I would have thought is a correct response of a 404?
Thanks in advance.
EDIT
As per bejos-aws's suggestion, I am able to override the default behaviour of the 403 Missing Authentication Token however, this will not solve my issue as then all the valid 403 errors would return a 404 response which is incorrect.
Also, my issue is regarding a 403 forbidden which doesn't exist in the default responses in the AWS Gateway Response's list (and even if it did, that wouldn't help).
Seems this is just not possible?
This is not currently a feature of API Gateway. However, there is a workaround. Using Gateway Responses, you can override the 403 Missing Authentication Token response with a 404 and supply whatever message you want as a response.
Note, this only works when the API stage is valid:
So if your API is deployed to a stage named v1
https://{MyGatewayDomain}/api/v1/somepath
And the caller supplies the wrong stage
https://{MyGatewayDomain}/api/invalidStage/somepath
Then the API will still respond with 403 Forbidden

Error:{"error: "unexpected error"} when using http request node in Node-Red editor on Bluemix

I added an http request node when using the Node-Red editor on Bluemix.
However, when I hit "Deploy", I see the following error:
Error:{"error: "unexpected error"}
Is there another way to find out what could be wrong, and get more helpful error messages?
These are the options I used:
Method: GET
URL: http://jsonplaceholder.typicode.com/posts/1
The URL is from JSONPlaceholder, a free online REST service for testing.
Thank you
I recreated the http request node (with the same parameters) today and the deploy was successful, and so was the GET request.