WebSocket API - Posting to connection - Route not found error

0

Hi,

I'm using AWS Lambda to build a basic chat app, however when trying to post a message back to a connection I get an error

"No method found matching route test0/@connections/PxWP8cfSDoECFYw= for http method POST."

This is the code....

let api = new AWS.ApiGatewayManagementApi({
apiVersion : '2018-11-29',
endpoint : event.requestContext.domainName _ '/' _ event.requestContext.stage
});

await api.postToConnection({ ConnectionId: event.requestContext.connectionId, Data: 'callback'}).promise();

Many Thanks,
Ady

3개 답변
1
endpoint : event.requestContext.domainName + '/' + event.requestContext.stage

"No method found matching route test0/@connections/PxWP8cfSDoECFYw= for http method POST."

Based on the error message and your code, I guess you're using a custom domain name with a base mapping to the API's "test0" stage. In the case,

https://YOUR_DOMAIN/test0/@connections/PxWP8cfSDoECFYw=

has a same effect to invoke:

https://[apiId].execute-api.<region>.amazonaws.com/test0/test0/@connections/PxWP8cfSDoECFYw=
(Note there is "test0" twice in the URI)

This is the reason why the route was resolved to "test0/@connections/PxWP8cfSDoECFYw=" instead of "@connections/PxWP8cfSDoECFYw=".

In the case, you should omit the stage name in the endpoint URI.

AWS
답변함 4년 전
0

@jwaataws, thanks for the swift response.

And yes, looks like you described this scenario exactly, and your suggestion of removing the stage name from the endpoint see this working well.

Many Thanks,
Ady

Ady
답변함 4년 전
0

Remove the stage from the url if you are using a custom domain.

Custom domain as in, I was using https://mywebsite.com, and when we append the stage, it was like https://mywebsite.com/dev. Then I got the above error. removing the stage fixed the issue

imtmh
답변함 8달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠