Open atlascoder opened 5 years ago
@atlascoder your url does not look correct '@connections' seems wrong (looks similar to something used in aws cloudformation, but not a correct api gateway path)
Hi @okigan , actually this is correct url for WebSocket API of APIGateway: https://docs.aws.amazon.com/en_us/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html
Oh this is something new (to me :), will require more digging
Yes, your tool is convenient and support for WebSocket url would be great
Ooops, I did not realize my tool made into into official AWS docs! 🤣 https://docs.aws.amazon.com/en_us/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html
@atlascoder ok, this is getting interesting, I need more information to reproduce this.
Paste your setup for the route, and how you’ve setup the request and response template/mapping/etc:
https://docs.google.com/document/d/1-5u7A-bqmYldUoTBy6rMsO4rJC_kQzaHjHs__1yfmHY
@okigan, sorry, it's not so straight.. I create WebSocket connection from Qt app and then I take session ID and try to send data to the socket with POST request. To reproduce this you can create any WebSocket-type API and a resource that does not require authorization. The resource should have Lambdas connected to $connect
, $disconnect
and default
.
Use any convenient language that have WebSocket lib in order to make connection. In $connect
lambda you will find connectionId
in requestContext
.
If I understood right the aim of your tool - it can make requests using AWSCredentials from env, so, if a current user will be authorized to post data to websocket - the POST requests like https://api_endpoint/stage/@connection/connectionId should send content to the connection (while it is open)
It’s more about that back end setup (not the qt setup), I tried to follow https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-wscat.html. But effectively it returns an error that request/response templates are not setup.
So I need more insight how to setup the WebSocket api (that works👻)
@atlascoder I think i have a repro (instead of mocking created a simple lambda), try out this branch confirm that it works for you as well: https://github.com/okigan/awscurl/pull/64
ok, i've figured it out, fantastically complicated, strap on your seatbelts! This will require usage of both tools: wscat and awscurl.
code for the connected lambda function:
exports.handler = (event, context, callback) => {
console.log("event:", event)
console.log("event:", event)
var result = {
// event,
// context,
"connectionId": event.requestContext.connectionId,
"for": "awscurl"
};
var response = {
"statusCode": 200,
"headers": {
"Content-Type": "*/*"
},
body: JSON.stringify(result)
}
console.log("response:", response)
callback(null, response);
};
@okigan cool! So, everything is needed is to make percent-encoding... Obvious! Thank you!
I'll check the branch #64 and reply
@okigan did you use WS API without authorization? Or how have you used wscat
with AWS credentials?
@atlascoder without, see updated snapshot above
OK, @okigan thank you!
@okigan, I confirm - it works! Thanks a lot!!
@okigan thanks a lot 💯 , I was really struggling to get execute-api
working with web-socket. Your clear notes with screen shots made it clear as water 👍
I've made a proposal to AWS to update documentation, all encouraged to review & comment on the draft.
proposal draft: https://docs.google.com/document/d/1G_vyFBV7d_3QS4dcaRqexLa8magZm7CsPAuivGTRip8/edit?usp=sharing
hmm, might be simpler to make a PR for https://github.com/awsdocs/amazon-api-gateway-developer-guide/blob/master/doc_source/apigateway-how-to-call-websocket-api-connections.md
This worked for me, using the https://github.com/legal90/awscurl tool. I have not been able to make messaging clients work with the Go SDK, but this shows the APIGW works.
I got error when trying to execute:
Also tried:
and
The error: