pzrq
pzrq

Reputation: 1907

How do I update the AWS API Gateway WebSocket chat app tutorial from aws-sdk v2 to v3 and Node.JS v16 to v18?

The AWS documentation (also archived) currently stops at Node.JS v16, which is EOL upstream. Unfortunately there's no simple way to get Node v16 with @aws-sdk v3 or Node v18 with aws-sdk v2, the combined leap across the chasm from Node v16 at aws-sdk v2 to Node v18 with @aws-sdk v3 generally seemed easiest in one go. Which is my way of apologising for the long but not oversimplified question title.

I can get part of the way there, by using the codemod (helpful suggestion, thanks!) on each of the four ZipFile values embedded in the starter.yaml extracted from the zip download of Step 1:

// copy ZipFile contents out to example.js, then run the codemod:
npx aws-sdk-js-codemod -t v2-to-v3 example.js  
// then copy results back in, someone can probably do it better than I

But I'd still get errors from testing it with wscat -c wss://<replace_with_url> like:

error: Unexpected server response: 502
< {"message": "Internal server error", "connectionId":"aA-fHfctSwMCIIg=", "requestId":"aA_QwESnSwMF-fw="}

Any ideas what I am missing?

Upvotes: 0

Views: 75

Answers (1)

pzrq
pzrq

Reputation: 1907

I figured it out from my CloudWatch logs and the AWS SDK API documentation:

... The endpoint will be of the form https://{api-id}.execute-api.{region}.amazonaws.com/{stage}, ...

There was also a need to add in the URL scheme i.e. to change the value of endpoint: in two places. So in git diff format:

-                      event.requestContext.domainName + '/' + event.requestContext.stage,
+                      'https://' + event.requestContext.domainName + '/' + event.requestContext.stage,

That got sendmessage working again:

# Terminal 1
{"action": "sendmessage", "message": "hello, everyone!"}
# Terminal 2
< hello, everyone!

P.S. I think I got lucky after a few hours of discouraged messing around where I nearly abandoned this, hence why I posted this rather than listen to the haters and trash it - if you're in a similar chasm, please don't give up, it's possible to get to your goal.

Upvotes: 0

Related Questions